Skip to content

Commit

Permalink
fix race condition in IndexShardIT.testIndexCanChangeCustomDataPath
Browse files Browse the repository at this point in the history
Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
  • Loading branch information
nknize committed Nov 1, 2022
1 parent c468308 commit 1f533a0
Showing 1 changed file with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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))
);

Expand Down

0 comments on commit 1f533a0

Please sign in to comment.