Skip to content

Commit a94e7de

Browse files
Fix NPE in Partial Snapshot Without Global State
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 elastic#50234
1 parent d903ff9 commit a94e7de

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
@@ -484,7 +484,12 @@ private static Metadata metadataForSnapshot(SnapshotsInProgress.Entry snapshot,
484484
// Remove global state from the cluster state
485485
Metadata.Builder builder = Metadata.builder();
486486
for (IndexId index : snapshot.indices()) {
487-
builder.put(metadata.index(index.getName()), false);
487+
final IndexMetadata indexMetadata = metadata.index(index.getName());
488+
if (indexMetadata == null) {
489+
assert snapshot.partial() : "Index [" + index + "] was deleted during a snapshot but snapshot was not partial.";
490+
} else {
491+
builder.put(indexMetadata, false);
492+
}
488493
}
489494
metadata = builder.build();
490495
}

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

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

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

696696
continueOrDie(createSnapshotResponseStepListener,
697697
createSnapshotResponse -> client().admin().indices().delete(new DeleteIndexRequest(index), new ActionListener<>() {

0 commit comments

Comments
 (0)