@@ -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