Skip to content

Commit 235b0f8

Browse files
Fix Edge Case Datastream Snapshot Create Bug (#72747) (#72749)
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 f92320a commit 235b0f8

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
@@ -1088,8 +1088,6 @@ private static Metadata metadataForSnapshot(SnapshotsInProgress.Entry snapshot,
10881088
for (Index index : dataStream.getIndices()) {
10891089
final String indexName = index.getName();
10901090
if (builder.get(indexName) == null || indicesInSnapshot.contains(indexName) == false) {
1091-
assert snapshot.partial() : "Data stream [" + dataStreamName +
1092-
"] is missing index [" + index + "] but snapshot was not partial.";
10931091
missingIndex = true;
10941092
break;
10951093
}
@@ -1691,9 +1689,8 @@ private void finalizeSnapshotEntry(SnapshotsInProgress.Entry entry, Metadata met
16911689
final SnapshotInfo snapshotInfo = new SnapshotInfo(
16921690
snapshot.getSnapshotId(),
16931691
finalIndices,
1694-
entry.partial() ? entry.dataStreams().stream()
1695-
.filter(metaForSnapshot.dataStreams()::containsKey)
1696-
.collect(Collectors.toList()) : entry.dataStreams(),
1692+
entry.dataStreams().stream().filter(metaForSnapshot.dataStreams()::containsKey)
1693+
.collect(Collectors.toList()),
16971694
entry.partial() ? onlySuccessfulFeatureStates(entry, finalIndices) : entry.featureStates(),
16981695
failure,
16991696
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)