Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RecoveryState clean up #9811

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
64 changes: 41 additions & 23 deletions docs/reference/indices/recovery.asciidoc
Expand Up @@ -8,29 +8,30 @@ For example, the following command would show recovery information for the indic

[source,js]
--------------------------------------------------
curl -XGET http://localhost:9200/index1,index2/_recovery?pretty=true
curl -XGET http://localhost:9200/index1,index2/_recovery
--------------------------------------------------

To see cluster-wide recovery status simply leave out the index names.

[source,js]
--------------------------------------------------
curl -XGET http://localhost:9200/_recovery?pretty=true
curl -XGET http://localhost:9200/_recovery?pretty&human
--------------------------------------------------

Response:

coming[1.5.0, this syntax was change to fix inconsistencies with other API]
[source,js]
--------------------------------------------------
{
"index1" : {
"shards" : [ {
"id" : 0,
"type" : "snapshot",
"stage" : "index",
"type" : "SNAPSHOT",
"stage" : "INDEX",
"primary" : true,
"start_time" : "2014-02-24T12:15:59.716",
"stop_time" : 0,
"start_time_in_millis": 1393244159716,
"total_time" : "2.9m"
"total_time_in_millis" : 175576,
"source" : {
"repository" : "my_repository",
Expand All @@ -44,26 +45,33 @@ Response:
"name" : "my_es_node"
},
"index" : {
"size" : {
"total" : "75.4mb"
"total_in_bytes" : 79063092,
"reused" : "0b",
"reused_in_bytes" : 0,
"recovered" : "65.7mb",
"recovered_in_bytes" : 68891939,
"percent" : "87.1%"
},
"files" : {
"total" : 73,
"reused" : 0,
"recovered" : 69,
"percent" : "94.5%"
},
"bytes" : {
"total" : 79063092,
"reused" : 0,
"recovered" : 68891939,
"percent" : "87.1%"
},
"total_time" : "0s",
"total_time_in_millis" : 0
},
"translog" : {
"recovered" : 0,
"total_time" : "0s",
"total_time_in_millis" : 0
},
"start" : {
"check_index_time" : 0,
"check_index_time" : "0s",
"check_index_time_in_millis" : 0,
"total_time" : "0s",
"total_time_in_millis" : 0
}
} ]
Expand All @@ -80,9 +88,10 @@ In some cases a higher level of detail may be preferable. Setting "detailed=true

[source,js]
--------------------------------------------------
curl -XGET http://localhost:9200/_recovery?pretty=true&detailed=true
curl -XGET http://localhost:9200/_recovery?pretty&human&detailed=true
--------------------------------------------------

coming[1.5.0, this syntax was change to fix inconsistencies with other API]
Response:

[source,js]
Expand All @@ -91,11 +100,14 @@ Response:
"index1" : {
"shards" : [ {
"id" : 0,
"type" : "gateway",
"stage" : "done",
"type" : "GATEWAY",
"stage" : "DONE",
"primary" : true,
"start_time" : "2014-02-24T12:38:06.349",
"start_time_in_millis" : "1393245486349",
"stop_time" : "2014-02-24T12:38:08.464",
"stop_time_in_millis" : "1393245488464",
"total_time" : "2.1s",
"total_time_in_millis" : 2115,
"source" : {
"id" : "RGMdRc-yQWWKIBM4DGvwqQ",
Expand All @@ -110,10 +122,19 @@ Response:
"name" : "my_es_node"
},
"index" : {
"size" : {
"total" : "24.7mb",
"total_in_bytes" : 26001617,
"reused" : "24.7mb",
"reused_in_bytes" : 26001617,
"recovered" : "0b",
"recovered_in_bytes" : 0,
"percent" : "100.0%"
},
"files" : {
"total" : 26,
"reused" : 26,
"recovered" : 26,
"recovered" : 0,
"percent" : "100.0%",
"details" : [ {
"name" : "segments.gen",
Expand All @@ -131,20 +152,17 @@ Response:
...
]
},
"bytes" : {
"total" : 26001617,
"reused" : 26001617,
"recovered" : 26001617,
"percent" : "100.0%"
},
"total_time" : "2ms",
"total_time_in_millis" : 2
},
"translog" : {
"recovered" : 71,
"total_time" : "2.0s",
"total_time_in_millis" : 2025
},
"start" : {
"check_index_time" : 0,
"total_time" : "88ms",
"total_time_in_millis" : 88
}
} ]
Expand Down
2 changes: 2 additions & 0 deletions rest-api-spec/test/cat.recovery/10_basic.yaml
Expand Up @@ -38,6 +38,8 @@
\d+\.\d+% \s+ # files_percent
\d+ \s+ # bytes
\d+\.\d+% \s+ # bytes_percent
\d+ \s+ # total_files
\d+ \s+ # total_bytes
\n
)+
$/
8 changes: 4 additions & 4 deletions rest-api-spec/test/indices.recovery/10_basic.yaml
Expand Up @@ -28,10 +28,10 @@
- gte: { test_1.shards.0.index.files.reused: 0 }
- gte: { test_1.shards.0.index.files.recovered: 0 }
- match: { test_1.shards.0.index.files.percent: /^\d+\.\d\%$/ }
- gte: { test_1.shards.0.index.bytes.total: 0 }
- gte: { test_1.shards.0.index.bytes.reused: 0 }
- gte: { test_1.shards.0.index.bytes.recovered: 0 }
- match: { test_1.shards.0.index.bytes.percent: /^\d+\.\d\%$/ }
- gte: { test_1.shards.0.index.size.total_in_bytes: 0 }
- gte: { test_1.shards.0.index.size.reused_in_bytes: 0 }
- gte: { test_1.shards.0.index.size.recovered_in_bytes: 0 }
- match: { test_1.shards.0.index.size.percent: /^\d+\.\d\%$/ }
- gte: { test_1.shards.0.translog.recovered: 0 }
- gte: { test_1.shards.0.translog.total_time_in_millis: 0 }
- gte: { test_1.shards.0.start.check_index_time_in_millis: 0 }
Expand Down
Expand Up @@ -28,9 +28,9 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

/**
* Information regarding the recovery state of indices and their associated shards.
Expand Down Expand Up @@ -64,17 +64,6 @@ public boolean hasRecoveries() {
return shardResponses.size() > 0;
}

public void addShardRecovery(String index, ShardRecoveryResponse shardRecoveryResponse) {

List<ShardRecoveryResponse> shardRecoveries = shardResponses.get(index);
if (shardRecoveries == null) {
shardRecoveries = new ArrayList<>();
shardResponses.put(index, shardRecoveries);
}

shardRecoveries.add(shardRecoveryResponse);
}

public boolean detailed() {
return detailed;
}
Expand All @@ -99,7 +88,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.startArray("shards");
for (ShardRecoveryResponse recoveryResponse : responses) {
builder.startObject();
recoveryResponse.detailed(this.detailed);
recoveryResponse.toXContent(builder, params);
builder.endObject();
}
Expand Down
Expand Up @@ -20,6 +20,7 @@
package org.elasticsearch.action.admin.indices.recovery;

import org.elasticsearch.action.support.broadcast.BroadcastShardOperationResponse;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContent;
Expand All @@ -35,7 +36,6 @@
public class ShardRecoveryResponse extends BroadcastShardOperationResponse implements ToXContent {

RecoveryState recoveryState;
private boolean detailed = false;

public ShardRecoveryResponse() { }

Expand All @@ -58,23 +58,15 @@ public void recoveryState(RecoveryState recoveryState) {
}

/**
* Gets the recovery state information for the shard.
* Gets the recovery state information for the shard. Null if shard wasn't recovered / recovery didn't start yet.
*
* @return Recovery state
*/
@Nullable
public RecoveryState recoveryState() {
return recoveryState;
}

public boolean detailed() {
return detailed;
}

public void detailed(boolean detailed) {
this.detailed = detailed;
this.recoveryState.setDetailed(detailed);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
recoveryState.toXContent(builder, params);
Expand Down
Expand Up @@ -34,13 +34,11 @@
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.gateway.IndexShardGatewayService;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.index.shard.IndexShard;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.indices.recovery.RecoveryState;
import org.elasticsearch.indices.recovery.RecoveryTarget;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;

Expand All @@ -58,15 +56,13 @@ public class TransportRecoveryAction extends
TransportBroadcastOperationAction<RecoveryRequest, RecoveryResponse, TransportRecoveryAction.ShardRecoveryRequest, ShardRecoveryResponse> {

private final IndicesService indicesService;
private final RecoveryTarget recoveryTarget;

@Inject
public TransportRecoveryAction(Settings settings, ThreadPool threadPool, ClusterService clusterService,
TransportService transportService, IndicesService indicesService, RecoveryTarget recoveryTarget, ActionFilters actionFilters) {
TransportService transportService, IndicesService indicesService, ActionFilters actionFilters) {

super(settings, RecoveryAction.NAME, threadPool, clusterService, transportService, actionFilters);
this.indicesService = indicesService;
this.recoveryTarget = recoveryTarget;
}

@Override
Expand Down Expand Up @@ -100,6 +96,12 @@ protected RecoveryResponse newResponse(RecoveryRequest request, AtomicReferenceA
} else {
ShardRecoveryResponse recoveryResponse = (ShardRecoveryResponse) shardResponse;
successfulShards++;

if (recoveryResponse.recoveryState() == null) {
// recovery not yet started
continue;
}

String indexName = recoveryResponse.getIndex();
List<ShardRecoveryResponse> responses = shardResponses.get(indexName);

Expand Down Expand Up @@ -146,17 +148,6 @@ protected ShardRecoveryResponse shardOperation(ShardRecoveryRequest request) thr
ShardRecoveryResponse shardRecoveryResponse = new ShardRecoveryResponse(request.shardId());

RecoveryState state = indexShard.recoveryState();

if (state == null) {
state = recoveryTarget.recoveryState(indexShard);
}

if (state == null) {
IndexShardGatewayService gatewayService =
indexService.shardInjectorSafe(request.shardId().id()).getInstance(IndexShardGatewayService.class);
state = gatewayService.recoveryState();
}

shardRecoveryResponse.recoveryState(state);
return shardRecoveryResponse;
}
Expand Down