Skip to content

Commit c37d5f6

Browse files
anshu1106Anshu Agarwal
and
Anshu Agarwal
authored
Modify create snapshot response when wait_for_completion is false (opensearch-project#15499)
Signed-off-by: Anshu Agarwal <anshukag@amazon.com> Co-authored-by: Anshu Agarwal <anshukag@amazon.com>
1 parent 758c2aa commit c37d5f6

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

server/src/internalClusterTest/java/org/opensearch/remotestore/RemoteRestoreSnapshotIT.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -839,18 +839,13 @@ public void testCreateSnapshotV2() throws Exception {
839839

840840
String snapshotName2 = "test-create-snapshot2";
841841

842-
// verify even if waitForCompletion is not true, the request executes in a sync manner
843-
CreateSnapshotResponse createSnapshotResponse2 = client().admin()
842+
// verify response status if waitForCompletion is not true
843+
RestStatus createSnapshotResponseStatus = client().admin()
844844
.cluster()
845845
.prepareCreateSnapshot(snapshotRepoName, snapshotName2)
846-
.get();
847-
snapshotInfo = createSnapshotResponse2.getSnapshotInfo();
848-
assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS));
849-
assertThat(snapshotInfo.successfulShards(), greaterThan(0));
850-
assertThat(snapshotInfo.successfulShards(), equalTo(snapshotInfo.totalShards()));
851-
assertThat(snapshotInfo.snapshotId().getName(), equalTo(snapshotName2));
852-
assertThat(snapshotInfo.getPinnedTimestamp(), greaterThan(0L));
853-
846+
.get()
847+
.status();
848+
assertEquals(RestStatus.ACCEPTED, createSnapshotResponseStatus);
854849
}
855850

856851
public void testMixedSnapshotCreationWithV2RepositorySetting() throws Exception {
@@ -914,6 +909,7 @@ public void testMixedSnapshotCreationWithV2RepositorySetting() throws Exception
914909
CreateSnapshotResponse createSnapshotResponse2 = client().admin()
915910
.cluster()
916911
.prepareCreateSnapshot(snapshotRepoName, snapshotName2)
912+
.setWaitForCompletion(true)
917913
.get();
918914
snapshotInfo = createSnapshotResponse2.getSnapshotInfo();
919915
assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS));
@@ -968,6 +964,7 @@ public void testConcurrentSnapshotV2CreateOperation() throws InterruptedExceptio
968964
CreateSnapshotResponse createSnapshotResponse2 = client().admin()
969965
.cluster()
970966
.prepareCreateSnapshot(snapshotRepoName, snapshotName)
967+
.setWaitForCompletion(true)
971968
.get();
972969
SnapshotInfo snapshotInfo = createSnapshotResponse2.getSnapshotInfo();
973970
assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS));
@@ -1036,6 +1033,7 @@ public void testCreateSnapshotV2WithRedIndex() throws Exception {
10361033
CreateSnapshotResponse createSnapshotResponse2 = client().admin()
10371034
.cluster()
10381035
.prepareCreateSnapshot(snapshotRepoName, snapshotName1)
1036+
.setWaitForCompletion(true)
10391037
.get();
10401038
SnapshotInfo snapshotInfo = createSnapshotResponse2.getSnapshotInfo();
10411039
assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS));
@@ -1097,6 +1095,7 @@ public void testCreateSnapshotV2WithIndexingLoad() throws Exception {
10971095
CreateSnapshotResponse createSnapshotResponse2 = client().admin()
10981096
.cluster()
10991097
.prepareCreateSnapshot(snapshotRepoName, snapshotName1)
1098+
.setWaitForCompletion(true)
11001099
.get();
11011100

11021101
SnapshotInfo snapshotInfo = createSnapshotResponse2.getSnapshotInfo();
@@ -1203,6 +1202,7 @@ public void testClusterManagerFailoverDuringSnapshotCreation() throws Exception
12031202
CreateSnapshotResponse createSnapshotResponse = client().admin()
12041203
.cluster()
12051204
.prepareCreateSnapshot(snapshotRepoName, snapshotName1)
1205+
.setWaitForCompletion(true)
12061206
.get();
12071207
snapshotInfo[0] = createSnapshotResponse.getSnapshotInfo();
12081208

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/create/TransportCreateSnapshotAction.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,10 @@ protected void clusterManagerOperation(
113113
) {
114114
Repository repository = repositoriesService.repository(request.repository());
115115
boolean isSnapshotV2 = SHALLOW_SNAPSHOT_V2.get(repository.getMetadata().settings());
116-
if (request.waitForCompletion() || isSnapshotV2) {
116+
if (request.waitForCompletion()) {
117117
snapshotsService.executeSnapshot(request, ActionListener.map(listener, CreateSnapshotResponse::new));
118+
} else if (isSnapshotV2) {
119+
snapshotsService.executeSnapshot(request, ActionListener.map(listener, snapshot -> new CreateSnapshotResponse()));
118120
} else {
119121
snapshotsService.createSnapshot(request, ActionListener.map(listener, snapshot -> new CreateSnapshotResponse()));
120122
}

0 commit comments

Comments
 (0)