Skip to content

Commit 52ebed3

Browse files
authored
Wait for shard index folder to be cleaned up (#80341) (#80393)
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 81d7742 commit 52ebed3

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
@@ -18,6 +18,7 @@
1818
import org.elasticsearch.common.settings.Settings;
1919
import org.elasticsearch.common.unit.ByteSizeUnit;
2020
import org.elasticsearch.common.unit.ByteSizeValue;
21+
import org.elasticsearch.common.util.CollectionUtils;
2122
import org.elasticsearch.common.util.concurrent.AtomicArray;
2223
import org.elasticsearch.env.NodeEnvironment;
2324
import org.elasticsearch.index.Index;
@@ -65,6 +66,7 @@
6566
import static org.hamcrest.Matchers.equalTo;
6667
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
6768
import static org.hamcrest.Matchers.instanceOf;
69+
import static org.hamcrest.Matchers.not;
6870

6971
@ESIntegTestCase.ClusterScope(supportsDedicatedMasters = false, numClientNodes = 0)
7072
public abstract class BaseSearchableSnapshotsIntegTestCase extends AbstractSnapshotIntegTestCase {
@@ -75,7 +77,7 @@ protected boolean addMockInternalEngine() {
7577

7678
@Override
7779
protected Collection<Class<? extends Plugin>> nodePlugins() {
78-
return List.of(LocalStateSearchableSnapshots.class);
80+
return CollectionUtils.appendToCopy(super.nodePlugins(), LocalStateSearchableSnapshots.class);
7981
}
8082

8183
@Override
@@ -234,9 +236,17 @@ protected void assertShardFolders(String indexName, boolean snapshotDirectory) t
234236
final ShardPath shardPath = ShardPath.loadShardPath(logger, service, shardId, customDataPath);
235237
if (shardPath != null && Files.exists(shardPath.getDataPath())) {
236238
shardFolderFound = true;
237-
assertEquals(snapshotDirectory, Files.notExists(shardPath.resolveIndex()));
238-
239-
assertTrue(Files.exists(shardPath.resolveTranslog()));
239+
final boolean indexExists = Files.exists(shardPath.resolveIndex());
240+
final boolean translogExists = Files.exists(shardPath.resolveTranslog());
241+
logger.info(
242+
"--> [{}] verifying shard data path [{}] (index exists: {}, translog exists: {})",
243+
node,
244+
shardPath.getDataPath(),
245+
indexExists,
246+
translogExists
247+
);
248+
assertThat(snapshotDirectory, not(indexExists));
249+
assertTrue(translogExists);
240250
try (Stream<Path> dir = Files.list(shardPath.resolveTranslog())) {
241251
final long translogFiles = dir.filter(path -> path.getFileName().toString().contains("translog")).count();
242252
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
@@ -254,7 +254,7 @@ public void testCreateAndRestoreSearchableSnapshot() throws Exception {
254254
assertSearchableSnapshotStats(restoredIndexName, cacheEnabled, nonCachedExtensions);
255255

256256
ensureGreen(restoredIndexName);
257-
assertShardFolders(restoredIndexName, true);
257+
assertBusy(() -> assertShardFolders(restoredIndexName, true));
258258

259259
assertThat(
260260
client().admin()

0 commit comments

Comments
 (0)