Skip to content

Commit 6d438ef

Browse files
committed
Jack reset this commit
1 parent e23275f commit 6d438ef

File tree

11 files changed

+325
-0
lines changed

11 files changed

+325
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.upgrades;
11+
12+
import com.carrotsearch.randomizedtesting.annotations.Name;
13+
import org.apache.logging.log4j.Logger;
14+
15+
public class TVBackportRollingUpgradeIT extends AbstractRollingUpgradeTestCase {
16+
17+
public TVBackportRollingUpgradeIT(@Name("upgradedNodes") int upgradedNodes) {
18+
super(upgradedNodes);
19+
}
20+
// We'd be most interested to see this failing on the patch issue where 9.0 thinks it's ahead of 8.x but it's not.
21+
/*
22+
v2 TV1,TV3,
23+
v3 TV1,TV2,TV3,TV4
24+
25+
*/
26+
public void testTVBackport() {
27+
if (isOldCluster()) {
28+
// TODO: Implement the test for old cluster
29+
} else if (isMixedCluster()) {
30+
// TODO: Test mixed cluster behavior
31+
} else if (isUpgradedCluster()) {
32+
// TODO: Test upgraded cluster behavior
33+
} else {
34+
fail("Unknown cluster state");
35+
}
36+
}
37+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@
2929
*/
3030
public class TransportVersions {
3131

32+
33+
static final TreeSet<Integer> ALL_VERSIONS = new TreeSet<>();
34+
35+
public static void register(TransportVersionsGroup transportVersionsGroup) {
36+
ALL_VERSIONS.addAll(transportVersionsGroup.getLocalAndBackportedTVIds());
37+
}
38+
3239
/*
3340
* NOTE: IntelliJ lies!
3441
* This map is used during class construction, referenced by the registerTransportVersion method.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch;
11+
12+
import java.util.ArrayList;
13+
import java.util.Collections;
14+
import java.util.List;
15+
import java.util.stream.Collectors;
16+
17+
public abstract class TransportVersionsGroup {
18+
public final TransportVersion localTV;
19+
public final List<TransportVersion> backportTVs;
20+
public final List<TransportVersion> futureTVs;
21+
22+
public TransportVersionsGroup(List<TransportVersion> transportVersions) {
23+
if (transportVersions.stream().sorted().toList().equals(transportVersions) == false) {
24+
throw new IllegalArgumentException("transportVersions must be sorted by version");
25+
}
26+
27+
TransportVersion currentVersion = TransportVersion.current(); // TODO this has to be set somehow
28+
29+
TransportVersion localTV = null;
30+
List<TransportVersion> backportTVs = new ArrayList<>();
31+
List<TransportVersion> futureTVs = new ArrayList<>();
32+
33+
for (TransportVersion transportVersion : transportVersions) {
34+
if (transportVersion.onOrAfter(currentVersion) == false) {
35+
futureTVs.add(transportVersion);
36+
} else if (localTV == null) {
37+
localTV = transportVersion;
38+
} else {
39+
backportTVs.add(transportVersion);
40+
}
41+
}
42+
if (localTV == null) {
43+
throw new IllegalArgumentException("TransportVersionsGroup must contain a local TransportVersion");
44+
}
45+
this.backportTVs = Collections.unmodifiableList(backportTVs);
46+
this.futureTVs = Collections.unmodifiableList(futureTVs);
47+
this.localTV = localTV;
48+
}
49+
50+
public boolean isCompatible(TransportVersion version) {
51+
return version.onOrAfter(localTV)
52+
|| backportTVs.stream().anyMatch(version::isPatchFrom);
53+
}
54+
55+
public List<Integer> getLocalAndBackportedTVIds() {
56+
var localAndBackportedTVs = new ArrayList<TransportVersion>();
57+
localAndBackportedTVs.add(localTV);
58+
localAndBackportedTVs.addAll(backportTVs);
59+
return localAndBackportedTVs.stream().map(TransportVersion::id).toList();
60+
}
61+
}

server/src/main/java/org/elasticsearch/action/ActionModule.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@
210210
import org.elasticsearch.action.termvectors.TransportMultiTermVectorsAction;
211211
import org.elasticsearch.action.termvectors.TransportShardMultiTermsVectorAction;
212212
import org.elasticsearch.action.termvectors.TransportTermVectorsAction;
213+
import org.elasticsearch.action.tvbackport.RestTVBackportAction;
214+
import org.elasticsearch.action.tvbackport.TVBackportAction;
215+
import org.elasticsearch.action.tvbackport.TransportTVBackportAction;
213216
import org.elasticsearch.action.update.TransportUpdateAction;
214217
import org.elasticsearch.client.internal.node.NodeClient;
215218
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
@@ -809,6 +812,9 @@ public <Request extends ActionRequest, Response extends ActionResponse> void reg
809812
actions.register(GetSynonymRuleAction.INSTANCE, TransportGetSynonymRuleAction.class);
810813
actions.register(DeleteSynonymRuleAction.INSTANCE, TransportDeleteSynonymRuleAction.class);
811814

815+
// Transport Version Backport Testing
816+
actions.register(TVBackportAction.INSTANCE, TransportTVBackportAction.class);
817+
812818
return unmodifiableMap(actions.getRegistry());
813819
}
814820

@@ -1036,6 +1042,9 @@ public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster, Predicate<
10361042
registerHandler.accept(new RestPutSynonymRuleAction());
10371043
registerHandler.accept(new RestGetSynonymRuleAction());
10381044
registerHandler.accept(new RestDeleteSynonymRuleAction());
1045+
1046+
// Transport Version Backport Testing
1047+
registerHandler.accept(new RestTVBackportAction());
10391048
}
10401049

10411050
@Override
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.action.tvbackport;
11+
12+
import org.elasticsearch.client.internal.node.NodeClient;
13+
import org.elasticsearch.rest.BaseRestHandler;
14+
import org.elasticsearch.rest.RestRequest;
15+
import org.elasticsearch.rest.action.RestToXContentListener;
16+
17+
import java.io.IOException;
18+
import java.util.List;
19+
20+
public class RestTVBackportAction extends BaseRestHandler {
21+
@Override
22+
public String getName() {
23+
return "_tv_backport_action";
24+
}
25+
26+
@Override
27+
public List<Route> routes() {
28+
return List.of(new Route(RestRequest.Method.GET, "/_tv_backport"));
29+
}
30+
31+
@Override
32+
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
33+
TVBackportRequest tvBackportRequest = new TVBackportRequest();
34+
// Here you can set any parameters from the request to the tvBackportRequest if needed
35+
return channel -> client.execute(TVBackportAction.INSTANCE, tvBackportRequest, new RestToXContentListener<>(channel));
36+
}
37+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.action.tvbackport;
11+
12+
import org.elasticsearch.action.ActionType;
13+
14+
public class TVBackportAction extends ActionType<TVBackportResponse> {
15+
public static final TVBackportAction INSTANCE = new TVBackportAction();
16+
public static final String NAME = "cluster:monitor/tvbackport";
17+
18+
private TVBackportAction() {
19+
super(NAME);
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.action.tvbackport;
11+
12+
import org.elasticsearch.action.ActionRequest;
13+
import org.elasticsearch.action.ActionRequestValidationException;
14+
15+
public class TVBackportRequest extends ActionRequest {
16+
17+
@Override
18+
public ActionRequestValidationException validate() {
19+
return null;
20+
}
21+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.action.tvbackport;
11+
12+
import org.elasticsearch.action.ActionResponse;
13+
import org.elasticsearch.common.io.stream.StreamInput;
14+
import org.elasticsearch.common.io.stream.StreamOutput;
15+
import org.elasticsearch.versions.TestTV;
16+
import org.elasticsearch.xcontent.ToXContentObject;
17+
import org.elasticsearch.xcontent.XContentBuilder;
18+
19+
import java.io.IOException;
20+
21+
public class TVBackportResponse extends ActionResponse implements ToXContentObject {
22+
String message;
23+
String testTV;
24+
25+
public TVBackportResponse(String message, String testTV) {
26+
this.message = message;
27+
this.testTV = testTV;
28+
}
29+
30+
public TVBackportResponse(StreamInput in) throws IOException {
31+
if (TestTV.INSTANCE.isCompatible(in.getTransportVersion())) {
32+
this.testTV = in.readOptionalString();
33+
} else {
34+
this.testTV = null; // Not compatible, so we don't read it
35+
}
36+
this.message = in.readString();
37+
}
38+
39+
@Override
40+
public void writeTo(StreamOutput out) throws IOException {
41+
if (TestTV.INSTANCE.isCompatible(out.getTransportVersion())) {
42+
out.writeOptionalString(testTV);
43+
}
44+
out.writeString(message);
45+
}
46+
47+
@Override
48+
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
49+
builder.startObject();
50+
if (testTV != null) {
51+
builder.field("TestTV", testTV);
52+
}
53+
builder.field("message", message);
54+
builder.endObject();
55+
return builder;
56+
}
57+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.action.tvbackport;
11+
12+
import org.apache.logging.log4j.LogManager;
13+
import org.apache.logging.log4j.Logger;
14+
import org.elasticsearch.action.ActionListener;
15+
import org.elasticsearch.action.support.ActionFilters;
16+
import org.elasticsearch.action.support.TransportAction;
17+
import org.elasticsearch.common.util.concurrent.EsExecutors;
18+
import org.elasticsearch.injection.guice.Inject;
19+
import org.elasticsearch.tasks.Task;
20+
import org.elasticsearch.transport.TransportService;
21+
22+
public class TransportTVBackportAction extends TransportAction<TVBackportRequest, TVBackportResponse> {
23+
private static final Logger logger = LogManager.getLogger(TransportTVBackportAction.class);
24+
25+
@Inject
26+
public TransportTVBackportAction(
27+
ActionFilters actionFilters,
28+
TransportService transportService
29+
) {
30+
super(TVBackportAction.NAME, actionFilters, transportService.getTaskManager(), EsExecutors.DIRECT_EXECUTOR_SERVICE);
31+
}
32+
33+
@Override
34+
protected void doExecute(Task task, TVBackportRequest request, ActionListener<TVBackportResponse> listener) {
35+
logger.info("Executing TVBackportAction for request");
36+
listener.onResponse(new TVBackportResponse("This is a TV Backport response", "with the testTV TVGroup"));
37+
}
38+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.versions;
11+
12+
import org.elasticsearch.TransportVersionsGroup;
13+
import org.elasticsearch.TransportVersion;
14+
import org.elasticsearch.TransportVersions;
15+
16+
import java.util.List;
17+
18+
public class TestTV extends TransportVersionsGroup {
19+
public static final TestTV INSTANCE = new TestTV();
20+
21+
static {
22+
TransportVersions.register(INSTANCE);
23+
}
24+
25+
private TestTV() {
26+
super(List.of(
27+
new TransportVersion(9_111_0_00),
28+
new TransportVersion(8_111_0_00)
29+
));
30+
}
31+
}

0 commit comments

Comments
 (0)