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 ;
6160import org .elasticsearch .common .unit .ByteSizeUnit ;
6261import org .elasticsearch .common .unit .ByteSizeValue ;
6362import org .elasticsearch .common .util .concurrent .AbstractRunnable ;
64- import org .elasticsearch .common .util .set .Sets ;
6563import org .elasticsearch .common .xcontent .LoggingDeprecationHandler ;
6664import org .elasticsearch .common .xcontent .NamedXContentRegistry ;
6765import 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 ;
@@ -407,6 +401,8 @@ public void deleteSnapshot(SnapshotId snapshotId, long repositoryStateId, Action
407401 try {
408402 final Map <String , BlobMetaData > rootBlobs = blobContainer ().listBlobs ();
409403 final RepositoryData repositoryData = getRepositoryData (latestGeneration (rootBlobs .keySet ()));
404+ // Cache the indices that were found before writing out the new index-N blob so that a stuck master will never
405+ // delete an index that was created by another master node after writing this index-N blob.
410406 final Map <String , BlobContainer > foundIndices = blobStore ().blobContainer (indicesPath ()).children ();
411407 doDeleteShardSnapshots (snapshotId , repositoryStateId , foundIndices , rootBlobs , repositoryData , listener );
412408 } catch (Exception ex ) {
@@ -432,36 +428,13 @@ private void doDeleteShardSnapshots(SnapshotId snapshotId, long repositoryStateI
432428 Map <String , BlobMetaData > rootBlobs , RepositoryData repositoryData ,
433429 ActionListener <Void > listener ) throws IOException {
434430 final RepositoryData updatedRepositoryData = repositoryData .removeSnapshot (snapshotId );
435- // Cache the indices that were found before writing out the new index-N blob so that a stuck master will never
436- // delete an index that was created by another master node after writing this index-N blob.
437431 writeIndexGen (updatedRepositoryData , repositoryStateId );
438- SnapshotInfo snapshot = null ;
439- try {
440- snapshot = getSnapshotInfo (snapshotId );
441- } catch (SnapshotMissingException ex ) {
442- listener .onFailure (ex );
443- return ;
444- } catch (IllegalStateException | SnapshotException | ElasticsearchParseException ex ) {
445- logger .warn (() -> new ParameterizedMessage ("cannot read snapshot file [{}]" , snapshotId ), ex );
446- }
447- final List <String > snapMetaFilesToDelete =
448- Arrays .asList (snapshotFormat .blobName (snapshotId .getUUID ()), globalMetaDataFormat .blobName (snapshotId .getUUID ()));
449- try {
450- blobContainer ().deleteBlobsIgnoringIfNotExists (snapMetaFilesToDelete );
451- } catch (IOException e ) {
452- logger .warn (() -> new ParameterizedMessage ("[{}] Unable to delete global metadata files" , snapshotId ), e );
453- }
454- final Map <String , IndexId > survivingIndices = updatedRepositoryData .getIndices ();
455432 deleteIndices (
456433 updatedRepositoryData ,
457- Optional .ofNullable (snapshot ).map (info -> info .indices ().stream ().filter (survivingIndices ::containsKey )
458- .map (updatedRepositoryData ::resolveIndexId ).collect (Collectors .toList ())).orElse (Collections .emptyList ()),
434+ repositoryData .indicesToUpdateAfterRemovingSnapshot (snapshotId ),
459435 snapshotId ,
460436 ActionListener .delegateFailure (listener ,
461- (l , v ) -> cleanupStaleBlobs (foundIndices ,
462- Sets .difference (rootBlobs .keySet (), new HashSet <>(snapMetaFilesToDelete )).stream ().collect (
463- Collectors .toMap (Function .identity (), rootBlobs ::get )),
464- updatedRepositoryData , ActionListener .map (l , ignored -> null ))));
437+ (l , v ) -> cleanupStaleBlobs (foundIndices , rootBlobs , updatedRepositoryData , ActionListener .map (l , ignored -> null ))));
465438 }
466439
467440 /**
0 commit comments