Skip to content

Commit a4f9515

Browse files
committed
Added reporting of snapshot status PARTIAL on _status endpoint (elastic#28692)
1 parent 5a8ec9b commit a4f9515

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,11 @@ private SnapshotsStatusResponse buildResponse(SnapshotsStatusRequest request, Li
242242
state = SnapshotsInProgress.State.FAILED;
243243
break;
244244
case SUCCESS:
245-
case PARTIAL:
246-
// Translating both PARTIAL and SUCCESS to SUCCESS for now
247-
// TODO: add the differentiation on the metadata level in the next major release
248245
state = SnapshotsInProgress.State.SUCCESS;
249246
break;
247+
case PARTIAL:
248+
state = SnapshotsInProgress.State.PARTIAL;
249+
break;
250250
default:
251251
throw new IllegalArgumentException("Unknown snapshot state " + snapshotInfo.state());
252252
}

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,21 @@ public static boolean completed(ObjectContainer<ShardSnapshotStatus> shards) {
235235
return true;
236236
}
237237

238+
/**
239+
* Checks if all shards in the list have completed successfully
240+
*
241+
* @param shards list of shard statuses
242+
* @return true if any shard has failed, false otherwise
243+
*/
244+
public static boolean partiallyCompleted(ObjectContainer<ShardSnapshotStatus> shards) {
245+
for (ObjectCursor<ShardSnapshotStatus> status : shards) {
246+
if (status.value.state().failed() == true) {
247+
return true;
248+
}
249+
}
250+
return false;
251+
}
252+
238253

239254
public static class ShardSnapshotStatus {
240255
private final State state;
@@ -316,7 +331,8 @@ public enum State {
316331
FAILED((byte) 3, true, true),
317332
ABORTED((byte) 4, false, true),
318333
MISSING((byte) 5, true, true),
319-
WAITING((byte) 6, false, false);
334+
WAITING((byte) 6, false, false),
335+
PARTIAL((byte) 7, false, false);
320336

321337
private byte value;
322338

@@ -358,6 +374,8 @@ public static State fromValue(byte value) {
358374
return MISSING;
359375
case 6:
360376
return WAITING;
377+
case 7:
378+
return PARTIAL;
361379
default:
362380
throw new IllegalArgumentException("No snapshot state for value [" + value + "]");
363381
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
import static java.util.Collections.emptyMap;
8585
import static java.util.Collections.unmodifiableMap;
8686
import static org.elasticsearch.cluster.SnapshotsInProgress.completed;
87+
import static org.elasticsearch.cluster.SnapshotsInProgress.partiallyCompleted;
8788
import static org.elasticsearch.transport.EmptyTransportResponseHandler.INSTANCE_SAME;
8889

8990
/**
@@ -588,9 +589,14 @@ public ClusterTasksResult<UpdateIndexShardSnapshotStatusRequest> execute(Cluster
588589
if (completed(shards.values()) == false) {
589590
entries.add(new SnapshotsInProgress.Entry(entry, shards.build()));
590591
} else {
591-
// Snapshot is finished - mark it as done
592-
// TODO: Add PARTIAL_SUCCESS status?
593-
SnapshotsInProgress.Entry updatedEntry = new SnapshotsInProgress.Entry(entry, State.SUCCESS, shards.build());
592+
SnapshotsInProgress.Entry updatedEntry;
593+
if (partiallyCompleted(shards.values()) == true) {
594+
// Snapshot partially completed
595+
updatedEntry = new SnapshotsInProgress.Entry(entry, State.PARTIAL, shards.build());
596+
} else {
597+
// Snapshot is finished - mark it as done
598+
updatedEntry = new SnapshotsInProgress.Entry(entry, State.SUCCESS, shards.build());
599+
}
594600
entries.add(updatedEntry);
595601
// Finalize snapshot in the repository
596602
snapshotsService.endSnapshot(updatedEntry);

0 commit comments

Comments
 (0)