27
27
import org .apache .lucene .store .IndexInput ;
28
28
import org .apache .lucene .store .RateLimiter ;
29
29
import org .apache .lucene .util .SetOnce ;
30
- import org .elasticsearch .ElasticsearchParseException ;
31
30
import org .elasticsearch .ExceptionsHelper ;
32
31
import org .elasticsearch .Version ;
33
32
import org .elasticsearch .action .ActionListener ;
62
61
import org .elasticsearch .common .unit .ByteSizeUnit ;
63
62
import org .elasticsearch .common .unit .ByteSizeValue ;
64
63
import org .elasticsearch .common .util .concurrent .AbstractRunnable ;
65
- import org .elasticsearch .common .util .set .Sets ;
66
64
import org .elasticsearch .common .xcontent .LoggingDeprecationHandler ;
67
65
import org .elasticsearch .common .xcontent .NamedXContentRegistry ;
68
66
import org .elasticsearch .common .xcontent .XContentFactory ;
101
99
import java .io .InputStream ;
102
100
import java .nio .file .NoSuchFileException ;
103
101
import java .util .ArrayList ;
104
- import java .util .Arrays ;
105
102
import java .util .Collection ;
106
103
import java .util .Collections ;
107
- import java .util .HashSet ;
108
104
import java .util .List ;
109
105
import java .util .Map ;
110
- import java .util .Optional ;
111
106
import java .util .Set ;
112
107
import java .util .concurrent .Executor ;
113
108
import java .util .concurrent .atomic .AtomicBoolean ;
114
- import java .util .function .Function ;
115
109
import java .util .stream .Collectors ;
116
110
117
111
import static org .elasticsearch .index .snapshots .blobstore .BlobStoreIndexShardSnapshot .FileInfo .canonicalName ;
@@ -365,6 +359,8 @@ public void deleteSnapshot(SnapshotId snapshotId, long repositoryStateId, Action
365
359
try {
366
360
final Map <String , BlobMetaData > rootBlobs = blobContainer ().listBlobs ();
367
361
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.
368
364
final Map <String , BlobContainer > foundIndices = blobStore ().blobContainer (indicesPath ()).children ();
369
365
doDeleteShardSnapshots (snapshotId , repositoryStateId , foundIndices , rootBlobs , repositoryData , listener );
370
366
} catch (Exception ex ) {
@@ -390,36 +386,13 @@ private void doDeleteShardSnapshots(SnapshotId snapshotId, long repositoryStateI
390
386
Map <String , BlobMetaData > rootBlobs , RepositoryData repositoryData ,
391
387
ActionListener <Void > listener ) throws IOException {
392
388
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.
395
389
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 ();
413
390
deleteIndices (
414
391
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 ),
417
393
snapshotId ,
418
394
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 ))));
423
396
}
424
397
425
398
/**
0 commit comments