Skip to content

Commit c4090a1

Browse files
author
Ali Beyad
committed
Remove the Snapshot class in favor of using SnapshotInfo
o/e/snapshots/Snapshot and o/e/snapshots/SnapshotInfo contain the same fields and represent the same information. Snapshot was used to maintain snapshot information to the snapshot repository, while SnapshotInfo was used to represent the snapshot information as presented through the REST layer. This removes the Snapshot class and combines all uses into the SnapshotInfo class. Closes #18167
1 parent 3912761 commit c4090a1

File tree

11 files changed

+299
-513
lines changed

11 files changed

+299
-513
lines changed

buildSrc/src/main/resources/checkstyle_suppressions.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,6 @@
778778
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]suggest[/\\]phrase[/\\]WordScorer.java" checks="LineLength" />
779779
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]suggest[/\\]term[/\\]TermSuggestParser.java" checks="LineLength" />
780780
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]snapshots[/\\]RestoreService.java" checks="LineLength" />
781-
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]snapshots[/\\]SnapshotInfo.java" checks="LineLength" />
782781
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]snapshots[/\\]SnapshotShardFailure.java" checks="LineLength" />
783782
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]snapshots[/\\]SnapshotShardsService.java" checks="LineLength" />
784783
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]snapshots[/\\]SnapshotsService.java" checks="LineLength" />

