Skip to content

Commit b899a27

Browse files
Snapshot _status API to return correct status for partial snapshots (opensearch-project#12812)
* Snapshot _status API to return correct status for partial snapshots Signed-off-by: aggarwalShivani <shivani.aggarwal@nokia.com> * Updated CHANGELOG.md Signed-off-by: aggarwalShivani <shivani.aggarwal@nokia.com> * Updated test case Signed-off-by: aggarwalShivani <shivani.aggarwal@nokia.com> * Setting snapshot status to SUCCESS for older versions for bwc Signed-off-by: aggarwalShivani <shivani.aggarwal@nokia.com> * Setting snapshot status to SUCCESS for older versions for bwc Signed-off-by: aggarwalShivani <shivani.aggarwal@nokia.com> * Moved BWC change to SnapshotsInProgress.java for partial snapshots Signed-off-by: aggarwalShivani <shivani.aggarwal@nokia.com> * Fix for flaky test testSnapshotStatusOnPartialSnapshot Signed-off-by: aggarwalShivani <shivani.aggarwal@nokia.com> * Updated the testcases to reuse existing getSnapshotStatus() method Signed-off-by: aggarwalShivani <shivani.aggarwal@nokia.com> * Fixed formatting issues detected in spotlessJavaCheck Signed-off-by: aggarwalShivani <shivani.aggarwal@nokia.com> * Moved the entry to CHANGELOG.md Signed-off-by: aggarwalShivani <shivani.aggarwal@nokia.com> --------- Signed-off-by: aggarwalShivani <shivani.aggarwal@nokia.com> Signed-off-by: aggarwalShivani <39588384+aggarwalShivani@users.noreply.github.com>
1 parent 1fcb79d commit b899a27

File tree

5 files changed

+34
-15
lines changed

5 files changed

+34
-15
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5656
- Fix UOE While building Exists query for nested search_as_you_type field ([#12048](https://github.com/opensearch-project/OpenSearch/pull/12048))
5757
- Client with Java 8 runtime and Apache HttpClient 5 Transport fails with java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer ([#13100](https://github.com/opensearch-project/opensearch-java/pull/13100))
5858
- Fix implement mark() and markSupported() in class FilterStreamInput ([#13098](https://github.com/opensearch-project/OpenSearch/pull/13098))
59+
- Fix snapshot _status API to return correct status for partial snapshots ([#12812](https://github.com/opensearch-project/OpenSearch/pull/12812))
5960

6061
### Security
6162

server/src/internalClusterTest/java/org/opensearch/snapshots/DedicatedClusterSnapshotRestoreIT.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ public void testRestoreIndexWithMissingShards() throws Exception {
572572
List<SnapshotStatus> snapshotStatuses = snapshotsStatusResponse.getSnapshots();
573573
assertEquals(snapshotStatuses.size(), 1);
574574
logger.trace("current snapshot status [{}]", snapshotStatuses.get(0));
575-
assertTrue(snapshotStatuses.get(0).getState().completed());
575+
assertThat(getSnapshot("test-repo", "test-snap-2").state(), equalTo(SnapshotState.PARTIAL));
576576
}, 1, TimeUnit.MINUTES);
577577
SnapshotsStatusResponse snapshotsStatusResponse = clusterAdmin().prepareSnapshotStatus("test-repo")
578578
.setSnapshots("test-snap-2")
@@ -589,7 +589,6 @@ public void testRestoreIndexWithMissingShards() throws Exception {
589589
// After it was marked as completed in the cluster state - we need to check if it's completed on the file system as well
590590
assertBusy(() -> {
591591
SnapshotInfo snapshotInfo = getSnapshot("test-repo", "test-snap-2");
592-
assertTrue(snapshotInfo.state().completed());
593592
assertEquals(SnapshotState.PARTIAL, snapshotInfo.state());
594593
}, 1, TimeUnit.MINUTES);
595594
} else {

server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotStatusApisIT.java

+19-8
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import org.opensearch.action.admin.cluster.snapshots.status.SnapshotIndexShardStatus;
4141
import org.opensearch.action.admin.cluster.snapshots.status.SnapshotStats;
4242
import org.opensearch.action.admin.cluster.snapshots.status.SnapshotStatus;
43-
import org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest;
4443
import org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse;
4544
import org.opensearch.client.Client;
4645
import org.opensearch.cluster.SnapshotsInProgress;
@@ -101,13 +100,9 @@ public void testStatusApiConsistency() {
101100
assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS));
102101
assertThat(snapshotInfo.version(), equalTo(Version.CURRENT));
103102

104-
final List<SnapshotStatus> snapshotStatus = clusterAdmin().snapshotsStatus(
105-
new SnapshotsStatusRequest("test-repo", new String[] { "test-snap" })
106-
).actionGet().getSnapshots();
107-
assertThat(snapshotStatus.size(), equalTo(1));
108-
final SnapshotStatus snStatus = snapshotStatus.get(0);
109-
assertEquals(snStatus.getStats().getStartTime(), snapshotInfo.startTime());
110-
assertEquals(snStatus.getStats().getTime(), snapshotInfo.endTime() - snapshotInfo.startTime());
103+
final SnapshotStatus snapshotStatus = getSnapshotStatus("test-repo", "test-snap");
104+
assertEquals(snapshotStatus.getStats().getStartTime(), snapshotInfo.startTime());
105+
assertEquals(snapshotStatus.getStats().getTime(), snapshotInfo.endTime() - snapshotInfo.startTime());
111106
}
112107

113108
public void testStatusAPICallForShallowCopySnapshot() {
@@ -357,6 +352,22 @@ public void testSnapshotStatusOnFailedSnapshot() throws Exception {
357352
assertEquals(SnapshotsInProgress.State.FAILED, snapshotsStatusResponse.getSnapshots().get(0).getState());
358353
}
359354

355+
public void testSnapshotStatusOnPartialSnapshot() throws Exception {
356+
final String dataNode = internalCluster().startDataOnlyNode();
357+
final String repoName = "test-repo";
358+
final String snapshotName = "test-snap";
359+
final String indexName = "test-idx";
360+
createRepository(repoName, "fs");
361+
// create an index with a single shard on the data node, that will be stopped
362+
createIndex(indexName, singleShardOneNode(dataNode));
363+
index(indexName, "_doc", "some_doc_id", "foo", "bar");
364+
logger.info("--> stopping data node before creating snapshot");
365+
stopNode(dataNode);
366+
startFullSnapshot(repoName, snapshotName, true).get();
367+
final SnapshotStatus snapshotStatus = getSnapshotStatus(repoName, snapshotName);
368+
assertEquals(SnapshotsInProgress.State.PARTIAL, snapshotStatus.getState());
369+
}
370+
360371
public void testStatusAPICallInProgressShallowSnapshot() throws Exception {
361372
internalCluster().startClusterManagerOnlyNode();
362373
internalCluster().startDataOnlyNode();

server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,11 @@ private void loadRepositoryData(
356356
state = SnapshotsInProgress.State.FAILED;
357357
break;
358358
case SUCCESS:
359-
case PARTIAL:
360-
// Translating both PARTIAL and SUCCESS to SUCCESS for now
361-
// TODO: add the differentiation on the metadata level in the next major release
362359
state = SnapshotsInProgress.State.SUCCESS;
363360
break;
361+
case PARTIAL:
362+
state = SnapshotsInProgress.State.PARTIAL;
363+
break;
364364
default:
365365
throw new IllegalArgumentException("Unknown snapshot state " + snapshotInfo.state());
366366
}

server/src/main/java/org/opensearch/cluster/SnapshotsInProgress.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,12 @@ public void writeTo(StreamOutput out) throws IOException {
747747
snapshot.writeTo(out);
748748
out.writeBoolean(includeGlobalState);
749749
out.writeBoolean(partial);
750-
out.writeByte(state.value());
750+
if ((out.getVersion().before(Version.V_3_0_0)) && state == State.PARTIAL) {
751+
// Setting to SUCCESS for partial snapshots in older versions to maintain backward compatibility
752+
out.writeByte(State.SUCCESS.value());
753+
} else {
754+
out.writeByte(state.value());
755+
}
751756
out.writeList(indices);
752757
out.writeLong(startTime);
753758
out.writeMap(shards, (o, v) -> v.writeTo(o), (o, v) -> v.writeTo(o));
@@ -937,7 +942,8 @@ public enum State {
937942
STARTED((byte) 1, false),
938943
SUCCESS((byte) 2, true),
939944
FAILED((byte) 3, true),
940-
ABORTED((byte) 4, false);
945+
ABORTED((byte) 4, false),
946+
PARTIAL((byte) 5, false);
941947

942948
private final byte value;
943949

@@ -968,6 +974,8 @@ public static State fromValue(byte value) {
968974
return FAILED;
969975
case 4:
970976
return ABORTED;
977+
case 5:
978+
return PARTIAL;
971979
default:
972980
throw new IllegalArgumentException("No snapshot state for value [" + value + "]");
973981
}

0 commit comments

Comments
 (0)