Skip to content

Commit fc302f7

Browse files
Remove Outdated BwC Logic in Snapshots (#58858)
7.8 is released so we can simplify a few things.
1 parent 001b3fb commit fc302f7

File tree

4 files changed

+8
-56
lines changed

4 files changed

+8
-56
lines changed

server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/delete/DeleteSnapshotRequest.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.elasticsearch.action.support.master.MasterNodeRequest;
2424
import org.elasticsearch.common.io.stream.StreamInput;
2525
import org.elasticsearch.common.io.stream.StreamOutput;
26-
import org.elasticsearch.snapshots.SnapshotsService;
2726

2827
import java.io.IOException;
2928

@@ -70,26 +69,14 @@ public DeleteSnapshotRequest(String repository) {
7069
public DeleteSnapshotRequest(StreamInput in) throws IOException {
7170
super(in);
7271
repository = in.readString();
73-
if (in.getVersion().onOrAfter(SnapshotsService.MULTI_DELETE_VERSION)) {
74-
snapshots = in.readStringArray();
75-
} else {
76-
snapshots = new String[] {in.readString()};
77-
}
72+
snapshots = in.readStringArray();
7873
}
7974

8075
@Override
8176
public void writeTo(StreamOutput out) throws IOException {
8277
super.writeTo(out);
8378
out.writeString(repository);
84-
if (out.getVersion().onOrAfter(SnapshotsService.MULTI_DELETE_VERSION)) {
85-
out.writeStringArray(snapshots);
86-
} else {
87-
if (snapshots.length != 1) {
88-
throw new IllegalArgumentException(
89-
"Can't write snapshot delete with more than one snapshot to version [" + out.getVersion() + "]");
90-
}
91-
out.writeString(snapshots[0]);
92-
}
79+
out.writeStringArray(snapshots);
9380
}
9481

9582
@Override

server/src/main/java/org/elasticsearch/cluster/SnapshotDeletionsInProgress.java

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
import org.elasticsearch.common.xcontent.XContentBuilder;
2929
import org.elasticsearch.repositories.RepositoryData;
3030
import org.elasticsearch.repositories.RepositoryOperation;
31-
import org.elasticsearch.snapshots.Snapshot;
3231
import org.elasticsearch.snapshots.SnapshotId;
33-
import org.elasticsearch.snapshots.SnapshotsService;
3432

3533
import java.io.IOException;
3634
import java.util.ArrayList;
@@ -199,14 +197,8 @@ public Entry(List<SnapshotId> snapshots, String repoName, long startTime, long r
199197
}
200198

201199
public Entry(StreamInput in) throws IOException {
202-
if (in.getVersion().onOrAfter(SnapshotsService.MULTI_DELETE_VERSION)) {
203-
this.repoName = in.readString();
204-
this.snapshots = in.readList(SnapshotId::new);
205-
} else {
206-
final Snapshot snapshot = new Snapshot(in);
207-
this.snapshots = Collections.singletonList(snapshot.getSnapshotId());
208-
this.repoName = snapshot.getRepository();
209-
}
200+
this.repoName = in.readString();
201+
this.snapshots = in.readList(SnapshotId::new);
210202
this.startTime = in.readVLong();
211203
this.repositoryStateId = in.readLong();
212204
}
@@ -244,14 +236,8 @@ public int hashCode() {
244236

245237
@Override
246238
public void writeTo(StreamOutput out) throws IOException {
247-
if (out.getVersion().onOrAfter(SnapshotsService.MULTI_DELETE_VERSION)) {
248-
out.writeString(repoName);
249-
out.writeCollection(snapshots);
250-
} else {
251-
assert snapshots.size() == 1 : "Only single deletion allowed in mixed version cluster containing [" + out.getVersion() +
252-
"] but saw " + snapshots;
253-
new Snapshot(repoName, snapshots.get(0)).writeTo(out);
254-
}
239+
out.writeString(repoName);
240+
out.writeCollection(snapshots);
255241
out.writeVLong(startTime);
256242
out.writeLong(repositoryStateId);
257243
}

server/src/main/java/org/elasticsearch/cluster/SnapshotsInProgress.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ public class SnapshotsInProgress extends AbstractNamedDiffable<Custom> implement
5959

6060
public static final SnapshotsInProgress EMPTY = new SnapshotsInProgress(List.of());
6161

62-
private static final Version VERSION_IN_SNAPSHOT_VERSION = Version.V_7_7_0;
63-
6462
public static final String TYPE = "snapshots";
6563

6664
@Override
@@ -545,15 +543,7 @@ public SnapshotsInProgress(StreamInput in) throws IOException {
545543
final String failure = in.readOptionalString();
546544
final Map<String, Object> userMetadata = in.readMap();
547545
final Version version;
548-
if (in.getVersion().onOrAfter(VERSION_IN_SNAPSHOT_VERSION)) {
549-
version = Version.readVersion(in);
550-
} else {
551-
// If an older master informs us that shard generations are supported we use the minimum shard generation compatible
552-
// version. If shard generations are not supported yet we use a placeholder for a version that does not use shard
553-
// generations.
554-
version = in.readBoolean() ? SnapshotsService.SHARD_GEN_IN_REPO_DATA_VERSION : SnapshotsService.OLD_SNAPSHOT_FORMAT;
555-
}
556-
546+
version = Version.readVersion(in);
557547
List<String> dataStreams;
558548
if (in.getVersion().onOrAfter(DATA_STREAMS_IN_SNAPSHOT)) {
559549
dataStreams = in.readStringList();
@@ -598,11 +588,7 @@ public void writeTo(StreamOutput out) throws IOException {
598588
out.writeLong(entry.repositoryStateId);
599589
out.writeOptionalString(entry.failure);
600590
out.writeMap(entry.userMetadata);
601-
if (out.getVersion().onOrAfter(VERSION_IN_SNAPSHOT_VERSION)) {
602-
Version.writeVersion(entry.version, out);
603-
} else {
604-
out.writeBoolean(SnapshotsService.useShardGenerations(entry.version));
605-
}
591+
Version.writeVersion(entry.version, out);
606592
if (out.getVersion().onOrAfter(DATA_STREAMS_IN_SNAPSHOT)) {
607593
out.writeStringCollection(entry.dataStreams);
608594
}

server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ public class SnapshotsService extends AbstractLifecycleComponent implements Clus
119119

120120
public static final Version OLD_SNAPSHOT_FORMAT = Version.V_7_5_0;
121121

122-
public static final Version MULTI_DELETE_VERSION = Version.V_7_8_0;
123-
124122
private static final Logger logger = LogManager.getLogger(SnapshotsService.class);
125123

126124
public static final String UPDATE_SNAPSHOT_STATUS_ACTION_NAME = "internal:cluster/snapshot/update_snapshot_status";
@@ -853,11 +851,6 @@ public void deleteSnapshots(final DeleteSnapshotRequest request, final ActionLis
853851

854852
@Override
855853
public ClusterState execute(ClusterState currentState) throws Exception {
856-
if (snapshotNames.length > 1 && currentState.nodes().getMinNodeVersion().before(MULTI_DELETE_VERSION)) {
857-
throw new IllegalArgumentException("Deleting multiple snapshots in a single request is only supported in version [ "
858-
+ MULTI_DELETE_VERSION + "] but cluster contained node of version [" + currentState.nodes().getMinNodeVersion()
859-
+ "]");
860-
}
861854
final SnapshotsInProgress snapshots = currentState.custom(SnapshotsInProgress.TYPE, SnapshotsInProgress.EMPTY);
862855
final SnapshotsInProgress.Entry snapshotEntry = findInProgressSnapshot(snapshots, snapshotNames, repositoryName);
863856
final List<SnapshotId> snapshotIds = matchingSnapshotIds(

0 commit comments

Comments
 (0)