Skip to content

Commit 17e42e3

Browse files
committed
Recovery: add total operations to the _recovery API
This commit adds the current total number of translog operations to the recovery reporting API. We also expose the recovered / total percentage: ``` "translog": { "recovered": 536, "total": 986, "percent": "54.3%", "total_time": "2ms", "total_time_in_millis": 2 }, ``` Closes elastic#9368 Closes elastic#10042
1 parent 2a79b94 commit 17e42e3

File tree

20 files changed

+206
-43
lines changed

20 files changed

+206
-43
lines changed

docs/reference/indices/recovery.asciidoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ coming[1.5.0, this syntax was change to fix inconsistencies with other API]
6565
},
6666
"translog" : {
6767
"recovered" : 0,
68+
"total" : 0,
69+
"percent" : "100.0%",
70+
"total_on_start" : 0,
6871
"total_time" : "0s",
6972
"total_time_in_millis" : 0
7073
},

rest-api-spec/test/cat.recovery/10_basic.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
\d+\.\d+% \s+ # bytes_percent
4141
\d+ \s+ # total_files
4242
\d+ \s+ # total_bytes
43+
\d+ \s+ # translog
44+
-?\d+\.\d+% \s+ # translog_percent
45+
-?\d+ \s+ # total_translog
4346
\n
4447
)+
4548
$/

rest-api-spec/test/indices.recovery/10_basic.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
- gte: { test_1.shards.0.index.size.recovered_in_bytes: 0 }
3434
- match: { test_1.shards.0.index.size.percent: /^\d+\.\d\%$/ }
3535
- gte: { test_1.shards.0.translog.recovered: 0 }
36+
- gte: { test_1.shards.0.translog.total: -1 }
37+
- gte: { test_1.shards.0.translog.total_on_start: 0 }
3638
- gte: { test_1.shards.0.translog.total_time_in_millis: 0 }
3739
- gte: { test_1.shards.0.start.check_index_time_in_millis: 0 }
3840
- gte: { test_1.shards.0.start.total_time_in_millis: 0 }

src/main/java/org/elasticsearch/action/admin/indices/status/TransportIndicesStatusAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ protected ShardStatus shardOperation(IndexShardStatusRequest request) throws Ela
202202
recoveryState.getTimer().time(),
203203
index.totalBytes(),
204204
index.reusedBytes(),
205-
index.recoveredBytes(), recoveryState.getTranslog().currentTranslogOperations());
205+
index.recoveredBytes(), recoveryState.getTranslog().recoveredOperations());
206206
} else if (recoveryState.getType() == RecoveryState.Type.GATEWAY) {
207207
GatewayRecoveryStatus.Stage stage;
208208
switch (recoveryState.getStage()) {
@@ -222,7 +222,7 @@ protected ShardStatus shardOperation(IndexShardStatusRequest request) throws Ela
222222
stage = GatewayRecoveryStatus.Stage.INIT;
223223
}
224224
shardStatus.gatewayRecoveryStatus = new GatewayRecoveryStatus(stage, recoveryState.getTimer().startTime(), recoveryState.getTimer().time(),
225-
index.totalBytes(), index.reusedBytes(), index.recoveredBytes(), recoveryState.getTranslog().currentTranslogOperations());
225+
index.totalBytes(), index.reusedBytes(), index.recoveredBytes(), recoveryState.getTranslog().recoveredOperations());
226226
}
227227
}
228228
}

