Skip to content

Commit f2f1296

Browse files
Fix NPE in Partial Snapshot Without Global State (#55776) (#55784)
We make sure to filter shard generations for indices that are missing from the metadata when finalizing a partial snapshot (from concurrent index deletion) but we failed to account for the case where we manually build a fake metadata instance for snapshots without the global state. Fixed this by handling missing indices by skipping, same way we do it for filtering the shard generations. Relates #50234
1 parent 79c9ef9 commit f2f1296

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,12 @@ private static MetaData metaDataForSnapshot(SnapshotsInProgress.Entry snapshot,
646646
// Remove global state from the cluster state
647647
MetaData.Builder builder = MetaData.builder();
648648
for (IndexId index : snapshot.indices()) {
649-
builder.put(metaData.index(index.getName()), false);
649+
final IndexMetaData indexMetadata = metaData.index(index.getName());
650+
if (indexMetadata == null) {
651+
assert snapshot.partial() : "Index [" + index + "] was deleted during a snapshot but snapshot was not partial.";
652+
} else {
653+
builder.put(indexMetadata, false);
654+
}
650655
}
651656
metaData = builder.build();
652657
}

server/src/test/java/org/elasticsearch/snapshots/SnapshotResiliencyTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ public void testConcurrentSnapshotDeleteAndDeleteIndex() throws IOException {
637637

638638
continueOrDie(createIndicesListener, createIndexResponses ->
639639
client().admin().cluster().prepareCreateSnapshot(repoName, snapshotName).setWaitForCompletion(false)
640-
.setPartial(partialSnapshot).execute(createSnapshotResponseStepListener));
640+
.setPartial(partialSnapshot).setIncludeGlobalState(randomBoolean()).execute(createSnapshotResponseStepListener));
641641

642642
continueOrDie(createSnapshotResponseStepListener,
643643
createSnapshotResponse -> client().admin().indices().delete(new DeleteIndexRequest(index),

0 commit comments

Comments
 (0)