Skip to content

Commit ea6a46a

Browse files
committed
Consistent updates of IndexShardSnapshotStatus (#28130)
This commit changes IndexShardSnapshotStatus so that the Stage is updated coherently with any required information. It also provides a asCopy() method that returns the status of a IndexShardSnapshotStatus at a given point in time, ensuring that all information are coherent. Closes #26480
1 parent a600dac commit ea6a46a

File tree

11 files changed

+287
-302
lines changed

11 files changed

+287
-302
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.elasticsearch.action.support.broadcast.BroadcastShardResponse;
2323
import org.elasticsearch.common.io.stream.StreamInput;
2424
import org.elasticsearch.common.io.stream.StreamOutput;
25-
import org.elasticsearch.common.xcontent.ToXContent.Params;
2625
import org.elasticsearch.common.xcontent.ToXContentFragment;
2726
import org.elasticsearch.common.xcontent.XContentBuilder;
2827
import org.elasticsearch.index.shard.ShardId;
@@ -49,13 +48,13 @@ private SnapshotIndexShardStatus() {
4948
this.stats = new SnapshotStats();
5049
}
5150

52-
SnapshotIndexShardStatus(ShardId shardId, IndexShardSnapshotStatus indexShardStatus) {
51+
SnapshotIndexShardStatus(ShardId shardId, IndexShardSnapshotStatus.Copy indexShardStatus) {
5352
this(shardId, indexShardStatus, null);
5453
}
5554

56-
SnapshotIndexShardStatus(ShardId shardId, IndexShardSnapshotStatus indexShardStatus, String nodeId) {
55+
SnapshotIndexShardStatus(ShardId shardId, IndexShardSnapshotStatus.Copy indexShardStatus, String nodeId) {
5756
super(shardId);
58-
switch (indexShardStatus.stage()) {
57+
switch (indexShardStatus.getStage()) {
5958
case INIT:
6059
stage = SnapshotIndexShardStage.INIT;
6160
break;
@@ -72,10 +71,12 @@ private SnapshotIndexShardStatus() {
7271
stage = SnapshotIndexShardStage.FAILURE;
7372
break;
7473
default:
75-
throw new IllegalArgumentException("Unknown stage type " + indexShardStatus.stage());
74+
throw new IllegalArgumentException("Unknown stage type " + indexShardStatus.getStage());
7675
}
77-
stats = new SnapshotStats(indexShardStatus);
78-
failure = indexShardStatus.failure();
76+
this.stats = new SnapshotStats(indexShardStatus.getStartTime(), indexShardStatus.getTotalTime(),
77+
indexShardStatus.getNumberOfFiles(), indexShardStatus.getProcessedFiles(),
78+
indexShardStatus.getTotalSize(), indexShardStatus.getProcessedSize());
79+
this.failure = indexShardStatus.getFailure();
7980
this.nodeId = nodeId;
8081
}
8182

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,28 @@
2525
import org.elasticsearch.common.xcontent.ToXContent;
2626
import org.elasticsearch.common.xcontent.ToXContentFragment;
2727
import org.elasticsearch.common.xcontent.XContentBuilder;
28-
import org.elasticsearch.index.snapshots.IndexShardSnapshotStatus;
2928

3029
import java.io.IOException;
3130

3231
public class SnapshotStats implements Streamable, ToXContentFragment {
33-
private long startTime;
3432

33+
private long startTime;
3534
private long time;
36-
3735
private int numberOfFiles;
38-
3936
private int processedFiles;
40-
4137
private long totalSize;
42-
4338
private long processedSize;
4439

4540
SnapshotStats() {
4641
}
4742

48-
SnapshotStats(IndexShardSnapshotStatus indexShardStatus) {
49-
startTime = indexShardStatus.startTime();
50-
time = indexShardStatus.time();
51-
numberOfFiles = indexShardStatus.numberOfFiles();
52-
processedFiles = indexShardStatus.processedFiles();
53-
totalSize = indexShardStatus.totalSize();
54-
processedSize = indexShardStatus.processedSize();
43+
SnapshotStats(long startTime, long time, int numberOfFiles, int processedFiles, long totalSize, long processedSize) {
44+
this.startTime = startTime;
45+
this.time = time;
46+
this.numberOfFiles = numberOfFiles;
47+
this.processedFiles = processedFiles;
48+
this.totalSize = totalSize;
49+
this.processedSize = processedSize;
5550
}
5651

5752
/**

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,25 @@ protected NodesSnapshotStatus newResponse(Request request, List<NodeSnapshotStat
9696
protected NodeSnapshotStatus nodeOperation(NodeRequest request) {
9797
Map<Snapshot, Map<ShardId, SnapshotIndexShardStatus>> snapshotMapBuilder = new HashMap<>();
9898
try {
99-
String nodeId = clusterService.localNode().getId();
99+
final String nodeId = clusterService.localNode().getId();
100100
for (Snapshot snapshot : request.snapshots) {
101101
Map<ShardId, IndexShardSnapshotStatus> shardsStatus = snapshotShardsService.currentSnapshotShards(snapshot);
102102
if (shardsStatus == null) {
103103
continue;
104104
}
105105
Map<ShardId, SnapshotIndexShardStatus> shardMapBuilder = new HashMap<>();
106106
for (Map.Entry<ShardId, IndexShardSnapshotStatus> shardEntry : shardsStatus.entrySet()) {
107-
SnapshotIndexShardStatus shardStatus;
108-
IndexShardSnapshotStatus.Stage stage = shardEntry.getValue().stage();
107+
final ShardId shardId = shardEntry.getKey();
108+
109+
final IndexShardSnapshotStatus.Copy lastSnapshotStatus = shardEntry.getValue().asCopy();
110+
final IndexShardSnapshotStatus.Stage stage = lastSnapshotStatus.getStage();
111+
112+
String shardNodeId = null;
109113
if (stage != IndexShardSnapshotStatus.Stage.DONE && stage != IndexShardSnapshotStatus.Stage.FAILURE) {
110114
// Store node id for the snapshots that are currently running.
111-
shardStatus = new SnapshotIndexShardStatus(shardEntry.getKey(), shardEntry.getValue(), nodeId);
112-
} else {
113-
shardStatus = new SnapshotIndexShardStatus(shardEntry.getKey(), shardEntry.getValue());
115+
shardNodeId = nodeId;
114116
}
115-
shardMapBuilder.put(shardEntry.getKey(), shardStatus);
117+
shardMapBuilder.put(shardEntry.getKey(), new SnapshotIndexShardStatus(shardId, lastSnapshotStatus, shardNodeId));
116118
}
117119
snapshotMapBuilder.put(snapshot, unmodifiableMap(shardMapBuilder));
118120
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ private SnapshotsStatusResponse buildResponse(SnapshotsStatusRequest request, Li
233233
Map<ShardId, IndexShardSnapshotStatus> shardStatues =
234234
snapshotsService.snapshotShards(request.repository(), snapshotInfo);
235235
for (Map.Entry<ShardId, IndexShardSnapshotStatus> shardStatus : shardStatues.entrySet()) {
236-
shardStatusBuilder.add(new SnapshotIndexShardStatus(shardStatus.getKey(), shardStatus.getValue()));
236+
IndexShardSnapshotStatus.Copy lastSnapshotStatus = shardStatus.getValue().asCopy();
237+
shardStatusBuilder.add(new SnapshotIndexShardStatus(shardStatus.getKey(), lastSnapshotStatus));
237238
}
238239
final SnapshotsInProgress.State state;
239240
switch (snapshotInfo.state()) {

0 commit comments

Comments
 (0)