Skip to content

Commit e683d71

Browse files
Fix Edge Case Datastream Snapshot Create Bug (#72747)
We always clean up the list of datastreams depending on the indices acutally in the snapshot. Even for non-partial snapshots datastream indices could be excluded from the snapshot by index exlusions that remove all the datastream's indices from the snapshot.
1 parent 5523976 commit e683d71

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

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

+2-5
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,6 @@ private static Metadata metadataForSnapshot(SnapshotsInProgress.Entry snapshot,
744744
for (Index index : dataStream.getIndices()) {
745745
final String indexName = index.getName();
746746
if (builder.get(indexName) == null || indicesInSnapshot.contains(indexName) == false) {
747-
assert snapshot.partial() : "Data stream [" + dataStreamName +
748-
"] is missing index [" + index + "] but snapshot was not partial.";
749747
missingIndex = true;
750748
break;
751749
}
@@ -1300,9 +1298,8 @@ private void finalizeSnapshotEntry(SnapshotsInProgress.Entry entry, Metadata met
13001298
final SnapshotInfo snapshotInfo = new SnapshotInfo(
13011299
snapshot.getSnapshotId(),
13021300
finalIndices,
1303-
entry.partial() ? entry.dataStreams().stream()
1304-
.filter(metaForSnapshot.dataStreams()::containsKey)
1305-
.collect(Collectors.toList()) : entry.dataStreams(),
1301+
entry.dataStreams().stream().filter(metaForSnapshot.dataStreams()::containsKey)
1302+
.collect(Collectors.toList()),
13061303
entry.partial() ? onlySuccessfulFeatureStates(entry, finalIndices) : entry.featureStates(),
13071304
failure,
13081305
threadPool.absoluteTimeInMillis(),

x-pack/plugin/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamsSnapshotsIT.java

+18
Original file line numberDiff line numberDiff line change
@@ -710,4 +710,22 @@ public void testSnapshotDSDuringRolloverAndDeleteOldIndex() throws Exception {
710710
assertEquals(restoreSnapshotResponse.successfulShards(), restoreSnapshotResponse.totalShards());
711711
assertEquals(restoreSnapshotResponse.failedShards(), 0);
712712
}
713+
714+
public void testExcludeDSFromSnapshotWhenExcludingItsIndices() {
715+
final String snapshot = "test-snapshot";
716+
final String indexWithoutDataStream = "test-idx-no-ds";
717+
createIndexWithContent(indexWithoutDataStream);
718+
final SnapshotInfo snapshotInfo = createSnapshot(REPO, snapshot, List.of("*", "-.*"));
719+
assertThat(snapshotInfo.dataStreams(), empty());
720+
assertAcked(client.admin().indices().prepareDelete(indexWithoutDataStream));
721+
RestoreInfo restoreInfo = client.admin()
722+
.cluster()
723+
.prepareRestoreSnapshot(REPO, snapshot)
724+
.setWaitForCompletion(true)
725+
.setRestoreGlobalState(randomBoolean())
726+
.get()
727+
.getRestoreInfo();
728+
assertThat(restoreInfo.failedShards(), is(0));
729+
assertThat(restoreInfo.successfulShards(), is(1));
730+
}
713731
}

0 commit comments

Comments
 (0)