Skip to content

Commit c061964

Browse files
Fix Default Restore not Restoring Indices when DS are Restored (#75266)
There was a simple bug that caused the default to `*` or `_all` on the request to not work anymore when resolving what indices to restore because we would add datastream indices to the restore array, thus causing the indices filtering to think we only wanted those specific indices. closes #75192
1 parent 379fad1 commit c061964

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777

7878
import java.io.IOException;
7979
import java.util.ArrayList;
80-
import java.util.Arrays;
8180
import java.util.Collection;
8281
import java.util.Collections;
8382
import java.util.HashMap;
@@ -308,7 +307,14 @@ private void startRestore(
308307
metadataBuilder = Metadata.builder();
309308
}
310309

311-
List<String> requestIndices = new ArrayList<>(Arrays.asList(request.indices()));
310+
final String[] indicesInRequest = request.indices();
311+
List<String> requestIndices = new ArrayList<>(indicesInRequest.length);
312+
if (indicesInRequest.length == 0) {
313+
// no specific indices request means restore everything
314+
requestIndices.add("*");
315+
} else {
316+
Collections.addAll(requestIndices, indicesInRequest);
317+
}
312318

313319
// Get data stream metadata for requested data streams
314320
Tuple<Map<String, DataStream>, Map<String, DataStreamAlias>> result = getDataStreamsToRestore(

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,4 +997,25 @@ public void testExcludeDSFromSnapshotWhenExcludingItsIndices() {
997997
assertThat(restoreInfo.failedShards(), is(0));
998998
assertThat(restoreInfo.successfulShards(), is(1));
999999
}
1000+
1001+
public void testRestoreSnapshotFully() throws Exception {
1002+
final String snapshotName = "test-snapshot";
1003+
final String indexName = "test-idx";
1004+
createIndexWithContent(indexName);
1005+
createFullSnapshot(REPO, snapshotName);
1006+
1007+
assertAcked(client.execute(DeleteDataStreamAction.INSTANCE, new DeleteDataStreamAction.Request(new String[] { "*" })).get());
1008+
assertAcked(client.admin().indices().prepareDelete("*").setIndicesOptions(IndicesOptions.lenientExpandOpenHidden()).get());
1009+
1010+
RestoreSnapshotResponse restoreSnapshotResponse = client.admin()
1011+
.cluster()
1012+
.prepareRestoreSnapshot(REPO, snapshotName)
1013+
.setWaitForCompletion(true)
1014+
.get();
1015+
assertEquals(RestStatus.OK, restoreSnapshotResponse.status());
1016+
1017+
GetDataStreamAction.Request getRequest = new GetDataStreamAction.Request(new String[] { "*" });
1018+
assertThat(client.execute(GetDataStreamAction.INSTANCE, getRequest).get().getDataStreams(), hasSize(2));
1019+
assertNotNull(client.admin().indices().prepareGetIndex().setIndices(indexName).get());
1020+
}
10001021
}

0 commit comments

Comments
 (0)