Fix snapshot status with empty repository
The snapshot status command with empty repository should return current status of currently running snapshots in all repositories. Fixes #5790
This commit is contained in:
parent
2cf66c4115
commit
3d23a71fa7
|
@ -34,11 +34,11 @@ import static org.elasticsearch.action.ValidateActions.addValidationError;
|
|||
*/
|
||||
public class SnapshotsStatusRequest extends MasterNodeOperationRequest<SnapshotsStatusRequest> {
|
||||
|
||||
private String repository;
|
||||
private String repository = "_all";
|
||||
|
||||
private String[] snapshots = Strings.EMPTY_ARRAY;
|
||||
|
||||
SnapshotsStatusRequest() {
|
||||
public SnapshotsStatusRequest() {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -87,7 +87,8 @@ public class TransportSnapshotsStatusAction extends TransportMasterNodeOperation
|
|||
ImmutableList<SnapshotMetaData.Entry> currentSnapshots = snapshotsService.currentSnapshots(request.repository(), request.snapshots());
|
||||
|
||||
if (currentSnapshots.isEmpty()) {
|
||||
buildResponse(request, currentSnapshots, null);
|
||||
listener.onResponse(buildResponse(request, currentSnapshots, null));
|
||||
return;
|
||||
}
|
||||
|
||||
Set<String> nodesIds = newHashSet();
|
||||
|
|
|
@ -447,4 +447,9 @@ public interface ClusterAdminClient {
|
|||
*/
|
||||
SnapshotsStatusRequestBuilder prepareSnapshotStatus(String repository);
|
||||
|
||||
/**
|
||||
* Get snapshot status.
|
||||
*/
|
||||
SnapshotsStatusRequestBuilder prepareSnapshotStatus();
|
||||
|
||||
}
|
||||
|
|
|
@ -419,4 +419,9 @@ public abstract class AbstractClusterAdminClient implements InternalClusterAdmin
|
|||
public SnapshotsStatusRequestBuilder prepareSnapshotStatus(String repository) {
|
||||
return new SnapshotsStatusRequestBuilder(this, repository);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SnapshotsStatusRequestBuilder prepareSnapshotStatus() {
|
||||
return new SnapshotsStatusRequestBuilder(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public class RestSnapshotsStatusAction extends BaseRestHandler {
|
|||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
String repository = request.param("repository");
|
||||
String repository = request.param("repository", "_all");
|
||||
String[] snapshots = request.paramAsStringArray("snapshot", Strings.EMPTY_ARRAY);
|
||||
if (snapshots.length == 1 && "_all".equalsIgnoreCase(snapshots[0])) {
|
||||
snapshots = Strings.EMPTY_ARRAY;
|
||||
|
|
|
@ -382,7 +382,7 @@ public class SnapshotsService extends AbstractComponent implements ClusterStateL
|
|||
if (snapshotMetaData == null || snapshotMetaData.entries().isEmpty()) {
|
||||
return ImmutableList.of();
|
||||
}
|
||||
if (repository == null) {
|
||||
if ("_all".equals(repository)) {
|
||||
return snapshotMetaData.entries();
|
||||
}
|
||||
if (snapshotMetaData.entries().size() == 1) {
|
||||
|
|
|
@ -1036,12 +1036,8 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
|
|||
logger.info("--> waiting for block to kick in");
|
||||
waitForBlock(blockedNode, "test-repo", TimeValue.timeValueSeconds(60));
|
||||
|
||||
logger.info("--> execution was blocked on node [{}], checking snapshot status", blockedNode);
|
||||
logger.info("--> execution was blocked on node [{}], checking snapshot status with specified repository and snapshot", blockedNode);
|
||||
SnapshotsStatusResponse response = client.admin().cluster().prepareSnapshotStatus("test-repo").execute().actionGet();
|
||||
|
||||
logger.info("--> unblocking blocked node");
|
||||
unblockNode(blockedNode);
|
||||
|
||||
assertThat(response.getSnapshots().size(), equalTo(1));
|
||||
SnapshotStatus snapshotStatus = response.getSnapshots().get(0);
|
||||
assertThat(snapshotStatus.getState(), equalTo(SnapshotMetaData.State.STARTED));
|
||||
|
@ -1053,6 +1049,22 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
|
|||
}
|
||||
}
|
||||
|
||||
logger.info("--> checking snapshot status for all currently running and snapshot with empty repository", blockedNode);
|
||||
response = client.admin().cluster().prepareSnapshotStatus().execute().actionGet();
|
||||
assertThat(response.getSnapshots().size(), equalTo(1));
|
||||
snapshotStatus = response.getSnapshots().get(0);
|
||||
assertThat(snapshotStatus.getState(), equalTo(SnapshotMetaData.State.STARTED));
|
||||
// We blocked the node during data write operation, so at least one shard snapshot should be in STARTED stage
|
||||
assertThat(snapshotStatus.getShardsStats().getStartedShards(), greaterThan(0));
|
||||
for( SnapshotIndexShardStatus shardStatus : snapshotStatus.getIndices().get("test-idx")) {
|
||||
if (shardStatus.getStage() == SnapshotIndexShardStage.STARTED) {
|
||||
assertThat(shardStatus.getNodeId(), notNullValue());
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("--> unblocking blocked node");
|
||||
unblockNode(blockedNode);
|
||||
|
||||
SnapshotInfo snapshotInfo = waitForCompletion("test-repo", "test-snap", TimeValue.timeValueSeconds(600));
|
||||
logger.info("Number of failed shards [{}]", snapshotInfo.shardFailures().size());
|
||||
logger.info("--> done");
|
||||
|
@ -1069,6 +1081,10 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
|
|||
assertThat(indexStatus.getShardsStats().getDoneShards(), equalTo(snapshotInfo.successfulShards()));
|
||||
assertThat(indexStatus.getShards().size(), equalTo(snapshotInfo.totalShards()));
|
||||
|
||||
logger.info("--> checking snapshot status after it is done with empty repository", blockedNode);
|
||||
response = client.admin().cluster().prepareSnapshotStatus().execute().actionGet();
|
||||
assertThat(response.getSnapshots().size(), equalTo(0));
|
||||
|
||||
try {
|
||||
client.admin().cluster().prepareSnapshotStatus("test-repo").addSnapshots("test-snap-doesnt-exist").execute().actionGet();
|
||||
fail();
|
||||
|
|
Loading…
Reference in New Issue