Skip to content

Commit 89a7d75

Browse files
authored
[Backport] Modify create snapshot v2 response when wait_for_completion is false (opensearch-project#15615)
Signed-off-by: Anshu Agarwal <anshukag@amazon.com>
1 parent 62e943c commit 89a7d75

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -845,18 +845,13 @@ public void testCreateSnapshotV2() throws Exception {
845845

846846
String snapshotName2 = "test-create-snapshot2";
847847

848-
// verify even if waitForCompletion is not true, the request executes in a sync manner
849-
CreateSnapshotResponse createSnapshotResponse2 = client().admin()
848+
// verify response status if waitForCompletion is not true
849+
RestStatus createSnapshotResponseStatus = client().admin()
850850
.cluster()
851851
.prepareCreateSnapshot(snapshotRepoName, snapshotName2)
852-
.get();
853-
snapshotInfo = createSnapshotResponse2.getSnapshotInfo();
854-
assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS));
855-
assertThat(snapshotInfo.successfulShards(), greaterThan(0));
856-
assertThat(snapshotInfo.successfulShards(), equalTo(snapshotInfo.totalShards()));
857-
assertThat(snapshotInfo.snapshotId().getName(), equalTo(snapshotName2));
858-
assertThat(snapshotInfo.getPinnedTimestamp(), greaterThan(0L));
859-
852+
.get()
853+
.status();
854+
assertEquals(RestStatus.ACCEPTED, createSnapshotResponseStatus);
860855
}
861856

862857
public void testMixedSnapshotCreationWithV2RepositorySetting() throws Exception {
@@ -932,6 +927,7 @@ public void testMixedSnapshotCreationWithV2RepositorySetting() throws Exception
932927
CreateSnapshotResponse createSnapshotResponse2 = client().admin()
933928
.cluster()
934929
.prepareCreateSnapshot(snapshotRepoName, snapshotName2)
930+
.setWaitForCompletion(true)
935931
.get();
936932
snapshotInfo = createSnapshotResponse2.getSnapshotInfo();
937933
assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS));
@@ -993,6 +989,7 @@ public void testConcurrentSnapshotV2CreateOperation() throws InterruptedExceptio
993989
CreateSnapshotResponse createSnapshotResponse2 = client().admin()
994990
.cluster()
995991
.prepareCreateSnapshot(snapshotRepoName, snapshotName)
992+
.setWaitForCompletion(true)
996993
.get();
997994
SnapshotInfo snapshotInfo = createSnapshotResponse2.getSnapshotInfo();
998995
assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS));
@@ -1068,6 +1065,7 @@ public void testCreateSnapshotV2WithRedIndex() throws Exception {
10681065
CreateSnapshotResponse createSnapshotResponse2 = client().admin()
10691066
.cluster()
10701067
.prepareCreateSnapshot(snapshotRepoName, snapshotName1)
1068+
.setWaitForCompletion(true)
10711069
.get();
10721070
SnapshotInfo snapshotInfo = createSnapshotResponse2.getSnapshotInfo();
10731071
assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS));
@@ -1136,6 +1134,7 @@ public void testCreateSnapshotV2WithIndexingLoad() throws Exception {
11361134
CreateSnapshotResponse createSnapshotResponse2 = client().admin()
11371135
.cluster()
11381136
.prepareCreateSnapshot(snapshotRepoName, snapshotName1)
1137+
.setWaitForCompletion(true)
11391138
.get();
11401139

11411140
SnapshotInfo snapshotInfo = createSnapshotResponse2.getSnapshotInfo();
@@ -1256,6 +1255,7 @@ public void testClusterManagerFailoverDuringSnapshotCreation() throws Exception
12561255
CreateSnapshotResponse createSnapshotResponse = client().admin()
12571256
.cluster()
12581257
.prepareCreateSnapshot(snapshotRepoName, snapshotName1)
1258+
.setWaitForCompletion(true)
12591259
.get();
12601260
snapshotInfo[0] = createSnapshotResponse.getSnapshotInfo();
12611261

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,22 @@ protected void clusterManagerOperation(
111111
ClusterState state,
112112
final ActionListener<CreateSnapshotResponse> listener
113113
) {
114+
114115
if (state.nodes().getMinNodeVersion().before(SnapshotsService.NO_REPO_INITIALIZE_VERSION)) {
115116
if (request.waitForCompletion()) {
116117
snapshotsService.executeSnapshotLegacy(request, ActionListener.map(listener, CreateSnapshotResponse::new));
117118
} else {
118119
snapshotsService.createSnapshotLegacy(request, ActionListener.map(listener, snapshot -> new CreateSnapshotResponse()));
119120
}
121+
120122
} else {
121123
Repository repository = repositoriesService.repository(request.repository());
122124
boolean isSnapshotV2 = SHALLOW_SNAPSHOT_V2.get(repository.getMetadata().settings());
123125

124-
if (request.waitForCompletion() || isSnapshotV2) {
126+
if (request.waitForCompletion()) {
125127
snapshotsService.executeSnapshot(request, ActionListener.map(listener, CreateSnapshotResponse::new));
128+
} else if (isSnapshotV2) {
129+
snapshotsService.executeSnapshot(request, ActionListener.map(listener, snapshot -> new CreateSnapshotResponse()));
126130
} else {
127131
snapshotsService.createSnapshot(request, ActionListener.map(listener, snapshot -> new CreateSnapshotResponse()));
128132
}

0 commit comments

Comments
 (0)