@@ -568,16 +568,17 @@ public void onNoLongerMaster() {
568
568
private void cleanupAfterError (Exception exception ) {
569
569
threadPool .generic ().execute (() -> {
570
570
if (snapshotCreated ) {
571
+ final MetaData metaData = clusterService .state ().metaData ();
571
572
repositoriesService .repository (snapshot .snapshot ().getRepository ())
572
573
.finalizeSnapshot (snapshot .snapshot ().getSnapshotId (),
573
- buildGenerations (snapshot ),
574
+ buildGenerations (snapshot , metaData ),
574
575
snapshot .startTime (),
575
576
ExceptionsHelper .stackTrace (exception ),
576
577
0 ,
577
578
Collections .emptyList (),
578
579
snapshot .repositoryStateId (),
579
580
snapshot .includeGlobalState (),
580
- metaDataForSnapshot (snapshot , clusterService . state (). metaData () ),
581
+ metaDataForSnapshot (snapshot , metaData ),
581
582
snapshot .userMetadata (),
582
583
snapshot .useShardGenerations (),
583
584
ActionListener .runAfter (ActionListener .wrap (ignored -> {
@@ -593,11 +594,22 @@ private void cleanupAfterError(Exception exception) {
593
594
}
594
595
}
595
596
596
- private static ShardGenerations buildGenerations (SnapshotsInProgress .Entry snapshot ) {
597
+ private static ShardGenerations buildGenerations (SnapshotsInProgress .Entry snapshot , MetaData metaData ) {
597
598
ShardGenerations .Builder builder = ShardGenerations .builder ();
598
599
final Map <String , IndexId > indexLookup = new HashMap <>();
599
- snapshot .indices ().forEach (idx -> indexLookup .put (idx .getName (), idx ));
600
- snapshot .shards ().forEach (c -> builder .put (indexLookup .get (c .key .getIndexName ()), c .key .id (), c .value .generation ()));
600
+ snapshot .indices ().forEach (idx -> {
601
+ if (metaData .index (idx .getName ()) != null ) {
602
+ indexLookup .put (idx .getName (), idx );
603
+ } else {
604
+ assert snapshot .partial () : "Index [" + idx + "] was deleted during a snapshot but snapshot was not partial." ;
605
+ }
606
+ });
607
+ snapshot .shards ().forEach (c -> {
608
+ final IndexId indexId = indexLookup .get (c .key .getIndexName ());
609
+ if (indexId != null ) {
610
+ builder .put (indexId , c .key .id (), c .value .generation ());
611
+ }
612
+ });
601
613
return builder .build ();
602
614
}
603
615
@@ -1034,7 +1046,7 @@ protected void doRun() {
1034
1046
}
1035
1047
repository .finalizeSnapshot (
1036
1048
snapshot .getSnapshotId (),
1037
- buildGenerations (entry ),
1049
+ buildGenerations (entry , metaData ),
1038
1050
entry .startTime (),
1039
1051
failure ,
1040
1052
entry .shards ().size (),
0 commit comments