2727import org .apache .lucene .store .IndexInput ;
2828import org .apache .lucene .store .RateLimiter ;
2929import org .apache .lucene .util .SetOnce ;
30- import org .elasticsearch .ElasticsearchParseException ;
3130import org .elasticsearch .ExceptionsHelper ;
3231import org .elasticsearch .Version ;
3332import org .elasticsearch .action .ActionListener ;
6261import org .elasticsearch .common .unit .ByteSizeUnit ;
6362import org .elasticsearch .common .unit .ByteSizeValue ;
6463import org .elasticsearch .common .util .concurrent .AbstractRunnable ;
65- import org .elasticsearch .common .util .set .Sets ;
6664import org .elasticsearch .common .xcontent .LoggingDeprecationHandler ;
6765import org .elasticsearch .common .xcontent .NamedXContentRegistry ;
6866import org .elasticsearch .common .xcontent .XContentFactory ;
10199import java .io .InputStream ;
102100import java .nio .file .NoSuchFileException ;
103101import java .util .ArrayList ;
104- import java .util .Arrays ;
105102import java .util .Collection ;
106103import java .util .Collections ;
107- import java .util .HashSet ;
108104import java .util .List ;
109105import java .util .Map ;
110- import java .util .Optional ;
111106import java .util .Set ;
112107import java .util .concurrent .Executor ;
113108import java .util .concurrent .atomic .AtomicBoolean ;
114- import java .util .function .Function ;
115109import java .util .stream .Collectors ;
116110
117111import static org .elasticsearch .index .snapshots .blobstore .BlobStoreIndexShardSnapshot .FileInfo .canonicalName ;
@@ -365,6 +359,8 @@ public void deleteSnapshot(SnapshotId snapshotId, long repositoryStateId, Action
365359 try {
366360 final Map <String , BlobMetaData > rootBlobs = blobContainer ().listBlobs ();
367361 final RepositoryData repositoryData = getRepositoryData (latestGeneration (rootBlobs .keySet ()));
362+ // Cache the indices that were found before writing out the new index-N blob so that a stuck master will never
363+ // delete an index that was created by another master node after writing this index-N blob.
368364 final Map <String , BlobContainer > foundIndices = blobStore ().blobContainer (indicesPath ()).children ();
369365 doDeleteShardSnapshots (snapshotId , repositoryStateId , foundIndices , rootBlobs , repositoryData , listener );
370366 } catch (Exception ex ) {
@@ -390,36 +386,13 @@ private void doDeleteShardSnapshots(SnapshotId snapshotId, long repositoryStateI
390386 Map <String , BlobMetaData > rootBlobs , RepositoryData repositoryData ,
391387 ActionListener <Void > listener ) throws IOException {
392388 final RepositoryData updatedRepositoryData = repositoryData .removeSnapshot (snapshotId );
393- // Cache the indices that were found before writing out the new index-N blob so that a stuck master will never
394- // delete an index that was created by another master node after writing this index-N blob.
395389 writeIndexGen (updatedRepositoryData , repositoryStateId );
396- SnapshotInfo snapshot = null ;
397- try {
398- snapshot = getSnapshotInfo (snapshotId );
399- } catch (SnapshotMissingException ex ) {
400- listener .onFailure (ex );
401- return ;
402- } catch (IllegalStateException | SnapshotException | ElasticsearchParseException ex ) {
403- logger .warn (() -> new ParameterizedMessage ("cannot read snapshot file [{}]" , snapshotId ), ex );
404- }
405- final List <String > snapMetaFilesToDelete =
406- Arrays .asList (snapshotFormat .blobName (snapshotId .getUUID ()), globalMetaDataFormat .blobName (snapshotId .getUUID ()));
407- try {
408- blobContainer ().deleteBlobsIgnoringIfNotExists (snapMetaFilesToDelete );
409- } catch (IOException e ) {
410- logger .warn (() -> new ParameterizedMessage ("[{}] Unable to delete global metadata files" , snapshotId ), e );
411- }
412- final var survivingIndices = updatedRepositoryData .getIndices ();
413390 deleteIndices (
414391 updatedRepositoryData ,
415- Optional .ofNullable (snapshot ).map (info -> info .indices ().stream ().filter (survivingIndices ::containsKey )
416- .map (updatedRepositoryData ::resolveIndexId ).collect (Collectors .toList ())).orElse (Collections .emptyList ()),
392+ repositoryData .indicesToUpdateAfterRemovingSnapshot (snapshotId ),
417393 snapshotId ,
418394 ActionListener .delegateFailure (listener ,
419- (l , v ) -> cleanupStaleBlobs (foundIndices ,
420- Sets .difference (rootBlobs .keySet (), new HashSet <>(snapMetaFilesToDelete )).stream ().collect (
421- Collectors .toMap (Function .identity (), rootBlobs ::get )),
422- updatedRepositoryData , ActionListener .map (l , ignored -> null ))));
395+ (l , v ) -> cleanupStaleBlobs (foundIndices , rootBlobs , updatedRepositoryData , ActionListener .map (l , ignored -> null ))));
423396 }
424397
425398 /**
0 commit comments