From a94e7ded1d5655594b7ccd77c66720e7f835645e Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Sun, 26 Apr 2020 20:30:49 +0200 Subject: [PATCH] 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 #50234 --- .../java/org/elasticsearch/snapshots/SnapshotsService.java | 7 ++++++- .../elasticsearch/snapshots/SnapshotResiliencyTests.java | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java b/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java index 5e00ddbd545ce..83a88e56b4fa5 100644 --- a/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java +++ b/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java @@ -484,7 +484,12 @@ private static Metadata metadataForSnapshot(SnapshotsInProgress.Entry snapshot, // Remove global state from the cluster state Metadata.Builder builder = Metadata.builder(); for (IndexId index : snapshot.indices()) { - builder.put(metadata.index(index.getName()), false); + final IndexMetadata indexMetadata = metadata.index(index.getName()); + if (indexMetadata == null) { + assert snapshot.partial() : "Index [" + index + "] was deleted during a snapshot but snapshot was not partial."; + } else { + builder.put(indexMetadata, false); + } } metadata = builder.build(); } diff --git a/server/src/test/java/org/elasticsearch/snapshots/SnapshotResiliencyTests.java b/server/src/test/java/org/elasticsearch/snapshots/SnapshotResiliencyTests.java index 4ddd2dec5bb28..0c38191120135 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/SnapshotResiliencyTests.java +++ b/server/src/test/java/org/elasticsearch/snapshots/SnapshotResiliencyTests.java @@ -691,7 +691,7 @@ public void testConcurrentSnapshotDeleteAndDeleteIndex() throws IOException { continueOrDie(createIndicesListener, createIndexResponses -> client().admin().cluster().prepareCreateSnapshot(repoName, snapshotName).setWaitForCompletion(false) - .setPartial(partialSnapshot).execute(createSnapshotResponseStepListener)); + .setPartial(partialSnapshot).setIncludeGlobalState(randomBoolean()).execute(createSnapshotResponseStepListener)); continueOrDie(createSnapshotResponseStepListener, createSnapshotResponse -> client().admin().indices().delete(new DeleteIndexRequest(index), new ActionListener<>() {