Skip to content

Commit bed89cf

Browse files
committed
Wait for shard index folder to be cleaned up (elastic#80341)
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 elastic#77831
1 parent 2a48308 commit bed89cf

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.elasticsearch.common.settings.Settings;
1717
import org.elasticsearch.common.unit.ByteSizeUnit;
1818
import org.elasticsearch.common.unit.ByteSizeValue;
19+
import org.elasticsearch.common.util.CollectionUtils;
1920
import org.elasticsearch.common.util.concurrent.AtomicArray;
2021
import org.elasticsearch.env.NodeEnvironment;
2122
import org.elasticsearch.index.Index;
@@ -61,6 +62,7 @@
6162
import static org.hamcrest.Matchers.equalTo;
6263
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
6364
import static org.hamcrest.Matchers.instanceOf;
65+
import static org.hamcrest.Matchers.not;
6466

6567
public abstract class BaseSearchableSnapshotsIntegTestCase extends AbstractSnapshotIntegTestCase {
6668
@Override
@@ -70,7 +72,7 @@ protected boolean addMockInternalEngine() {
7072

7173
@Override
7274
protected Collection<Class<? extends Plugin>> nodePlugins() {
73-
return org.elasticsearch.core.List.of(LocalStateSearchableSnapshots.class);
75+
return CollectionUtils.appendToCopy(super.nodePlugins(), LocalStateSearchableSnapshots.class);
7476
}
7577

7678
@Override
@@ -235,9 +237,17 @@ protected void assertShardFolders(String indexName, boolean snapshotDirectory) t
235237
final ShardPath shardPath = ShardPath.loadShardPath(logger, service, shardId, customDataPath);
236238
if (shardPath != null && Files.exists(shardPath.getDataPath())) {
237239
shardFolderFound = true;
238-
assertEquals(snapshotDirectory, Files.notExists(shardPath.resolveIndex()));
239-
240-
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);
241251
try (Stream<Path> dir = Files.list(shardPath.resolveTranslog())) {
242252
final long translogFiles = dir.filter(path -> path.getFileName().toString().contains("translog")).count();
243253
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)