Skip to content

Commit 0a1cec2

Browse files
authored
Fix SearchableSnapshotsPersistentCacheIntegTests.testCacheSurviveRestart (#66354)
Closes #66278
1 parent 4b0f75b commit 0a1cec2

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
package org.elasticsearch.xpack.searchablesnapshots.cache;
88

99
import org.apache.lucene.document.Document;
10-
import org.apache.lucene.util.LuceneTestCase;
1110
import org.elasticsearch.cluster.metadata.IndexMetadata;
1211
import org.elasticsearch.cluster.node.DiscoveryNode;
1312
import org.elasticsearch.cluster.node.DiscoveryNodes;
1413
import org.elasticsearch.common.settings.Settings;
1514
import org.elasticsearch.common.unit.ByteSizeUnit;
1615
import org.elasticsearch.common.unit.ByteSizeValue;
16+
import org.elasticsearch.common.unit.TimeValue;
1717
import org.elasticsearch.index.Index;
1818
import org.elasticsearch.index.IndexService;
1919
import org.elasticsearch.index.shard.ShardPath;
@@ -39,7 +39,6 @@
3939
import static org.hamcrest.Matchers.greaterThan;
4040
import static org.hamcrest.Matchers.notNullValue;
4141

42-
@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/66278")
4342
public class SearchableSnapshotsPersistentCacheIntegTests extends BaseSearchableSnapshotsIntegTestCase {
4443

4544
@Override
@@ -48,6 +47,8 @@ protected Settings nodeSettings(int nodeOrdinal) {
4847
.put(super.nodeSettings(nodeOrdinal))
4948
// ensure the cache is definitely used
5049
.put(CacheService.SNAPSHOT_CACHE_SIZE_SETTING.getKey(), new ByteSizeValue(1L, ByteSizeUnit.GB))
50+
// to make cache synchronization predictable
51+
.put(CacheService.SNAPSHOT_CACHE_SYNC_INTERVAL_SETTING.getKey(), TimeValue.timeValueHours(1L))
5152
.build();
5253
}
5354

@@ -141,19 +142,21 @@ public Settings onNodeStopped(String nodeName) {
141142
}
142143
});
143144

144-
persistentCache = internalCluster().getInstance(CacheService.class, dataNode).getPersistentCache();
145-
assertThat(persistentCache.getNumDocs(), equalTo((long) cacheFiles.size()));
145+
cacheService = internalCluster().getInstance(CacheService.class, dataNode);
146+
persistentCache = cacheService.getPersistentCache();
146147
ensureGreen(restoredIndexName);
147148

148149
cacheFiles.forEach(cacheFile -> assertTrue(cacheFile + " should have survived node restart", Files.exists(cacheFile)));
150+
assertThat("Cache files should be repopulated in cache", persistentCache.getNumDocs(), equalTo((long) cacheFiles.size()));
149151

150152
assertAcked(client().admin().indices().prepareDelete(restoredIndexName));
151153

152-
assertBusy(() -> cacheFiles.forEach(cacheFile -> assertFalse(cacheFile + " should have been cleaned up", Files.exists(cacheFile))));
153-
cacheService = internalCluster().getInstance(CacheService.class, dataNode);
154+
assertBusy(() -> {
155+
cacheFiles.forEach(cacheFile -> assertFalse(cacheFile + " should have been cleaned up", Files.exists(cacheFile)));
156+
assertTrue(internalCluster().getInstance(CacheService.class, dataNode).getPersistentCache().hasDeletions());
157+
});
154158
cacheService.synchronizeCache();
155159

156-
persistentCache = cacheService.getPersistentCache();
157160
assertThat(persistentCache.getNumDocs(), equalTo(0L));
158161
}
159162
}

0 commit comments

Comments
 (0)