From 7cd881fbd46738cfc523343af1aee8dc1710ced4 Mon Sep 17 00:00:00 2001 From: Nicholas Walter Knize Date: Wed, 19 Oct 2022 13:53:36 -0500 Subject: [PATCH] fix race condition in IndexShardIT.testIndexCanChangeCustomDataPath Signed-off-by: Nicholas Walter Knize --- .../opensearch/index/shard/IndexShardIT.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/server/src/internalClusterTest/java/org/opensearch/index/shard/IndexShardIT.java b/server/src/internalClusterTest/java/org/opensearch/index/shard/IndexShardIT.java index 3d8da7eac7690..959b04b7861a3 100644 --- a/server/src/internalClusterTest/java/org/opensearch/index/shard/IndexShardIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/index/shard/IndexShardIT.java @@ -288,7 +288,14 @@ public void testIndexCanChangeCustomDataPath() throws Exception { final Path indexDataPath = sharedDataPath.resolve("start-" + randomAsciiLettersOfLength(10)); logger.info("--> creating index [{}] with data_path [{}]", index, indexDataPath); - createIndex(index, Settings.builder().put(IndexMetadata.SETTING_DATA_PATH, indexDataPath.toAbsolutePath().toString()).build()); + createIndex( + index, + Settings.builder() + .put(IndexMetadata.SETTING_DATA_PATH, indexDataPath.toAbsolutePath().toString()) + .put(IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.getKey(), Translog.Durability.REQUEST) + .put(IndexSettings.INDEX_MERGE_ON_FLUSH_ENABLED.getKey(), false) + .build() + ); client().prepareIndex(index).setId("1").setSource("foo", "bar").setRefreshPolicy(IMMEDIATE).get(); ensureGreen(index); @@ -307,6 +314,16 @@ public void testIndexCanChangeCustomDataPath() throws Exception { logger.info("--> closing the index [{}] before updating data_path", index); assertAcked(client().admin().indices().prepareClose(index).setWaitForActiveShards(ActiveShardCount.DEFAULT)); + // race condition: async flush may cause translog file deletion resulting in an inconsistent stream from + // Files.walk below during copy phase + // temporarily disable refresh to avoid any flushes or syncs that may inadvertently cause the deletion + assertAcked( + client().admin() + .indices() + .prepareUpdateSettings(index) + .setSettings(Settings.builder().put(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), "-1").build()) + ); + final Path newIndexDataPath = sharedDataPath.resolve("end-" + randomAlphaOfLength(10)); IOUtils.rm(newIndexDataPath); @@ -326,11 +343,17 @@ public void testIndexCanChangeCustomDataPath() throws Exception { } logger.info("--> updating data_path to [{}] for index [{}]", newIndexDataPath, index); + // update data path and re-enable refresh assertAcked( client().admin() .indices() .prepareUpdateSettings(index) - .setSettings(Settings.builder().put(IndexMetadata.SETTING_DATA_PATH, newIndexDataPath.toAbsolutePath().toString()).build()) + .setSettings( + Settings.builder() + .put(IndexMetadata.SETTING_DATA_PATH, newIndexDataPath.toAbsolutePath().toString()) + .put(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), IndexSettings.DEFAULT_REFRESH_INTERVAL.toString()) + .build() + ) .setIndicesOptions(IndicesOptions.fromOptions(true, false, true, true)) );