Skip to content

Commit 4403b69

Browse files
Fix NPE in Partial Snapshot Without Global State (#55776) (#55783)
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 1a3f9e5 commit 4403b69

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
@@ -494,7 +494,12 @@ private static Metadata metadataForSnapshot(SnapshotsInProgress.Entry snapshot,
494494
// Remove global state from the cluster state
495495
Metadata.Builder builder = Metadata.builder();
496496
for (IndexId index : snapshot.indices()) {
497-
builder.put(metadata.index(index.getName()), false);
497+
final IndexMetadata indexMetadata = metadata.index(index.getName());
498+
if (indexMetadata == null) {
499+
assert snapshot.partial() : "Index [" + index + "] was deleted during a snapshot but snapshot was not partial.";
500+
} else {
501+
builder.put(indexMetadata, false);
502+
}
498503
}
499504
metadata = builder.build();
500505
}

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

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

694694
continueOrDie(createIndicesListener, createIndexResponses ->
695695
client().admin().cluster().prepareCreateSnapshot(repoName, snapshotName).setWaitForCompletion(false)
696-
.setPartial(partialSnapshot).execute(createSnapshotResponseStepListener));
696+
.setPartial(partialSnapshot).setIncludeGlobalState(randomBoolean()).execute(createSnapshotResponseStepListener));
697697

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

0 commit comments

Comments
 (0)