Skip to content

Commit f437b74

Browse files
authored
Introduce oldClusterHasFeatures to full-cluster-restart (#104462)
Remove Version-based prerequisites in favour of feature-based prerequisites in ParameterizedFullClusterRestartTestCase and derived. Follows #104279
1 parent 3f4d811 commit f437b74

File tree

10 files changed

+111
-54
lines changed

10 files changed

+111
-54
lines changed

qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/upgrades/FullClusterRestartIT.java

+7-19
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import org.apache.http.util.EntityUtils;
1616
import org.elasticsearch.Build;
17-
import org.elasticsearch.Version;
1817
import org.elasticsearch.action.admin.cluster.settings.RestClusterGetSettingsResponse;
1918
import org.elasticsearch.client.Request;
2019
import org.elasticsearch.client.Response;
@@ -266,10 +265,7 @@ public void testNewReplicas() throws Exception {
266265
}
267266

268267
public void testSearchTimeSeriesMode() throws Exception {
269-
270-
var originalClusterHasNewTimeSeriesIndexing = parseLegacyVersion(getOldClusterVersion()).map(v -> v.onOrAfter(Version.V_8_2_0))
271-
.orElse(true);
272-
assumeTrue("indexing time series indices changed in 8.2.0", originalClusterHasNewTimeSeriesIndexing);
268+
assumeTrue("indexing time series indices changed in 8.2.0", oldClusterHasFeature(RestTestLegacyFeatures.TSDB_NEW_INDEX_FORMAT));
273269
int numDocs;
274270
if (isRunningAgainstOldCluster()) {
275271
numDocs = createTimeSeriesModeIndex(1);
@@ -307,9 +303,7 @@ public void testSearchTimeSeriesMode() throws Exception {
307303
}
308304

309305
public void testNewReplicasTimeSeriesMode() throws Exception {
310-
var originalClusterHasNewTimeSeriesIndexing = parseLegacyVersion(getOldClusterVersion()).map(v -> v.onOrAfter(Version.V_8_2_0))
311-
.orElse(true);
312-
assumeTrue("indexing time series indices changed in 8.2.0", originalClusterHasNewTimeSeriesIndexing);
306+
assumeTrue("indexing time series indices changed in 8.2.0", oldClusterHasFeature(RestTestLegacyFeatures.TSDB_NEW_INDEX_FORMAT));
313307
if (isRunningAgainstOldCluster()) {
314308
createTimeSeriesModeIndex(0);
315309
} else {
@@ -1216,9 +1210,7 @@ public void testClosedIndices() throws Exception {
12161210
}
12171211

12181212
@UpdateForV9 // This check can be removed (always assume true)
1219-
var originalClusterSupportsReplicationOfClosedIndices = parseLegacyVersion(getOldClusterVersion()).map(
1220-
v -> v.onOrAfter(Version.V_7_2_0)
1221-
).orElse(true);
1213+
var originalClusterSupportsReplicationOfClosedIndices = oldClusterHasFeature(RestTestLegacyFeatures.REPLICATION_OF_CLOSED_INDICES);
12221214

12231215
if (originalClusterSupportsReplicationOfClosedIndices) {
12241216
ensureGreenLongWait(index);
@@ -1624,9 +1616,7 @@ public void testResize() throws Exception {
16241616
public void testSystemIndexMetadataIsUpgraded() throws Exception {
16251617

16261618
@UpdateForV9 // assumeTrue can be removed (condition always true)
1627-
var originalClusterTaskIndexIsSystemIndex = parseLegacyVersion(getOldClusterVersion()).map(v -> v.onOrAfter(Version.V_7_10_0))
1628-
.orElse(true);
1629-
1619+
var originalClusterTaskIndexIsSystemIndex = oldClusterHasFeature(RestTestLegacyFeatures.TASK_INDEX_SYSTEM_INDEX);
16301620
assumeTrue(".tasks became a system index in 7.10.0", originalClusterTaskIndexIsSystemIndex);
16311621
final String systemIndexWarning = "this request accesses system indices: [.tasks], but in a future major version, direct "
16321622
+ "access to system indices will be prevented by default";
@@ -1748,8 +1738,7 @@ public void testSystemIndexMetadataIsUpgraded() throws Exception {
17481738
*/
17491739
@UpdateForV9 // This test can be removed in v9
17501740
public void testEnableSoftDeletesOnRestore() throws Exception {
1751-
var originalClusterDidNotEnforceSoftDeletes = parseLegacyVersion(getOldClusterVersion()).map(v -> v.before(Version.V_8_0_0))
1752-
.orElse(false);
1741+
var originalClusterDidNotEnforceSoftDeletes = oldClusterHasFeature(RestTestLegacyFeatures.SOFT_DELETES_ENFORCED) == false;
17531742

17541743
assumeTrue("soft deletes must be enabled on 8.0+", originalClusterDidNotEnforceSoftDeletes);
17551744
final String snapshot = "snapshot-" + index;
@@ -1862,9 +1851,8 @@ public void testForbidDisableSoftDeletesOnRestore() throws Exception {
18621851
*/
18631852
@UpdateForV9
18641853
public void testTransportCompressionSetting() throws IOException {
1865-
var originalClusterCompressSettingIsBoolean = parseLegacyVersion(getOldClusterVersion()).map(v -> v.before(Version.V_7_14_0))
1866-
.orElse(false);
1867-
assumeTrue("the old transport.compress setting existed before 7.14", originalClusterCompressSettingIsBoolean);
1854+
var originalClusterBooleanCompressSetting = oldClusterHasFeature(RestTestLegacyFeatures.NEW_TRANSPORT_COMPRESSED_SETTING) == false;
1855+
assumeTrue("the old transport.compress setting existed before 7.14", originalClusterBooleanCompressSetting);
18681856
if (isRunningAgainstOldCluster()) {
18691857
client().performRequest(
18701858
newXContentRequest(

qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/upgrades/ParameterizedFullClusterRestartTestCase.java

+23
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import org.elasticsearch.client.Request;
1616
import org.elasticsearch.client.Response;
17+
import org.elasticsearch.features.NodeFeature;
1718
import org.elasticsearch.index.IndexVersion;
1819
import org.elasticsearch.index.IndexVersions;
1920
import org.elasticsearch.test.cluster.ElasticsearchCluster;
@@ -26,6 +27,7 @@
2627
import java.util.Arrays;
2728
import java.util.Locale;
2829
import java.util.Map;
30+
import java.util.Set;
2931

3032
import static org.elasticsearch.upgrades.FullClusterRestartUpgradeStatus.OLD;
3133
import static org.elasticsearch.upgrades.FullClusterRestartUpgradeStatus.UPGRADED;
@@ -39,6 +41,8 @@ public abstract class ParameterizedFullClusterRestartTestCase extends ESRestTest
3941
private static IndexVersion oldIndexVersion;
4042
private static boolean upgradeFailed = false;
4143
private static boolean upgraded = false;
44+
45+
private static Set<String> oldClusterFeatures;
4246
private final FullClusterRestartUpgradeStatus requestedUpgradeStatus;
4347

4448
public ParameterizedFullClusterRestartTestCase(@Name("cluster") FullClusterRestartUpgradeStatus upgradeStatus) {
@@ -50,6 +54,15 @@ public static Iterable<Object[]> parameters() throws Exception {
5054
return Arrays.stream(FullClusterRestartUpgradeStatus.values()).map(v -> new Object[] { v }).toList();
5155
}
5256

57+
@Before
58+
public void extractOldClusterFeatures() {
59+
if (upgraded == false && oldClusterFeatures == null) {
60+
assert testFeatureServiceInitialized()
61+
: "Old cluster features can be extracted only after testFeatureService has been initialized. See ESRestTestCase#initClient";
62+
oldClusterFeatures = Set.copyOf(testFeatureService.getAllSupportedFeatures());
63+
}
64+
}
65+
5366
@Before
5467
public void extractOldIndexVersion() throws Exception {
5568
if (upgraded == false) {
@@ -111,6 +124,7 @@ public void maybeUpgrade() throws Exception {
111124
public static void resetUpgrade() {
112125
upgraded = false;
113126
upgradeFailed = false;
127+
oldClusterFeatures = null;
114128
}
115129

116130
public boolean isRunningAgainstOldCluster() {
@@ -121,6 +135,15 @@ public static String getOldClusterVersion() {
121135
return OLD_CLUSTER_VERSION;
122136
}
123137

138+
protected static boolean oldClusterHasFeature(String featureId) {
139+
assert oldClusterFeatures != null : "Old cluster features cannot be accessed before initialization is completed";
140+
return oldClusterFeatures.contains(featureId);
141+
}
142+
143+
protected static boolean oldClusterHasFeature(NodeFeature feature) {
144+
return oldClusterHasFeature(feature.id());
145+
}
146+
124147
public static IndexVersion getOldClusterIndexVersion() {
125148
assert oldIndexVersion != null;
126149
return oldIndexVersion;

qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/upgrades/QueryBuilderBWCIT.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.elasticsearch.test.cluster.FeatureFlag;
4343
import org.elasticsearch.test.cluster.local.LocalClusterConfigProvider;
4444
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
45+
import org.elasticsearch.test.rest.RestTestLegacyFeatures;
4546
import org.elasticsearch.xcontent.XContentBuilder;
4647
import org.junit.ClassRule;
4748

@@ -53,7 +54,6 @@
5354
import java.util.List;
5455
import java.util.Map;
5556

56-
import static org.elasticsearch.cluster.ClusterState.VERSION_INTRODUCING_TRANSPORT_VERSIONS;
5757
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
5858

5959
/**
@@ -255,10 +255,7 @@ public void testQueryBuilderBWC() throws Exception {
255255
) {
256256

257257
@UpdateForV9 // condition will always be true
258-
var originalClusterHasTransportVersion = parseLegacyVersion(getOldClusterVersion()).map(
259-
v -> v.onOrAfter(VERSION_INTRODUCING_TRANSPORT_VERSIONS)
260-
).orElse(true);
261-
258+
var originalClusterHasTransportVersion = oldClusterHasFeature(RestTestLegacyFeatures.TRANSPORT_VERSION_SUPPORTED);
262259
final TransportVersion transportVersion;
263260
if (originalClusterHasTransportVersion == false) {
264261
transportVersion = TransportVersion.fromId(

qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/FeatureUpgradeIT.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,14 @@ public void testGetFeatureUpgradeStatus() throws Exception {
100100

101101
assertThat(feature, aMapWithSize(4));
102102
assertThat(feature.get("minimum_index_version"), equalTo(getOldClusterIndexVersion().toString()));
103-
if (getOldClusterVersion().before(TransportGetFeatureUpgradeStatusAction.NO_UPGRADE_REQUIRED_VERSION)) {
103+
104+
// Feature migration happens only across major versions; also, we usually begin to require migrations once we start testing
105+
// for the next major version upgrade (see e.g. #93666). Trying to express this with features may be problematic, so we
106+
// want to keep using versions here. We also assume that for non-semantic version migrations are not required.
107+
boolean migrationNeeded = parseLegacyVersion(getOldClusterVersion()).map(
108+
v -> v.before(TransportGetFeatureUpgradeStatusAction.NO_UPGRADE_REQUIRED_VERSION)
109+
).orElse(false);
110+
if (migrationNeeded) {
104111
assertThat(feature.get("migration_status"), equalTo("MIGRATION_NEEDED"));
105112
} else {
106113
assertThat(feature.get("migration_status"), equalTo("NO_MIGRATION_NEEDED"));

qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/ParameterizedRollingUpgradeTestCase.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.core.SuppressForbidden;
1818
import org.elasticsearch.features.NodeFeature;
1919
import org.elasticsearch.index.IndexVersion;
20+
import org.elasticsearch.index.IndexVersions;
2021
import org.elasticsearch.test.cluster.ElasticsearchCluster;
2122
import org.elasticsearch.test.cluster.FeatureFlag;
2223
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
@@ -99,12 +100,13 @@ public void extractOldIndexVersion() throws Exception {
99100
Map<String, Object> nodeMap = objectPath.evaluate("nodes");
100101
for (String id : nodeMap.keySet()) {
101102
Number ix = objectPath.evaluate("nodes." + id + ".index_version");
102-
IndexVersion version;
103+
final IndexVersion version;
103104
if (ix != null) {
104105
version = IndexVersion.fromId(ix.intValue());
105106
} else {
106107
// it doesn't have index version (pre 8.11) - just infer it from the release version
107-
version = IndexVersion.fromId(getOldClusterVersion().id);
108+
version = parseLegacyVersion(getOldClusterVersion()).map(v -> IndexVersion.fromId(v.id))
109+
.orElse(IndexVersions.MINIMUM_COMPATIBLE);
108110
}
109111

110112
if (indexVersion == null) {
@@ -152,8 +154,8 @@ public static void resetNodes() {
152154
}
153155

154156
@Deprecated // Use the new testing framework and oldClusterHasFeature(feature) instead
155-
protected static org.elasticsearch.Version getOldClusterVersion() {
156-
return org.elasticsearch.Version.fromString(OLD_CLUSTER_VERSION);
157+
protected static String getOldClusterVersion() {
158+
return OLD_CLUSTER_VERSION;
157159
}
158160

159161
protected static boolean oldClusterHasFeature(String featureId) {

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,18 @@ protected static boolean clusterHasFeature(NodeFeature feature) {
274274
return testFeatureService.clusterHasFeature(feature.id());
275275
}
276276

277+
protected static boolean testFeatureServiceInitialized() {
278+
return testFeatureService != ALL_FEATURES;
279+
}
280+
277281
@Before
278282
public void initClient() throws IOException {
279283
if (client == null) {
280284
assert adminClient == null;
281285
assert clusterHosts == null;
282286
assert availableFeatures == null;
283287
assert nodesVersions == null;
284-
assert testFeatureService == ALL_FEATURES;
288+
assert testFeatureServiceInitialized() == false;
285289
clusterHosts = parseClusterHosts(getTestRestCluster());
286290
logger.info("initializing REST clients against {}", clusterHosts);
287291
client = buildClient(restClientSettings(), clusterHosts.toArray(new HttpHost[clusterHosts.size()]));
@@ -343,7 +347,7 @@ public void initClient() throws IOException {
343347
testFeatureService = createTestFeatureService(getClusterStateFeatures(adminClient), semanticNodeVersions);
344348
}
345349

346-
assert testFeatureService != ALL_FEATURES;
350+
assert testFeatureServiceInitialized();
347351
assert client != null;
348352
assert adminClient != null;
349353
assert clusterHosts != null;

test/framework/src/main/java/org/elasticsearch/test/rest/RestTestLegacyFeatures.java

+39-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,32 @@ public class RestTestLegacyFeatures implements FeatureSpecification {
9797
public static final NodeFeature INDEXING_SLOWLOG_LEVEL_SETTING_REMOVED = new NodeFeature("settings.indexing_slowlog_level_removed");
9898
public static final NodeFeature DEPRECATION_WARNINGS_LEAK_FIXED = new NodeFeature("deprecation_warnings_leak_fixed");
9999

100+
// QA - Full cluster restart
101+
@UpdateForV9
102+
public static final NodeFeature REPLICATION_OF_CLOSED_INDICES = new NodeFeature("indices.closed_replication_supported");
103+
@UpdateForV9
104+
public static final NodeFeature TASK_INDEX_SYSTEM_INDEX = new NodeFeature("tasks.moved_to_system_index");
105+
@UpdateForV9
106+
public static final NodeFeature SOFT_DELETES_ENFORCED = new NodeFeature("indices.soft_deletes_enforced");
107+
@UpdateForV9
108+
public static final NodeFeature NEW_TRANSPORT_COMPRESSED_SETTING = new NodeFeature("transport.new_compressed_setting");
109+
@UpdateForV9
110+
public static final NodeFeature SHUTDOWN_SUPPORTED = new NodeFeature("shutdown.supported");
111+
@UpdateForV9
112+
public static final NodeFeature SERVICE_ACCOUNTS_SUPPORTED = new NodeFeature("auth.service_accounts_supported");
113+
@UpdateForV9
114+
public static final NodeFeature TRANSFORM_SUPPORTED = new NodeFeature("transform.supported");
115+
@UpdateForV9
116+
public static final NodeFeature SLM_SUPPORTED = new NodeFeature("slm.supported");
117+
@UpdateForV9
118+
public static final NodeFeature DATA_STREAMS_SUPPORTED = new NodeFeature("data_stream.supported");
119+
@UpdateForV9
120+
public static final NodeFeature NEW_DATA_STREAMS_INDEX_NAME_FORMAT = new NodeFeature("data_stream.new_index_name_format");
121+
@UpdateForV9
122+
public static final NodeFeature DISABLE_FIELD_NAMES_FIELD_REMOVED = new NodeFeature("disable_of_field_names_field_removed");
123+
@UpdateForV9
124+
public static final NodeFeature ML_NLP_SUPPORTED = new NodeFeature("ml.nlp_supported");
125+
100126
// YAML
101127
public static final NodeFeature REST_ELASTIC_PRODUCT_HEADER_PRESENT = new NodeFeature("action.rest.product_header_present");
102128

@@ -133,7 +159,19 @@ public Map<NodeFeature, Version> getHistoricalFeatures() {
133159
entry(TSDB_GENERALLY_AVAILABLE, Version.V_8_7_0),
134160
entry(TSDB_EMPTY_TEMPLATE_FIXED, Version.V_8_11_0),
135161
entry(INDEXING_SLOWLOG_LEVEL_SETTING_REMOVED, Version.V_8_0_0),
136-
entry(DEPRECATION_WARNINGS_LEAK_FIXED, Version.V_7_17_9)
162+
entry(DEPRECATION_WARNINGS_LEAK_FIXED, Version.V_7_17_9),
163+
entry(REPLICATION_OF_CLOSED_INDICES, Version.V_7_2_0),
164+
entry(TASK_INDEX_SYSTEM_INDEX, Version.V_7_10_0),
165+
entry(SOFT_DELETES_ENFORCED, Version.V_8_0_0),
166+
entry(NEW_TRANSPORT_COMPRESSED_SETTING, Version.V_7_14_0),
167+
entry(SHUTDOWN_SUPPORTED, Version.V_7_15_0),
168+
entry(SERVICE_ACCOUNTS_SUPPORTED, Version.V_7_13_0),
169+
entry(TRANSFORM_SUPPORTED, Version.V_7_2_0),
170+
entry(SLM_SUPPORTED, Version.V_7_4_0),
171+
entry(DATA_STREAMS_SUPPORTED, Version.V_7_9_0),
172+
entry(NEW_DATA_STREAMS_INDEX_NAME_FORMAT, Version.V_7_11_0),
173+
entry(DISABLE_FIELD_NAMES_FIELD_REMOVED, Version.V_8_0_0),
174+
entry(ML_NLP_SUPPORTED, Version.V_8_0_0)
137175
);
138176
}
139177
}

x-pack/plugin/shutdown/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/xpack/restart/FullClusterRestartIT.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import com.carrotsearch.randomizedtesting.annotations.Name;
1010

11-
import org.elasticsearch.Version;
1211
import org.elasticsearch.client.Request;
1312
import org.elasticsearch.client.Response;
1413
import org.elasticsearch.cluster.metadata.SingleNodeShutdownMetadata;
@@ -21,11 +20,12 @@
2120
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
2221
import org.elasticsearch.test.cluster.util.resource.Resource;
2322
import org.elasticsearch.test.rest.ESRestTestCase;
23+
import org.elasticsearch.test.rest.RestTestLegacyFeatures;
2424
import org.elasticsearch.upgrades.FullClusterRestartUpgradeStatus;
2525
import org.elasticsearch.upgrades.ParameterizedFullClusterRestartTestCase;
2626
import org.elasticsearch.xcontent.XContentBuilder;
2727
import org.elasticsearch.xcontent.json.JsonXContent;
28-
import org.junit.BeforeClass;
28+
import org.junit.Before;
2929
import org.junit.ClassRule;
3030

3131
import java.io.IOException;
@@ -88,11 +88,10 @@ protected Settings restClientSettings() {
8888
.build();
8989
}
9090

91-
@BeforeClass
92-
public static void checkClusterVersion() {
91+
@Before
92+
public void checkClusterVersion() {
9393
@UpdateForV9 // always true
94-
var originalClusterSupportsShutdown = parseLegacyVersion(getOldClusterVersion()).map(v -> v.onOrAfter(Version.V_7_15_0))
95-
.orElse(true);
94+
var originalClusterSupportsShutdown = oldClusterHasFeature(RestTestLegacyFeatures.SHUTDOWN_SUPPORTED);
9695
assumeTrue("no shutdown in versions before 7.15", originalClusterSupportsShutdown);
9796
}
9897

0 commit comments

Comments
 (0)