Skip to content

Commit fa17c66

Browse files
committed
Fix eviction logic
1 parent 53ad877 commit fa17c66

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/SearchableSnapshotIndexFoldersDeletionListener.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,25 @@ private void markShardAsEvictedInCache(ShardId shardId, IndexSettings indexSetti
8383
shardId
8484
);
8585

86-
// Only partial searchable snapshots use the shared blob cache. Only force-evict if we know the shard won't be coming back.
87-
if (indexSettings.getIndexMetadata().isPartialSearchableSnapshot() && indexRemovalReason == IndexRemovalReason.DELETED) {
88-
final SharedBlobCacheService<CacheKey> sharedBlobCacheService =
89-
SearchableSnapshotIndexFoldersDeletionListener.this.frozenCacheServiceSupplier.get();
90-
assert sharedBlobCacheService != null : "frozen cache service not initialized";
91-
sharedBlobCacheService.forceEvictAsync(SearchableSnapshots.forceEvictPredicate(shardId, indexSettings.getSettings()));
86+
// Only partial searchable snapshots use the shared blob cache.
87+
if (indexSettings.getIndexMetadata().isPartialSearchableSnapshot()) {
88+
switch (indexRemovalReason) {
89+
// The index was deleted, it's not coming back - we can evict asynchronously
90+
case DELETED -> {
91+
final SharedBlobCacheService<CacheKey> sharedBlobCacheService =
92+
SearchableSnapshotIndexFoldersDeletionListener.this.frozenCacheServiceSupplier.get();
93+
assert sharedBlobCacheService != null : "frozen cache service not initialized";
94+
sharedBlobCacheService.forceEvictAsync(SearchableSnapshots.forceEvictPredicate(shardId, indexSettings.getSettings()));
95+
}
96+
// An error occurred - we should eagerly clear the state
97+
case FAILURE -> {
98+
final SharedBlobCacheService<CacheKey> sharedBlobCacheService =
99+
SearchableSnapshotIndexFoldersDeletionListener.this.frozenCacheServiceSupplier.get();
100+
assert sharedBlobCacheService != null : "frozen cache service not initialized";
101+
sharedBlobCacheService.forceEvict(SearchableSnapshots.forceEvictPredicate(shardId, indexSettings.getSettings()));
102+
}
103+
// Any other reason - we let the cache entries expire naturally
104+
}
92105
}
93106
}
94107
}

0 commit comments

Comments
 (0)