src/main/java/org/elasticsearch/index/gateway/IndexShardGatewayService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public void run() {
130130
.append(new ByteSizeValue(index.reusedBytes())).append("]\n");
131131
sb.append(" start : took [").append(TimeValue.timeValueMillis(recoveryState.getStart().time())).append("], check_index [")
132132
.append(timeValueMillis(recoveryState.getStart().checkIndexTime())).append("]\n");
133-
sb.append(" translog : number_of_operations [").append(recoveryState.getTranslog().currentTranslogOperations())
133+
sb.append(" translog : number_of_operations [").append(recoveryState.getTranslog().recoveredOperations())
134134
.append("], took [").append(TimeValue.timeValueMillis(recoveryState.getTranslog().time())).append("]");
135135
logger.trace(sb.toString());
136136
} else if (logger.isDebugEnabled()) {

src/main/java/org/elasticsearch/index/gateway/local/LocalIndexShardGateway.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
import java.io.File;
5757
import java.io.IOException;
5858
import java.nio.file.Files;
59-
import java.nio.file.StandardCopyOption;
6059
import java.util.Arrays;
6160
import java.util.Set;
6261
import java.util.concurrent.CountDownLatch;
@@ -229,6 +228,8 @@ public void recover(boolean indexShouldExists, RecoveryState recoveryState) thro
229228
if (recoveringTranslogFile == null || !recoveringTranslogFile.exists()) {
230229
// no translog to recovery from, start and bail
231230
// no translog files, bail
231+
recoveryState.getTranslog().totalOperations(0);
232+
recoveryState.getTranslog().totalOperationsOnStart(0);
232233
indexShard.finalizeRecovery();
233234
indexShard.postRecovery("post recovery from gateway, no translog");
234235
// no index, just start the shard and bail
@@ -273,7 +274,7 @@ public void recover(boolean indexShouldExists, RecoveryState recoveryState) thro
273274
typesToUpdate.add(potentialIndexOperation.docMapper().type());
274275
}
275276
}
276-
recoveryState.getTranslog().addTranslogOperations(1);
277+
recoveryState.getTranslog().incrementRecoveredOperations();
277278
} catch (ElasticsearchException e) {
278279
if (e.status() == RestStatus.BAD_REQUEST) {
279280
// mainly for MapperParsingException and Failure to detect xcontent

src/main/java/org/elasticsearch/index/gateway/none/NoneIndexShardGateway.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public void recover(boolean indexShouldExists, RecoveryState recoveryState) thro
6565
} finally {
6666
indexShard.store().decRef();
6767
}
68+
recoveryState.getTranslog().totalOperations(0);
69+
recoveryState.getTranslog().totalOperationsOnStart(0);
6870
indexShard.prepareForTranslogRecovery();
6971
indexShard.finalizeRecovery();
7072
indexShard.postRecovery("post recovery from gateway");

src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotAndRestoreService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ public void restore(final RecoveryState recoveryState) {
115115
logger.trace("[{}] restoring shard [{}]", restoreSource.snapshotId(), shardId);
116116
}
117117
try {
118+
recoveryState.getTranslog().totalOperations(0);
119+
recoveryState.getTranslog().totalOperationsOnStart(0);
118120
indexShard.prepareForIndexRecovery();
119121
IndexShardRepository indexShardRepository = repositoriesService.indexShardRepository(restoreSource.snapshotId().getRepository());
120122
ShardId snapshotShardId = shardId;

src/main/java/org/elasticsearch/indices/recovery/RecoveryCleanFilesRequest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,16 @@ class RecoveryCleanFilesRequest extends TransportRequest {
4040
private ShardId shardId;
4141
private Set<String> legacySnapshotFiles; // legacy - we moved to a real snapshot in 1.5
4242
private Store.MetadataSnapshot snapshotFiles;
43+
private int totalTranslogOps = RecoveryState.Translog.UNKNOWN;
4344

4445
RecoveryCleanFilesRequest() {
4546
}
4647

47-
RecoveryCleanFilesRequest(long recoveryId, ShardId shardId, Store.MetadataSnapshot snapshotFiles) {
48+
RecoveryCleanFilesRequest(long recoveryId, ShardId shardId, Store.MetadataSnapshot snapshotFiles, int totalTranslogOps) {
4849
this.recoveryId = recoveryId;
4950
this.shardId = shardId;
5051
this.snapshotFiles = snapshotFiles;
52+
this.totalTranslogOps = totalTranslogOps;
5153
}
5254

5355
public long recoveryId() {
@@ -65,6 +67,7 @@ public void readFrom(StreamInput in) throws IOException {
6567
shardId = ShardId.readShardId(in);
6668
if (in.getVersion().onOrAfter(Version.V_1_5_0)) {
6769
snapshotFiles = Store.MetadataSnapshot.read(in);
70+
totalTranslogOps = in.readVInt();
6871
} else {
6972
int size = in.readVInt();
7073
legacySnapshotFiles = Sets.newHashSetWithExpectedSize(size);
@@ -82,6 +85,7 @@ public void writeTo(StreamOutput out) throws IOException {
8285
shardId.writeTo(out);
8386
if (out.getVersion().onOrAfter(Version.V_1_5_0)) {
8487
snapshotFiles.writeTo(out);
88+
out.writeVInt(totalTranslogOps);
8589
} else {
8690
out.writeVInt(snapshotFiles.size());
8791
for (StoreFileMetaData snapshotFile : snapshotFiles) {
@@ -98,4 +102,8 @@ public Store.MetadataSnapshot sourceMetaSnapshot() {
98102
public Set<String> legacySnapshotFiles() {
99103
return legacySnapshotFiles;
100104
}
105+
106+
public int totalTranslogOps() {
107+
return totalTranslogOps;
108+
}
101109
}

src/main/java/org/elasticsearch/indices/recovery/RecoveryFileChunkRequest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,20 @@ public final class RecoveryFileChunkRequest extends TransportRequest { // publi
4242
private BytesReference content;
4343
private StoreFileMetaData metaData;
4444

45+
private int totalTranslogOps;
46+
4547
RecoveryFileChunkRequest() {
4648
}
4749

48-
public RecoveryFileChunkRequest(long recoveryId, ShardId shardId, StoreFileMetaData metaData, long position, BytesReference content, boolean lastChunk) {
50+
public RecoveryFileChunkRequest(long recoveryId, ShardId shardId, StoreFileMetaData metaData, long position, BytesReference content,
51+
boolean lastChunk, int totalTranslogOps) {
4952
this.recoveryId = recoveryId;
5053
this.shardId = shardId;
5154
this.metaData = metaData;
5255
this.position = position;
5356
this.content = content;
5457
this.lastChunk = lastChunk;
58+
this.totalTranslogOps = totalTranslogOps;
5559
}
5660

5761
public long recoveryId() {
@@ -83,6 +87,10 @@ public BytesReference content() {
8387
return content;
8488
}
8589

90+
public int totalTranslogOps() {
91+
return totalTranslogOps;
92+
}
93+
8694
@Override
8795
public void readFrom(StreamInput in) throws IOException {
8896
super.readFrom(in);
@@ -104,6 +112,12 @@ public void readFrom(StreamInput in) throws IOException {
104112
} else {
105113
lastChunk = false;
106114
}
115+
116+
if (in.getVersion().onOrAfter(org.elasticsearch.Version.V_1_5_0)) {
117+
totalTranslogOps = in.readVInt();
118+
} else {
119+
totalTranslogOps = RecoveryState.Translog.UNKNOWN;
120+
}
107121
}
108122

109123
@Override
@@ -122,6 +136,10 @@ public void writeTo(StreamOutput out) throws IOException {
122136
if (out.getVersion().onOrAfter(org.elasticsearch.Version.V_1_4_0_Beta1)) {
123137
out.writeBoolean(lastChunk);
124138
}
139+
if (out.getVersion().onOrAfter(org.elasticsearch.Version.V_1_5_0)) {
140+
out.writeVInt(totalTranslogOps);
141+
}
142+
125143
}
126144

127145
@Override

0 commit comments

Comments
 (0)