Skip to content

Commit 1f533a0

Browse files
committed
fix race condition in IndexShardIT.testIndexCanChangeCustomDataPath
Signed-off-by: Nicholas Walter Knize <[email protected]>
1 parent c468308 commit 1f533a0

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

server/src/internalClusterTest/java/org/opensearch/index/shard/IndexShardIT.java

+25-2
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,14 @@ public void testIndexCanChangeCustomDataPath() throws Exception {
288288
final Path indexDataPath = sharedDataPath.resolve("start-" + randomAsciiLettersOfLength(10));
289289

290290
logger.info("--> creating index [{}] with data_path [{}]", index, indexDataPath);
291-
createIndex(index, Settings.builder().put(IndexMetadata.SETTING_DATA_PATH, indexDataPath.toAbsolutePath().toString()).build());
291+
createIndex(
292+
index,
293+
Settings.builder()
294+
.put(IndexMetadata.SETTING_DATA_PATH, indexDataPath.toAbsolutePath().toString())
295+
.put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.REQUEST)
296+
.put(IndexSettings.INDEX_MERGE_ON_FLUSH_ENABLED.getKey(), false)
297+
.build()
298+
);
292299
client().prepareIndex(index).setId("1").setSource("foo", "bar").setRefreshPolicy(IMMEDIATE).get();
293300
ensureGreen(index);
294301

@@ -307,6 +314,16 @@ public void testIndexCanChangeCustomDataPath() throws Exception {
307314
logger.info("--> closing the index [{}] before updating data_path", index);
308315
assertAcked(client().admin().indices().prepareClose(index).setWaitForActiveShards(ActiveShardCount.DEFAULT));
309316

317+
// race condition: async flush may cause translog file deletion resulting in an inconsistent stream from
318+
// Files.walk below during copy phase
319+
// temporarily disable refresh to avoid any flushes or syncs that may inadvertently cause the deletion
320+
assertAcked(
321+
client().admin()
322+
.indices()
323+
.prepareUpdateSettings(index)
324+
.setSettings(Settings.builder().put(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), "-1").build())
325+
);
326+
310327
final Path newIndexDataPath = sharedDataPath.resolve("end-" + randomAlphaOfLength(10));
311328
IOUtils.rm(newIndexDataPath);
312329

@@ -326,11 +343,17 @@ public void testIndexCanChangeCustomDataPath() throws Exception {
326343
}
327344

328345
logger.info("--> updating data_path to [{}] for index [{}]", newIndexDataPath, index);
346+
// update data path and re-enable refresh
329347
assertAcked(
330348
client().admin()
331349
.indices()
332350
.prepareUpdateSettings(index)
333-
.setSettings(Settings.builder().put(IndexMetadata.SETTING_DATA_PATH, newIndexDataPath.toAbsolutePath().toString()).build())
351+
.setSettings(
352+
Settings.builder()
353+
.put(IndexMetadata.SETTING_DATA_PATH, newIndexDataPath.toAbsolutePath().toString())
354+
.put(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), IndexSettings.DEFAULT_REFRESH_INTERVAL.toString())
355+
.build()
356+
)
334357
.setIndicesOptions(IndicesOptions.fromOptions(true, false, true, true))
335358
);
336359

0 commit comments

Comments
 (0)