Skip to content

Commit 76f09cf

Browse files
authored
Wait for shard index folder to be cleaned up (#80341) (#80402)
The tests testCreateAndRestoreSearchableSnapshot and testCreateAndRestorePartialSearchableSnapshot both failed once when asserting the shard folders using assertShardFolders(index, true). The failures occurred when the original index is first closed (not deleted) and mounted again under the same name (so it will be restored as a searchable snapshot index on top of the existing shard files). The SearchableSnapshotDirectory implementation takes care to clean up the shard files on disk using SearchableSnapshotDirectory.cleanExistingRegularShardFiles() and the tests verify that the shard index folder is indeed deleted from disk on all nodes but sometime fail because the folder is still present. I wasn't able to reproduce but I think that the closing of the original index + the creation of the .snapshot-blob-cache index trigger some shard relocations that are cancelled by the subsequent mount/restore, leaving some files on disk that should be cleaned up but maybe not immediately. This commit changes the tests to assertBusy() when verifying the shard folders and also adds more logging information in case waiting for the assertShardFolders(index, true) is not enough. Closes #77831
1 parent f0c7f6e commit 76f09cf

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/BaseSearchableSnapshotsIntegTestCase.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import static org.hamcrest.Matchers.equalTo;
6363
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
6464
import static org.hamcrest.Matchers.instanceOf;
65+
import static org.hamcrest.Matchers.not;
6566

6667
public abstract class BaseSearchableSnapshotsIntegTestCase extends AbstractSnapshotIntegTestCase {
6768
@Override
@@ -236,9 +237,17 @@ protected void assertShardFolders(String indexName, boolean snapshotDirectory) t
236237
final ShardPath shardPath = ShardPath.loadShardPath(logger, service, shardId, customDataPath);
237238
if (shardPath != null && Files.exists(shardPath.getDataPath())) {
238239
shardFolderFound = true;
239-
assertEquals(snapshotDirectory, Files.notExists(shardPath.resolveIndex()));
240-
241-
assertTrue(Files.exists(shardPath.resolveTranslog()));
240+
final boolean indexExists = Files.exists(shardPath.resolveIndex());
241+
final boolean translogExists = Files.exists(shardPath.resolveTranslog());
242+
logger.info(
243+
"--> [{}] verifying shard data path [{}] (index exists: {}, translog exists: {})",
244+
node,
245+
shardPath.getDataPath(),
246+
indexExists,
247+
translogExists
248+
);
249+
assertThat(snapshotDirectory, not(indexExists));
250+
assertTrue(translogExists);
242251
try (Stream<Path> dir = Files.list(shardPath.resolveTranslog())) {
243252
final long translogFiles = dir.filter(path -> path.getFileName().toString().contains("translog")).count();
244253
if (snapshotDirectory) {

x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/FrozenSearchableSnapshotsIntegTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public void testCreateAndRestorePartialSearchableSnapshot() throws Exception {
309309
// TODO: fix
310310
// assertSearchableSnapshotStats(restoredIndexName, true, nonCachedExtensions);
311311
ensureGreen(restoredIndexName);
312-
assertShardFolders(restoredIndexName, true);
312+
assertBusy(() -> assertShardFolders(restoredIndexName, true));
313313

314314
assertThat(
315315
client().admin()

x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsIntegTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public void testCreateAndRestoreSearchableSnapshot() throws Exception {
256256
assertSearchableSnapshotStats(restoredIndexName, cacheEnabled, nonCachedExtensions);
257257

258258
ensureGreen(restoredIndexName);
259-
assertShardFolders(restoredIndexName, true);
259+
assertBusy(() -> assertShardFolders(restoredIndexName, true));
260260

261261
assertThat(
262262
client().admin()

0 commit comments

Comments
 (0)