core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotResponse.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ public SnapshotInfo getSnapshotInfo() {
5757
@Override
5858
public void readFrom(StreamInput in) throws IOException {
5959
super.readFrom(in);
60-
snapshotInfo = SnapshotInfo.readOptionalSnapshotInfo(in);
60+
snapshotInfo = in.readOptionalWriteable(SnapshotInfo::new);
6161
}
6262

6363
@Override
6464
public void writeTo(StreamOutput out) throws IOException {
6565
super.writeTo(out);
66-
out.writeOptionalStreamable(snapshotInfo);
66+
out.writeOptionalWriteable(snapshotInfo);
6767
}
6868

6969
/**
@@ -90,7 +90,7 @@ static final class Fields {
9090
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
9191
if (snapshotInfo != null) {
9292
builder.field(Fields.SNAPSHOT);
93-
snapshotInfo.toXContent(builder, params);
93+
snapshotInfo.toExternalXContent(builder, params);
9494
} else {
9595
builder.field(Fields.ACCEPTED, true);
9696
}

core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsResponse.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void readFrom(StreamInput in) throws IOException {
6060
int size = in.readVInt();
6161
List<SnapshotInfo> builder = new ArrayList<>();
6262
for (int i = 0; i < size; i++) {
63-
builder.add(SnapshotInfo.readSnapshotInfo(in));
63+
builder.add(new SnapshotInfo(in));
6464
}
6565
snapshots = Collections.unmodifiableList(builder);
6666
}
@@ -82,7 +82,7 @@ static final class Fields {
8282
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
8383
builder.startArray(Fields.SNAPSHOTS);
8484
for (SnapshotInfo snapshotInfo : snapshots) {
85-
snapshotInfo.toXContent(builder, params);
85+
snapshotInfo.toExternalXContent(builder, params);
8686
}
8787
builder.endArray();
8888
return builder;

core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/TransportGetSnapshotsAction.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.elasticsearch.common.inject.Inject;
3232
import org.elasticsearch.common.regex.Regex;
3333
import org.elasticsearch.common.settings.Settings;
34-
import org.elasticsearch.snapshots.Snapshot;
3534
import org.elasticsearch.snapshots.SnapshotInfo;
3635
import org.elasticsearch.snapshots.SnapshotsService;
3736
import org.elasticsearch.threadpool.ThreadPool;
@@ -77,26 +76,20 @@ protected void masterOperation(final GetSnapshotsRequest request, ClusterState s
7776
try {
7877
List<SnapshotInfo> snapshotInfoBuilder = new ArrayList<>();
7978
if (isAllSnapshots(request.snapshots())) {
80-
List<Snapshot> snapshots = snapshotsService.snapshots(request.repository(), request.ignoreUnavailable());
81-
for (Snapshot snapshot : snapshots) {
82-
snapshotInfoBuilder.add(new SnapshotInfo(snapshot));
83-
}
79+
snapshotInfoBuilder.addAll(snapshotsService.snapshots(request.repository(), request.ignoreUnavailable()));
8480
} else if (isCurrentSnapshots(request.snapshots())) {
85-
List<Snapshot> snapshots = snapshotsService.currentSnapshots(request.repository());
86-
for (Snapshot snapshot : snapshots) {
87-
snapshotInfoBuilder.add(new SnapshotInfo(snapshot));
88-
}
81+
snapshotInfoBuilder.addAll(snapshotsService.currentSnapshots(request.repository()));
8982
} else {
9083
Set<String> snapshotsToGet = new LinkedHashSet<>(); // to keep insertion order
91-
List<Snapshot> snapshots = null;
84+
List<SnapshotInfo> snapshots = null;
9285
for (String snapshotOrPattern : request.snapshots()) {
9386
if (Regex.isSimpleMatchPattern(snapshotOrPattern) == false) {
9487
snapshotsToGet.add(snapshotOrPattern);
9588
} else {
9689
if (snapshots == null) { // lazily load snapshots
9790
snapshots = snapshotsService.snapshots(request.repository(), request.ignoreUnavailable());
9891
}
99-
for (Snapshot snapshot : snapshots) {
92+
for (SnapshotInfo snapshot : snapshots) {
10093
if (Regex.simpleMatch(snapshotOrPattern, snapshot.name())) {
10194
snapshotsToGet.add(snapshot.name());
10295
}
@@ -105,7 +98,7 @@ protected void masterOperation(final GetSnapshotsRequest request, ClusterState s
10598
}
10699
for (String snapshot : snapshotsToGet) {
107100
SnapshotId snapshotId = new SnapshotId(request.repository(), snapshot);
108-
snapshotInfoBuilder.add(new SnapshotInfo(snapshotsService.snapshot(snapshotId)));
101+
snapshotInfoBuilder.add(snapshotsService.snapshot(snapshotId));
109102
}
110103
}
111104
listener.onResponse(new GetSnapshotsResponse(Collections.unmodifiableList(snapshotInfoBuilder)));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import org.elasticsearch.common.settings.Settings;
3737
import org.elasticsearch.index.shard.ShardId;
3838
import org.elasticsearch.index.snapshots.IndexShardSnapshotStatus;
39-
import org.elasticsearch.snapshots.Snapshot;
39+
import org.elasticsearch.snapshots.SnapshotInfo;
4040
import org.elasticsearch.snapshots.SnapshotsService;
4141
import org.elasticsearch.threadpool.ThreadPool;
4242
import org.elasticsearch.transport.TransportService;
@@ -202,7 +202,7 @@ private SnapshotsStatusResponse buildResponse(SnapshotsStatusRequest request, Li
202202
// This is a snapshot the is currently running - skipping
203203
continue;
204204
}
205-
Snapshot snapshot = snapshotsService.snapshot(snapshotId);
205+
SnapshotInfo snapshot = snapshotsService.snapshot(snapshotId);
206206
List<SnapshotIndexShardStatus> shardStatusBuilder = new ArrayList<>();
207207
if (snapshot.state().completed()) {
208208
Map<ShardId, IndexShardSnapshotStatus> shardStatues = snapshotsService.snapshotShards(snapshotId);

core/src/main/java/org/elasticsearch/repositories/Repository.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.elasticsearch.common.component.LifecycleComponent;
2525
import org.elasticsearch.index.shard.ShardId;
2626
import org.elasticsearch.index.snapshots.IndexShardSnapshotStatus;
27-
import org.elasticsearch.snapshots.Snapshot;
27+
import org.elasticsearch.snapshots.SnapshotInfo;
2828
import org.elasticsearch.snapshots.SnapshotShardFailure;
2929

3030
import java.io.IOException;
@@ -54,7 +54,7 @@ public interface Repository extends LifecycleComponent<Repository> {
5454
* @param snapshotId snapshot ID
5555
* @return information about snapshot
5656
*/
57-
Snapshot readSnapshot(SnapshotId snapshotId);
57+
SnapshotInfo readSnapshot(SnapshotId snapshotId);
5858

5959
/**
6060
* Returns global metadata associate with the snapshot.
@@ -65,7 +65,7 @@ public interface Repository extends LifecycleComponent<Repository> {
6565
* @param indices list of indices
6666
* @return information about snapshot
6767
*/
68-
MetaData readSnapshotMetaData(SnapshotId snapshotId, Snapshot snapshot, List<String> indices) throws IOException;
68+
MetaData readSnapshotMetaData(SnapshotId snapshotId, SnapshotInfo snapshot, List<String> indices) throws IOException;
6969

7070
/**
7171
* Returns the list of snapshots currently stored in the repository
@@ -94,7 +94,7 @@ public interface Repository extends LifecycleComponent<Repository> {
9494
* @param shardFailures list of shard failures
9595
* @return snapshot description
9696
*/
97-
Snapshot finalizeSnapshot(SnapshotId snapshotId, List<String> indices, long startTime, String failure, int totalShards, List<SnapshotShardFailure> shardFailures);
97+
SnapshotInfo finalizeSnapshot(SnapshotId snapshotId, List<String> indices, long startTime, String failure, int totalShards, List<SnapshotShardFailure> shardFailures);
9898

9999
/**
100100
* Deletes snapshot

core/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@
5757
import org.elasticsearch.repositories.RepositorySettings;
5858
import org.elasticsearch.repositories.RepositoryVerificationException;
5959
import org.elasticsearch.snapshots.InvalidSnapshotNameException;
60-
import org.elasticsearch.snapshots.Snapshot;
6160
import org.elasticsearch.snapshots.SnapshotCreationException;
6261
import org.elasticsearch.snapshots.SnapshotException;
62+
import org.elasticsearch.snapshots.SnapshotInfo;
6363
import org.elasticsearch.snapshots.SnapshotMissingException;
6464
import org.elasticsearch.snapshots.SnapshotShardFailure;
6565

@@ -165,9 +165,9 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent<Rep
165165

166166
private LegacyBlobStoreFormat<IndexMetaData> indexMetaDataLegacyFormat;
167167

168-
private ChecksumBlobStoreFormat<Snapshot> snapshotFormat;
168+
private ChecksumBlobStoreFormat<SnapshotInfo> snapshotFormat;
169169

170-
private LegacyBlobStoreFormat<Snapshot> snapshotLegacyFormat;
170+
private LegacyBlobStoreFormat<SnapshotInfo> snapshotLegacyFormat;
171171

172172
private final boolean readOnly;
173173

@@ -202,8 +202,8 @@ protected void doStart() {
202202
indexMetaDataFormat = new ChecksumBlobStoreFormat<>(INDEX_METADATA_CODEC, METADATA_NAME_FORMAT, IndexMetaData.PROTO, parseFieldMatcher, isCompress());
203203
indexMetaDataLegacyFormat = new LegacyBlobStoreFormat<>(LEGACY_SNAPSHOT_NAME_FORMAT, IndexMetaData.PROTO, parseFieldMatcher);
204204

205-
snapshotFormat = new ChecksumBlobStoreFormat<>(SNAPSHOT_CODEC, SNAPSHOT_NAME_FORMAT, Snapshot.PROTO, parseFieldMatcher, isCompress());
206-
snapshotLegacyFormat = new LegacyBlobStoreFormat<>(LEGACY_SNAPSHOT_NAME_FORMAT, Snapshot.PROTO, parseFieldMatcher);
205+
snapshotFormat = new ChecksumBlobStoreFormat<>(SNAPSHOT_CODEC, SNAPSHOT_NAME_FORMAT, SnapshotInfo.PROTO, parseFieldMatcher, isCompress());
206+
snapshotLegacyFormat = new LegacyBlobStoreFormat<>(LEGACY_SNAPSHOT_NAME_FORMAT, SnapshotInfo.PROTO, parseFieldMatcher);
207207
}
208208

209209
/**
@@ -294,7 +294,7 @@ public void deleteSnapshot(SnapshotId snapshotId) {
294294
throw new RepositoryException(this.repositoryName, "cannot delete snapshot from a readonly repository");
295295
}
296296
List<String> indices = Collections.emptyList();
297-
Snapshot snapshot = null;
297+
SnapshotInfo snapshot = null;
298298
try {
299299
snapshot = readSnapshot(snapshotId);
300300
indices = snapshot.indices();
@@ -368,9 +368,9 @@ public void deleteSnapshot(SnapshotId snapshotId) {
368368
* {@inheritDoc}
369369
*/
370370
@Override
371-
public Snapshot finalizeSnapshot(SnapshotId snapshotId, List<String> indices, long startTime, String failure, int totalShards, List<SnapshotShardFailure> shardFailures) {
371+
public SnapshotInfo finalizeSnapshot(SnapshotId snapshotId, List<String> indices, long startTime, String failure, int totalShards, List<SnapshotShardFailure> shardFailures) {
372372
try {
373-
Snapshot blobStoreSnapshot = new Snapshot(snapshotId.getSnapshot(), indices, startTime, failure, System.currentTimeMillis(), totalShards, shardFailures);
373+
SnapshotInfo blobStoreSnapshot = new SnapshotInfo(snapshotId.getSnapshot(), indices, startTime, failure, System.currentTimeMillis(), totalShards, shardFailures);
374374
snapshotFormat.write(blobStoreSnapshot, snapshotsBlobContainer, snapshotId.getSnapshot());
375375
List<SnapshotId> snapshotIds = snapshots();
376376
if (!snapshotIds.contains(snapshotId)) {
@@ -425,15 +425,15 @@ public List<SnapshotId> snapshots() {
425425
* {@inheritDoc}
426426
*/
427427
@Override
428-
public MetaData readSnapshotMetaData(SnapshotId snapshotId, Snapshot snapshot, List<String> indices) throws IOException {
428+
public MetaData readSnapshotMetaData(SnapshotId snapshotId, SnapshotInfo snapshot, List<String> indices) throws IOException {
429429
return readSnapshotMetaData(snapshotId, snapshot.version(), indices, false);
430430
}
431431

432432
/**
433433
* {@inheritDoc}
434434
*/
435435
@Override
436-
public Snapshot readSnapshot(SnapshotId snapshotId) {
436+
public SnapshotInfo readSnapshot(SnapshotId snapshotId) {
437437
try {
438438
return snapshotFormat.read(snapshotsBlobContainer, snapshotId.getSnapshot());
439439
} catch (FileNotFoundException | NoSuchFileException ex) {
@@ -520,7 +520,7 @@ private BlobStoreFormat<MetaData> globalMetaDataFormat(Version version) {
520520
/**
521521
* Returns appropriate snapshot format based on the provided version of the snapshot
522522
*/
523-
private BlobStoreFormat<Snapshot> snapshotFormat(Version version) {
523+
private BlobStoreFormat<SnapshotInfo> snapshotFormat(Version version) {
524524
if(legacyMetaData(version)) {
525525
return snapshotLegacyFormat;
526526
} else {

core/src/main/java/org/elasticsearch/snapshots/RestoreService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public void restoreSnapshot(final RestoreRequest request, final ActionListener<R
190190
// Read snapshot info and metadata from the repository
191191
Repository repository = repositoriesService.repository(request.repository());
192192
final SnapshotId snapshotId = new SnapshotId(request.repository(), request.name());
193-
final Snapshot snapshot = repository.readSnapshot(snapshotId);
193+
final SnapshotInfo snapshot = repository.readSnapshot(snapshotId);
194194
List<String> filteredIndices = SnapshotUtils.filterIndices(snapshot.indices(), request.indices(), request.indicesOptions());
195195
MetaData metaDataIn = repository.readSnapshotMetaData(snapshotId, snapshot, filteredIndices);
196196

@@ -708,7 +708,7 @@ private Map<String, String> renamedIndices(RestoreRequest request, List<String>
708708
* @param snapshotId snapshot id
709709
* @param snapshot snapshot metadata
710710
*/
711-
private void validateSnapshotRestorable(SnapshotId snapshotId, Snapshot snapshot) {
711+
private void validateSnapshotRestorable(SnapshotId snapshotId, SnapshotInfo snapshot) {
712712
if (!snapshot.state().restorable()) {
713713
throw new SnapshotRestoreException(snapshotId, "unsupported snapshot state [" + snapshot.state() + "]");
714714
}
@@ -765,7 +765,7 @@ public void failRestore(SnapshotId snapshotId, ShardId shardId) {
765765
UPDATE_RESTORE_ACTION_NAME, request, EmptyTransportResponseHandler.INSTANCE_SAME);
766766
}
767767

768-
private boolean failed(Snapshot snapshot, String index) {
768+
private boolean failed(SnapshotInfo snapshot, String index) {
769769
for (SnapshotShardFailure failure : snapshot.shardFailures()) {
770770
if (index.equals(failure.index())) {
771771
return true;

0 commit comments

Comments
 (0)