Skip to content

Commit 7aa6286

Browse files
Fix Edge Case Datastream Snapshot Create Bug (#72747) (#72748)
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 95f9fce commit 7aa6286

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,8 +1092,6 @@ private static Metadata metadataForSnapshot(SnapshotsInProgress.Entry snapshot,
10921092
for (Index index : dataStream.getIndices()) {
10931093
final String indexName = index.getName();
10941094
if (builder.get(indexName) == null || indicesInSnapshot.contains(indexName) == false) {
1095-
assert snapshot.partial() : "Data stream [" + dataStreamName +
1096-
"] is missing index [" + index + "] but snapshot was not partial.";
10971095
missingIndex = true;
10981096
break;
10991097
}
@@ -1695,9 +1693,8 @@ private void finalizeSnapshotEntry(SnapshotsInProgress.Entry entry, Metadata met
16951693
final SnapshotInfo snapshotInfo = new SnapshotInfo(
16961694
snapshot.getSnapshotId(),
16971695
finalIndices,
1698-
entry.partial() ? entry.dataStreams().stream()
1699-
.filter(metaForSnapshot.dataStreams()::containsKey)
1700-
.collect(Collectors.toList()) : entry.dataStreams(),
1696+
entry.dataStreams().stream().filter(metaForSnapshot.dataStreams()::containsKey)
1697+
.collect(Collectors.toList()),
17011698
entry.partial() ? onlySuccessfulFeatureStates(entry, finalIndices) : entry.featureStates(),
17021699
failure,
17031700
threadPool.absoluteTimeInMillis(),

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,4 +715,22 @@ public void testSnapshotDSDuringRolloverAndDeleteOldIndex() throws Exception {
715715
assertEquals(restoreSnapshotResponse.successfulShards(), restoreSnapshotResponse.totalShards());
716716
assertEquals(restoreSnapshotResponse.failedShards(), 0);
717717
}
718+
719+
public void testExcludeDSFromSnapshotWhenExcludingItsIndices() {
720+
final String snapshot = "test-snapshot";
721+
final String indexWithoutDataStream = "test-idx-no-ds";
722+
createIndexWithContent(indexWithoutDataStream);
723+
final SnapshotInfo snapshotInfo = createSnapshot(REPO, snapshot, List.of("*", "-.*"));
724+
assertThat(snapshotInfo.dataStreams(), empty());
725+
assertAcked(client.admin().indices().prepareDelete(indexWithoutDataStream));
726+
RestoreInfo restoreInfo = client.admin()
727+
.cluster()
728+
.prepareRestoreSnapshot(REPO, snapshot)
729+
.setWaitForCompletion(true)
730+
.setRestoreGlobalState(randomBoolean())
731+
.get()
732+
.getRestoreInfo();
733+
assertThat(restoreInfo.failedShards(), is(0));
734+
assertThat(restoreInfo.successfulShards(), is(1));
735+
}
718736
}

0 commit comments

Comments
 (0)