Skip to content

Commit 83eb627

Browse files
authored
[9.0] Remove the failures field from snapshot responses (#114496) (#121770)
Backports #114496 to 9.0 > Failure handling for snapshots was made stricter in #107191 (8.15), so this field is always empty since then. Clients don't need to check it anymore for failure handling, we can remove it from API responses in 9.0
1 parent 5bb6a3a commit 83eb627

File tree

8 files changed

+17
-94
lines changed

8 files changed

+17
-94
lines changed

qa/smoke-test-http/src/javaRestTest/java/org/elasticsearch/http/snapshots/RestGetSnapshotsIT.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
package org.elasticsearch.http.snapshots;
1111

1212
import org.apache.http.client.methods.HttpGet;
13-
import org.elasticsearch.ElasticsearchException;
1413
import org.elasticsearch.action.ActionFuture;
1514
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse;
1615
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest;
@@ -37,7 +36,6 @@
3736
import java.io.InputStream;
3837
import java.util.ArrayList;
3938
import java.util.Collection;
40-
import java.util.HashMap;
4139
import java.util.HashSet;
4240
import java.util.List;
4341
import java.util.Map;
@@ -516,10 +514,9 @@ private static GetSnapshotsResponse sortedWithLimit(
516514
true,
517515
(args) -> new GetSnapshotsResponse(
518516
(List<SnapshotInfo>) args[0],
519-
(Map<String, ElasticsearchException>) args[1],
520-
(String) args[2],
521-
args[3] == null ? UNKNOWN_COUNT : (int) args[3],
522-
args[4] == null ? UNKNOWN_COUNT : (int) args[4]
517+
(String) args[1],
518+
args[2] == null ? UNKNOWN_COUNT : (int) args[2],
519+
args[3] == null ? UNKNOWN_COUNT : (int) args[3]
523520
)
524521
);
525522

@@ -529,11 +526,6 @@ private static GetSnapshotsResponse sortedWithLimit(
529526
(p, c) -> SnapshotInfoUtils.snapshotInfoFromXContent(p),
530527
new ParseField("snapshots")
531528
);
532-
GET_SNAPSHOT_PARSER.declareObject(
533-
ConstructingObjectParser.optionalConstructorArg(),
534-
(p, c) -> p.map(HashMap::new, ElasticsearchException::fromXContent),
535-
new ParseField("failures")
536-
);
537529
GET_SNAPSHOT_PARSER.declareStringOrNull(ConstructingObjectParser.optionalConstructorArg(), new ParseField("next"));
538530
GET_SNAPSHOT_PARSER.declareIntOrNull(ConstructingObjectParser.optionalConstructorArg(), UNKNOWN_COUNT, new ParseField("total"));
539531
GET_SNAPSHOT_PARSER.declareIntOrNull(ConstructingObjectParser.optionalConstructorArg(), UNKNOWN_COUNT, new ParseField("remaining"));

server/src/internalClusterTest/java/org/elasticsearch/snapshots/SnapshotStatusApisIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,6 @@ public void testGetSnapshotsNoRepos() {
316316
.get();
317317

318318
assertTrue(getSnapshotsResponse.getSnapshots().isEmpty());
319-
assertTrue(getSnapshotsResponse.getFailures().isEmpty());
320319
}
321320

322321
public void testGetSnapshotsMultipleRepos() throws Exception {

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ static TransportVersion def(int id) {
173173
public static final TransportVersion INFERENCE_REQUEST_ADAPTIVE_RATE_LIMITING = def(8_839_0_00);
174174
public static final TransportVersion ML_INFERENCE_IBM_WATSONX_RERANK_ADDED = def(8_840_0_00);
175175
public static final TransportVersion ELASTICSEARCH_9_0 = def(9_000_0_00);
176-
public static final TransportVersion TRANSPORT_STATS_HANDLING_TIME_REQUIRED = def(9_002_0_00);
176+
public static final TransportVersion REMOVE_SNAPSHOT_FAILURES = def(9_002_0_00);
177+
public static final TransportVersion TRANSPORT_STATS_HANDLING_TIME_REQUIRED = def(9_003_0_00);
177178

178179
/*
179180
* STOP! READ THIS FIRST! No, really,

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

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,18 @@
99

1010
package org.elasticsearch.action.admin.cluster.snapshots.get;
1111

12-
import org.elasticsearch.ElasticsearchException;
12+
import org.elasticsearch.TransportVersions;
1313
import org.elasticsearch.action.ActionResponse;
1414
import org.elasticsearch.common.Strings;
1515
import org.elasticsearch.common.collect.Iterators;
1616
import org.elasticsearch.common.io.stream.StreamInput;
1717
import org.elasticsearch.common.io.stream.StreamOutput;
1818
import org.elasticsearch.common.xcontent.ChunkedToXContentObject;
1919
import org.elasticsearch.core.Nullable;
20-
import org.elasticsearch.core.UpdateForV9;
2120
import org.elasticsearch.snapshots.SnapshotInfo;
2221
import org.elasticsearch.xcontent.ToXContent;
2322

2423
import java.io.IOException;
25-
import java.util.Collections;
2624
import java.util.Iterator;
2725
import java.util.List;
2826
import java.util.Map;
@@ -35,33 +33,26 @@ public class GetSnapshotsResponse extends ActionResponse implements ChunkedToXCo
3533

3634
private final List<SnapshotInfo> snapshots;
3735

38-
@UpdateForV9(owner = UpdateForV9.Owner.DISTRIBUTED_COORDINATION) // always empty, can be dropped
39-
private final Map<String, ElasticsearchException> failures;
40-
4136
@Nullable
4237
private final String next;
4338

4439
private final int total;
4540

4641
private final int remaining;
4742

48-
public GetSnapshotsResponse(
49-
List<SnapshotInfo> snapshots,
50-
Map<String, ElasticsearchException> failures,
51-
@Nullable String next,
52-
final int total,
53-
final int remaining
54-
) {
43+
public GetSnapshotsResponse(List<SnapshotInfo> snapshots, @Nullable String next, final int total, final int remaining) {
5544
this.snapshots = List.copyOf(snapshots);
56-
this.failures = failures == null ? Map.of() : Map.copyOf(failures);
5745
this.next = next;
5846
this.total = total;
5947
this.remaining = remaining;
6048
}
6149

6250
public GetSnapshotsResponse(StreamInput in) throws IOException {
6351
this.snapshots = in.readCollectionAsImmutableList(SnapshotInfo::readFrom);
64-
this.failures = Collections.unmodifiableMap(in.readMap(StreamInput::readException));
52+
if (in.getTransportVersion().before(TransportVersions.REMOVE_SNAPSHOT_FAILURES)) {
53+
// Deprecated `failures` field
54+
in.readMap(StreamInput::readException);
55+
}
6556
this.next = in.readOptionalString();
6657
this.total = in.readVInt();
6758
this.remaining = in.readVInt();
@@ -76,25 +67,11 @@ public List<SnapshotInfo> getSnapshots() {
7667
return snapshots;
7768
}
7869

79-
/**
80-
* Returns a map of repository name to {@link ElasticsearchException} for each unsuccessful response.
81-
*/
82-
public Map<String, ElasticsearchException> getFailures() {
83-
return failures;
84-
}
85-
8670
@Nullable
8771
public String next() {
8872
return next;
8973
}
9074

91-
/**
92-
* Returns true if there is at least one failed response.
93-
*/
94-
public boolean isFailed() {
95-
return failures.isEmpty() == false;
96-
}
97-
9875
public int totalCount() {
9976
return total;
10077
}
@@ -106,7 +83,10 @@ public int remaining() {
10683
@Override
10784
public void writeTo(StreamOutput out) throws IOException {
10885
out.writeCollection(snapshots);
109-
out.writeMap(failures, StreamOutput::writeException);
86+
if (out.getTransportVersion().before(TransportVersions.REMOVE_SNAPSHOT_FAILURES)) {
87+
// Deprecated `failures` field
88+
out.writeMap(Map.of(), StreamOutput::writeException);
89+
}
11090
out.writeOptionalString(next);
11191
out.writeVInt(total);
11292
out.writeVInt(remaining);
@@ -120,18 +100,6 @@ public Iterator<ToXContent> toXContentChunked(ToXContent.Params params) {
120100
return b;
121101
}), Iterators.map(getSnapshots().iterator(), snapshotInfo -> snapshotInfo::toXContentExternal), Iterators.single((b, p) -> {
122102
b.endArray();
123-
if (failures.isEmpty() == false) {
124-
b.startObject("failures");
125-
for (Map.Entry<String, ElasticsearchException> error : failures.entrySet()) {
126-
b.field(error.getKey(), (bb, pa) -> {
127-
bb.startObject();
128-
error.getValue().toXContent(bb, pa);
129-
bb.endObject();
130-
return bb;
131-
});
132-
}
133-
b.endObject();
134-
}
135103
if (next != null) {
136104
b.field("next", next);
137105
}
@@ -151,12 +119,12 @@ public boolean equals(Object o) {
151119
if (this == o) return true;
152120
if (o == null || getClass() != o.getClass()) return false;
153121
GetSnapshotsResponse that = (GetSnapshotsResponse) o;
154-
return Objects.equals(snapshots, that.snapshots) && Objects.equals(failures, that.failures) && Objects.equals(next, that.next);
122+
return Objects.equals(snapshots, that.snapshots) && Objects.equals(next, that.next);
155123
}
156124

157125
@Override
158126
public int hashCode() {
159-
return Objects.hash(snapshots, failures, next);
127+
return Objects.hash(snapshots, next);
160128
}
161129

162130
@Override

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,6 @@ private GetSnapshotsResponse buildResponse() {
543543
}
544544
return new GetSnapshotsResponse(
545545
snapshotInfos,
546-
null,
547546
remaining > 0 ? sortBy.encodeAfterQueryParam(snapshotInfos.get(snapshotInfos.size() - 1)) : null,
548547
totalCount.get(),
549548
remaining

server/src/main/java/org/elasticsearch/rest/action/cat/RestSnapshotAction.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99

1010
package org.elasticsearch.rest.action.cat;
1111

12-
import org.elasticsearch.ElasticsearchException;
1312
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest;
1413
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse;
1514
import org.elasticsearch.client.internal.node.NodeClient;
16-
import org.elasticsearch.common.Strings;
1715
import org.elasticsearch.common.Table;
1816
import org.elasticsearch.common.time.DateFormatter;
1917
import org.elasticsearch.core.TimeValue;
@@ -99,24 +97,6 @@ protected Table getTableWithHeader(RestRequest request) {
9997
private Table buildTable(RestRequest req, GetSnapshotsResponse getSnapshotsResponse) {
10098
Table table = getTableWithHeader(req);
10199

102-
if (getSnapshotsResponse.isFailed()) {
103-
ElasticsearchException causes = null;
104-
105-
for (ElasticsearchException e : getSnapshotsResponse.getFailures().values()) {
106-
if (causes == null) {
107-
causes = e;
108-
} else {
109-
causes.addSuppressed(e);
110-
}
111-
}
112-
throw new ElasticsearchException(
113-
"Repositories ["
114-
+ Strings.collectionToCommaDelimitedString(getSnapshotsResponse.getFailures().keySet())
115-
+ "] failed to retrieve snapshots",
116-
causes
117-
);
118-
}
119-
120100
for (SnapshotInfo snapshotStatus : getSnapshotsResponse.getSnapshots()) {
121101
table.startRow();
122102

server/src/test/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsResponseTests.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
package org.elasticsearch.action.admin.cluster.snapshots.get;
1111

12-
import org.elasticsearch.ElasticsearchException;
1312
import org.elasticsearch.TransportVersion;
1413
import org.elasticsearch.common.UUIDs;
1514
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
@@ -31,14 +30,10 @@
3130
import java.util.Arrays;
3231
import java.util.Base64;
3332
import java.util.Collections;
34-
import java.util.HashMap;
3533
import java.util.HashSet;
3634
import java.util.List;
37-
import java.util.Map;
3835
import java.util.Set;
3936

40-
import static org.hamcrest.CoreMatchers.containsString;
41-
4237
public class GetSnapshotsResponseTests extends ESTestCase {
4338
// We can not subclass AbstractSerializingTestCase because it
4439
// can only be used for instances with equals and hashCode
@@ -60,12 +55,6 @@ private GetSnapshotsResponse copyInstance(GetSnapshotsResponse instance) throws
6055
private void assertEqualInstances(GetSnapshotsResponse expectedInstance, GetSnapshotsResponse newInstance) {
6156
assertEquals(expectedInstance.getSnapshots(), newInstance.getSnapshots());
6257
assertEquals(expectedInstance.next(), newInstance.next());
63-
assertEquals(expectedInstance.getFailures().keySet(), newInstance.getFailures().keySet());
64-
for (Map.Entry<String, ElasticsearchException> expectedEntry : expectedInstance.getFailures().entrySet()) {
65-
ElasticsearchException expectedException = expectedEntry.getValue();
66-
ElasticsearchException newException = newInstance.getFailures().get(expectedEntry.getKey());
67-
assertThat(newException.getMessage(), containsString(expectedException.getMessage()));
68-
}
6958
}
7059

7160
private List<SnapshotInfo> createSnapshotInfos(String repoName) {
@@ -99,7 +88,6 @@ private List<SnapshotInfo> createSnapshotInfos(String repoName) {
9988

10089
private GetSnapshotsResponse createTestInstance() {
10190
Set<String> repositories = new HashSet<>();
102-
Map<String, ElasticsearchException> failures = new HashMap<>();
10391
List<SnapshotInfo> responses = new ArrayList<>();
10492

10593
for (int i = 0; i < randomIntBetween(0, 5); i++) {
@@ -111,12 +99,10 @@ private GetSnapshotsResponse createTestInstance() {
11199
for (int i = 0; i < randomIntBetween(0, 5); i++) {
112100
String repository = randomValueOtherThanMany(repositories::contains, () -> randomAlphaOfLength(10));
113101
repositories.add(repository);
114-
failures.put(repository, new ElasticsearchException(randomAlphaOfLength(10)));
115102
}
116103

117104
return new GetSnapshotsResponse(
118105
responses,
119-
failures,
120106
randomBoolean()
121107
? Base64.getUrlEncoder()
122108
.encodeToString(

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotStepTests.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ public void testSlmPolicyExecutedAfterStep() {
164164
SnapshotState.SUCCESS
165165
)
166166
),
167-
Map.of(),
168167
null,
169168
0,
170169
0
@@ -202,7 +201,6 @@ public void testIndexNotBackedUpYet() {
202201
SnapshotState.SUCCESS
203202
)
204203
),
205-
Map.of(),
206204
null,
207205
0,
208206
0

0 commit comments

Comments
 (0)