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

Simplify and Cleanup some Snapshot Code #45480

Closed
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -29,13 +29,6 @@
public class DeleteRepositoryRequestBuilder
extends AcknowledgedRequestBuilder<DeleteRepositoryRequest, AcknowledgedResponse, DeleteRepositoryRequestBuilder> {

/**
* Constructs unregister repository request builder
*/
public DeleteRepositoryRequestBuilder(ElasticsearchClient client, DeleteRepositoryAction action) {
super(client, action, new DeleteRepositoryRequest());
}

/**
* Constructs unregister repository request builder with specified repository name
*/
Expand Down
Expand Up @@ -29,13 +29,6 @@
public class GetRepositoriesRequestBuilder
extends MasterNodeReadOperationRequestBuilder<GetRepositoriesRequest, GetRepositoriesResponse, GetRepositoriesRequestBuilder> {

/**
* Creates new get repository request builder
*/
public GetRepositoriesRequestBuilder(ElasticsearchClient client, GetRepositoriesAction action) {
super(client, action, new GetRepositoriesRequest());
}

/**
* Creates new get repository request builder
*/
Expand Down
Expand Up @@ -33,13 +33,6 @@
public class PutRepositoryRequestBuilder
extends AcknowledgedRequestBuilder<PutRepositoryRequest, AcknowledgedResponse, PutRepositoryRequestBuilder> {

/**
* Constructs register repository request
*/
public PutRepositoryRequestBuilder(ElasticsearchClient client, PutRepositoryAction action) {
super(client, action, new PutRepositoryRequest());
}

/**
* Constructs register repository request for the repository with a given name
*/
Expand Down
Expand Up @@ -28,13 +28,6 @@
public class VerifyRepositoryRequestBuilder
extends MasterNodeOperationRequestBuilder<VerifyRepositoryRequest, VerifyRepositoryResponse, VerifyRepositoryRequestBuilder> {

/**
* Constructs unregister repository request builder
*/
public VerifyRepositoryRequestBuilder(ElasticsearchClient client, VerifyRepositoryAction action) {
super(client, action, new VerifyRepositoryRequest());
}

/**
* Constructs unregister repository request builder with specified repository name
*/
Expand Down
Expand Up @@ -42,8 +42,8 @@
*/
public class VerifyRepositoryResponse extends ActionResponse implements ToXContentObject {

static final String NODES = "nodes";
static final String NAME = "name";
private static final String NODES = "nodes";
private static final String NAME = "name";

public static class NodeView implements Writeable, ToXContentObject {
private static final ObjectParser.NamedObjectParser<NodeView, Void> PARSER;
Expand Down Expand Up @@ -77,8 +77,6 @@ public void writeTo(StreamOutput out) throws IOException {

public String getName() { return name; }

public String getNodeId() { return nodeId; }

public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(nodeId);
{
Expand Down
Expand Up @@ -65,7 +65,7 @@
*/
public class CreateSnapshotRequest extends MasterNodeRequest<CreateSnapshotRequest>
implements IndicesRequest.Replaceable, ToXContentObject {
public static int MAXIMUM_METADATA_BYTES = 1024; // chosen arbitrarily
public static final int MAXIMUM_METADATA_BYTES = 1024; // chosen arbitrarily

private String snapshot;

Expand Down Expand Up @@ -169,8 +169,7 @@ public static int metadataSize(Map<String, Object> userMetadata) {
}
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
builder.value(userMetadata);
int size = BytesReference.bytes(builder).length();
return size;
return BytesReference.bytes(builder).length();
} catch (IOException e) {
// This should not be possible as we are just rendering the xcontent in memory
throw new ElasticsearchException(e);
Expand Down
Expand Up @@ -33,13 +33,6 @@
public class CreateSnapshotRequestBuilder extends MasterNodeOperationRequestBuilder<CreateSnapshotRequest,
CreateSnapshotResponse, CreateSnapshotRequestBuilder> {

/**
* Constructs a new create snapshot request builder
*/
public CreateSnapshotRequestBuilder(ElasticsearchClient client, CreateSnapshotAction action) {
super(client, action, new CreateSnapshotRequest());
}

/**
* Constructs a new create snapshot request builder with specified repository and snapshot names
*/
Expand Down
Expand Up @@ -66,11 +66,7 @@ protected CreateSnapshotResponse read(StreamInput in) throws IOException {
@Override
protected ClusterBlockException checkBlock(CreateSnapshotRequest request, ClusterState state) {
// We only check metadata block, as we want to snapshot closed indices (which have a read block)
ClusterBlockException clusterBlockException = state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ);
if (clusterBlockException != null) {
return clusterBlockException;
}
return null;
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ);
}

@Override
Expand Down
Expand Up @@ -29,13 +29,6 @@
public class DeleteSnapshotRequestBuilder extends MasterNodeOperationRequestBuilder<DeleteSnapshotRequest,
AcknowledgedResponse, DeleteSnapshotRequestBuilder> {

/**
* Constructs delete snapshot request builder
*/
public DeleteSnapshotRequestBuilder(ElasticsearchClient client, DeleteSnapshotAction action) {
super(client, action, new DeleteSnapshotRequest());
}

/**
* Constructs delete snapshot request builder with specified repository and snapshot names
*/
Expand Down
Expand Up @@ -34,13 +34,6 @@
public class RestoreSnapshotRequestBuilder extends MasterNodeOperationRequestBuilder<RestoreSnapshotRequest,
RestoreSnapshotResponse, RestoreSnapshotRequestBuilder> {

/**
* Constructs new restore snapshot request builder
*/
public RestoreSnapshotRequestBuilder(ElasticsearchClient client, RestoreSnapshotAction action) {
super(client, action, new RestoreSnapshotRequest());
}

/**
* Constructs new restore snapshot request builder with specified repository and snapshot names
*/
Expand Down
Expand Up @@ -88,7 +88,7 @@ public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params par
return builder;
}

public static final ConstructingObjectParser<RestoreSnapshotResponse, Void> PARSER = new ConstructingObjectParser<>(
private static final ConstructingObjectParser<RestoreSnapshotResponse, Void> PARSER = new ConstructingObjectParser<>(
"restore_snapshot", true, v -> {
RestoreInfo restoreInfo = (RestoreInfo) v[0];
Boolean accepted = (Boolean) v[1];
Expand Down
Expand Up @@ -25,31 +25,28 @@ public enum SnapshotIndexShardStage {
/**
* Snapshot hasn't started yet
*/
INIT((byte)0, false),
INIT((byte)0),
/**
* Index files are being copied
*/
STARTED((byte)1, false),
STARTED((byte)1),
/**
* Snapshot metadata is being written
*/
FINALIZE((byte)2, false),
FINALIZE((byte)2),
/**
* Snapshot completed successfully
*/
DONE((byte)3, true),
DONE((byte)3),
/**
* Snapshot failed
*/
FAILURE((byte)4, true);
FAILURE((byte)4);

private byte value;
private final byte value;

private boolean completed;

SnapshotIndexShardStage(byte value, boolean completed) {
SnapshotIndexShardStage(byte value) {
this.value = value;
this.completed = completed;
}

/**
Expand All @@ -61,15 +58,6 @@ public byte value() {
return value;
}

/**
* Returns true if snapshot completed (successfully or not)
*
* @return true if snapshot completed, false otherwise
*/
public boolean completed() {
return completed;
}

/**
* Generate snapshot state from code
*
Expand Down
Expand Up @@ -36,13 +36,14 @@
import org.elasticsearch.index.snapshots.IndexShardSnapshotStatus;

import java.io.IOException;
import java.util.Objects;

import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg;

public class SnapshotIndexShardStatus extends BroadcastShardResponse implements ToXContentFragment {

private SnapshotIndexShardStage stage = SnapshotIndexShardStage.INIT;
private final SnapshotIndexShardStage stage;

private SnapshotStats stats;

Expand Down Expand Up @@ -215,10 +216,8 @@ public boolean equals(Object o) {

SnapshotIndexShardStatus that = (SnapshotIndexShardStatus) o;

if (stage != that.stage) return false;
if (stats != null ? !stats.equals(that.stats) : that.stats != null) return false;
if (nodeId != null ? !nodeId.equals(that.nodeId) : that.nodeId != null) return false;
return failure != null ? failure.equals(that.failure) : that.failure == null;
return stage == that.stage && Objects.equals(stats, that.stats) && Objects.equals(nodeId, that.nodeId)
&& Objects.equals(failure, that.failure);
}

@Override
Expand Down
Expand Up @@ -33,6 +33,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import static java.util.Collections.emptyMap;
import static java.util.Collections.unmodifiableMap;
Expand Down Expand Up @@ -64,8 +65,8 @@ public class SnapshotIndexStatus implements Iterable<SnapshotIndexShardStatus>,
this.indexShards = unmodifiableMap(indexShards);
}

public SnapshotIndexStatus(String index, Map<Integer, SnapshotIndexShardStatus> indexShards, SnapshotShardsStats shardsStats,
SnapshotStats stats) {
private SnapshotIndexStatus(String index, Map<Integer, SnapshotIndexShardStatus> indexShards, SnapshotShardsStats shardsStats,
SnapshotStats stats) {
this.index = index;
this.indexShards = indexShards;
this.shardsStats = shardsStats;
Expand Down Expand Up @@ -93,13 +94,6 @@ public SnapshotShardsStats getShardsStats() {
return shardsStats;
}

/**
* Returns snapshot stats
*/
public SnapshotStats getStats() {
return stats;
}

@Override
public Iterator<SnapshotIndexShardStatus> iterator() {
return indexShards.values().iterator();
Expand Down Expand Up @@ -165,10 +159,8 @@ public boolean equals(Object o) {

SnapshotIndexStatus that = (SnapshotIndexStatus) o;

if (index != null ? !index.equals(that.index) : that.index != null) return false;
if (indexShards != null ? !indexShards.equals(that.indexShards) : that.indexShards != null) return false;
if (shardsStats != null ? !shardsStats.equals(that.shardsStats) : that.shardsStats != null) return false;
return stats != null ? stats.equals(that.stats) : that.stats == null;
return Objects.equals(index, that.index) && Objects.equals(indexShards, that.indexShards)
&& Objects.equals(shardsStats, that.shardsStats) && Objects.equals(stats, that.stats);
}

@Override
Expand Down
Expand Up @@ -92,13 +92,6 @@ public int getStartedShards() {
return startedShards;
}

/**
* Number of shards with the snapshot in the finalizing stage
*/
public int getFinalizingShards() {
return finalizingShards;
}

/**
* Number of shards with completed snapshot
*/
Expand Down Expand Up @@ -136,7 +129,7 @@ public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params par
{
builder.field(Fields.INITIALIZING, getInitializingShards());
builder.field(Fields.STARTED, getStartedShards());
builder.field(Fields.FINALIZING, getFinalizingShards());
builder.field(Fields.FINALIZING, finalizingShards);
builder.field(Fields.DONE, getDoneShards());
builder.field(Fields.FAILED, getFailedShards());
builder.field(Fields.TOTAL, getTotalShards());
Expand Down Expand Up @@ -167,7 +160,7 @@ public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params par
PARSER.declareInt(constructorArg(), new ParseField(Fields.TOTAL));
}

public static SnapshotShardsStats fromXContent(XContentParser parser) throws IOException {
public static SnapshotShardsStats fromXContent(XContentParser parser) {
return PARSER.apply(parser, null);
}

Expand Down
Expand Up @@ -295,13 +295,9 @@ public boolean equals(Object o) {

SnapshotStatus that = (SnapshotStatus) o;

if (snapshot != null ? !snapshot.equals(that.snapshot) : that.snapshot != null) return false;
if (state != that.state) return false;
if (indicesStatus != null ? !indicesStatus.equals(that.indicesStatus) : that.indicesStatus != null)
return false;
if (shardsStats != null ? !shardsStats.equals(that.shardsStats) : that.shardsStats != null) return false;
if (stats != null ? !stats.equals(that.stats) : that.stats != null) return false;
return includeGlobalState != null ? includeGlobalState.equals(that.includeGlobalState) : that.includeGlobalState == null;
return Objects.equals(snapshot, that.snapshot) && state == that.state && Objects.equals(indicesStatus, that.indicesStatus)
&& Objects.equals(shardsStats, that.shardsStats) && Objects.equals(stats, that.stats)
&& Objects.equals(includeGlobalState, that.includeGlobalState);
}

@Override
Expand Down
Expand Up @@ -32,6 +32,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;

Expand All @@ -40,7 +41,7 @@
*/
public class SnapshotsStatusResponse extends ActionResponse implements ToXContentObject {

private List<SnapshotStatus> snapshots = Collections.emptyList();
private final List<SnapshotStatus> snapshots;

public SnapshotsStatusResponse(StreamInput in) throws IOException {
super(in);
Expand Down Expand Up @@ -104,10 +105,7 @@ public static SnapshotsStatusResponse fromXContent(XContentParser parser) throws
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

SnapshotsStatusResponse response = (SnapshotsStatusResponse) o;

return snapshots != null ? snapshots.equals(response.snapshots) : response.snapshots == null;
return Objects.equals(snapshots, ((SnapshotsStatusResponse) o).snapshots);
}

@Override
Expand Down
5 changes: 3 additions & 2 deletions server/src/main/java/org/elasticsearch/node/Node.java
Expand Up @@ -491,8 +491,9 @@ protected Node(
RepositoriesService repositoryService = repositoriesModule.getRepositoryService();
SnapshotsService snapshotsService = new SnapshotsService(settings, clusterService,
clusterModule.getIndexNameExpressionResolver(), repositoryService, threadPool);
SnapshotShardsService snapshotShardsService = new SnapshotShardsService(settings, clusterService, snapshotsService, threadPool,
transportService, indicesService, actionModule.getActionFilters(), clusterModule.getIndexNameExpressionResolver());
SnapshotShardsService snapshotShardsService = new SnapshotShardsService(settings, clusterService, repositoryService,
threadPool, transportService, indicesService, actionModule.getActionFilters(),
clusterModule.getIndexNameExpressionResolver());
RestoreService restoreService = new RestoreService(clusterService, repositoryService, clusterModule.getAllocationService(),
metaDataCreateIndexService, metaDataIndexUpgradeService, clusterService.getClusterSettings());

Expand Down
Expand Up @@ -21,9 +21,9 @@

public class VerificationFailure {

private String nodeId;
private final String nodeId;

private Exception cause;
private final Exception cause;

VerificationFailure(String nodeId, Exception cause) {
this.nodeId = nodeId;
Expand Down