Skip to content

Commit ede1a7a

Browse files
authored
Include v7 in IndexVersionUtils#ALL_VERSIONS (#118793)
We are going to retain read-only compatibility with v7 index versions upon upgrade to v9. This means that all the v7 index versions and corresponding version conditionals will stay around for another major series. This PR reflects this decision in the codebase. No need to filter index versions when retrieving ALL_VERSIONS, and we can remove corresponding @UpdateForV9 annotations from the IndexVersions class. At the same time, there are tests that need to randomize version but need to write to an index, hence 7x versions should be filtered out. The overall goal is to extend testing to v7 index versions when possible, and making randomization across writeable versions an exception that certain tests can rely on as needed. These are the mechanical steps I made in this PR: - Rename `getFirstVersion` to `getLowestReadCompatibleVersion`, which returns the lowest supported index version ( which can not be written to) - Introduce `getLowestWriteCompatibleVersion` to identify the lowest writeable version. This is used by tests that used to call `getFirstVersion` and need to write to the index. - Remove `randomVersion(Random random)` in favour of `randomVersion()` . It was always called providing `random()` which is equivalent to what `randomVersion()` already does. - Introduce `randomWriteVersion` for tests that need a random writeable version. Moved tests that need it to use it (from `randomVersion` to `randomWriteVersion`) There is still work to do in `IndexVersionUtils` to extend testing, especially as some randomized tests have a lower bound of `MINIMUM_COMPATIBLE_VERSION` hence don't include v7 index versions yet. We will address that as a follow-up.
1 parent 47d5e87 commit ede1a7a

File tree

32 files changed

+83
-80
lines changed

32 files changed

+83
-80
lines changed

modules/analysis-common/src/test/java/org/elasticsearch/analysis/common/NGramTokenizerFactoryTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public void testBackwardsCompatibilityEdgeNgramTokenFilter() throws Exception {
161161
for (int i = 0; i < iters; i++) {
162162
final Index index = new Index("test", "_na_");
163163
final String name = "ngr";
164-
IndexVersion v = IndexVersionUtils.randomVersion(random());
164+
IndexVersion v = IndexVersionUtils.randomVersion();
165165
Builder builder = newAnalysisSettingsBuilder().put("min_gram", 2).put("max_gram", 3);
166166
boolean reverse = random().nextBoolean();
167167
if (reverse) {

modules/analysis-common/src/test/java/org/elasticsearch/analysis/common/PersianAnalyzerProviderTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void testPersianAnalyzerPostLucene10() throws IOException {
5656
public void testPersianAnalyzerPreLucene10() throws IOException {
5757
IndexVersion preLucene10Version = IndexVersionUtils.randomVersionBetween(
5858
random(),
59-
IndexVersionUtils.getFirstVersion(),
59+
IndexVersionUtils.getLowestReadCompatibleVersion(),
6060
IndexVersionUtils.getPreviousVersion(IndexVersions.UPGRADE_TO_LUCENE_10_0_0)
6161
);
6262
Settings settings = ESTestCase.indexSettings(1, 1)

modules/analysis-common/src/test/java/org/elasticsearch/analysis/common/RomanianAnalyzerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void testRomanianAnalyzerPostLucene10() throws IOException {
5757
public void testRomanianAnalyzerPreLucene10() throws IOException {
5858
IndexVersion preLucene10Version = IndexVersionUtils.randomVersionBetween(
5959
random(),
60-
IndexVersionUtils.getFirstVersion(),
60+
IndexVersionUtils.getLowestReadCompatibleVersion(),
6161
IndexVersionUtils.getPreviousVersion(IndexVersions.UPGRADE_TO_LUCENE_10_0_0)
6262
);
6363
Settings settings = ESTestCase.indexSettings(1, 1)

modules/analysis-common/src/test/java/org/elasticsearch/analysis/common/StemmerTokenFilterFactoryTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class StemmerTokenFilterFactoryTests extends ESTokenStreamTestCase {
3939
public void testEnglishFilterFactory() throws IOException {
4040
int iters = scaledRandomIntBetween(20, 100);
4141
for (int i = 0; i < iters; i++) {
42-
IndexVersion v = IndexVersionUtils.randomVersion(random());
42+
IndexVersion v = IndexVersionUtils.randomVersion();
4343
Settings settings = Settings.builder()
4444
.put("index.analysis.filter.my_english.type", "stemmer")
4545
.put("index.analysis.filter.my_english.language", "english")
@@ -66,7 +66,7 @@ public void testPorter2FilterFactory() throws IOException {
6666
int iters = scaledRandomIntBetween(20, 100);
6767
for (int i = 0; i < iters; i++) {
6868

69-
IndexVersion v = IndexVersionUtils.randomVersion(random());
69+
IndexVersion v = IndexVersionUtils.randomVersion();
7070
Settings settings = Settings.builder()
7171
.put("index.analysis.filter.my_porter2.type", "stemmer")
7272
.put("index.analysis.filter.my_porter2.language", "porter2")
@@ -90,7 +90,7 @@ public void testPorter2FilterFactory() throws IOException {
9090
}
9191

9292
public void testMultipleLanguagesThrowsException() throws IOException {
93-
IndexVersion v = IndexVersionUtils.randomVersion(random());
93+
IndexVersion v = IndexVersionUtils.randomVersion();
9494
Settings settings = Settings.builder()
9595
.put("index.analysis.filter.my_english.type", "stemmer")
9696
.putList("index.analysis.filter.my_english.language", "english", "light_english")
@@ -142,7 +142,7 @@ private static Analyzer createGermanStemmer(String variant, IndexVersion v) thro
142142
}
143143

144144
public void testKpDeprecation() throws IOException {
145-
IndexVersion v = IndexVersionUtils.randomVersion(random());
145+
IndexVersion v = IndexVersionUtils.randomVersion();
146146
Settings settings = Settings.builder()
147147
.put("index.analysis.filter.my_kp.type", "stemmer")
148148
.put("index.analysis.filter.my_kp.language", "kp")
@@ -155,7 +155,7 @@ public void testKpDeprecation() throws IOException {
155155
}
156156

157157
public void testLovinsDeprecation() throws IOException {
158-
IndexVersion v = IndexVersionUtils.randomVersion(random());
158+
IndexVersion v = IndexVersionUtils.randomVersion();
159159
Settings settings = Settings.builder()
160160
.put("index.analysis.filter.my_lovins.type", "stemmer")
161161
.put("index.analysis.filter.my_lovins.language", "lovins")

server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/ShrinkIndexIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ private static IndexMetadata indexMetadata(final Client client, final String ind
236236

237237
public void testCreateShrinkIndex() {
238238
internalCluster().ensureAtLeastNumDataNodes(2);
239-
IndexVersion version = IndexVersionUtils.randomVersion(random());
239+
IndexVersion version = IndexVersionUtils.randomWriteVersion();
240240
prepareCreate("source").setSettings(
241241
Settings.builder().put(indexSettings()).put("number_of_shards", randomIntBetween(2, 7)).put("index.version.created", version)
242242
).get();

server/src/internalClusterTest/java/org/elasticsearch/cluster/ClusterStateDiffIT.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import static org.elasticsearch.test.XContentTestUtils.convertToMap;
7272
import static org.elasticsearch.test.XContentTestUtils.differenceBetweenMapsIgnoringArrayOrder;
7373
import static org.elasticsearch.test.index.IndexVersionUtils.randomVersion;
74+
import static org.elasticsearch.test.index.IndexVersionUtils.randomWriteVersion;
7475
import static org.hamcrest.Matchers.equalTo;
7576
import static org.hamcrest.Matchers.is;
7677

@@ -218,7 +219,7 @@ private ClusterState.Builder randomCoordinationMetadata(ClusterState clusterStat
218219

219220
private DiscoveryNode randomNode(String nodeId) {
220221
Version nodeVersion = VersionUtils.randomVersion(random());
221-
IndexVersion indexVersion = randomVersion(random());
222+
IndexVersion indexVersion = randomVersion();
222223
return DiscoveryNodeUtils.builder(nodeId)
223224
.roles(emptySet())
224225
.version(nodeVersion, IndexVersion.fromId(indexVersion.id() - 1_000_000), indexVersion)
@@ -561,7 +562,7 @@ public IndexMetadata randomCreate(String name) {
561562
IndexMetadata.Builder builder = IndexMetadata.builder(name);
562563
Settings.Builder settingsBuilder = Settings.builder();
563564
setRandomIndexSettings(random(), settingsBuilder);
564-
settingsBuilder.put(randomSettings(Settings.EMPTY)).put(IndexMetadata.SETTING_VERSION_CREATED, randomVersion(random()));
565+
settingsBuilder.put(randomSettings(Settings.EMPTY)).put(IndexMetadata.SETTING_VERSION_CREATED, randomWriteVersion());
565566
builder.settings(settingsBuilder);
566567
builder.numberOfShards(randomIntBetween(1, 10)).numberOfReplicas(randomInt(10));
567568
builder.eventIngestedRange(IndexLongFieldRange.UNKNOWN, TransportVersion.current());
@@ -736,7 +737,7 @@ public ClusterState.Custom randomCreate(String name) {
736737
ImmutableOpenMap.of(),
737738
null,
738739
SnapshotInfoTestUtils.randomUserMetadata(),
739-
randomVersion(random())
740+
randomVersion()
740741
)
741742
);
742743
case 1 -> new RestoreInProgress.Builder().add(

server/src/internalClusterTest/java/org/elasticsearch/indices/analysis/PreBuiltAnalyzerIntegrationIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void testThatPreBuiltAnalyzersAreNotClosedOnIndexClose() throws Exception
4747
PreBuiltAnalyzers preBuiltAnalyzer = PreBuiltAnalyzers.values()[randomInt];
4848
String name = preBuiltAnalyzer.name().toLowerCase(Locale.ROOT);
4949

50-
IndexVersion randomVersion = IndexVersionUtils.randomVersion(random());
50+
IndexVersion randomVersion = IndexVersionUtils.randomWriteVersion();
5151
if (loadedAnalyzers.containsKey(preBuiltAnalyzer) == false) {
5252
loadedAnalyzers.put(preBuiltAnalyzer, new ArrayList<>());
5353
}

server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2050,7 +2050,7 @@ public void testPostRecoveryMergeDisabledOnOlderIndices() throws Exception {
20502050
IndexMetadata.SETTING_VERSION_CREATED,
20512051
IndexVersionUtils.randomVersionBetween(
20522052
random(),
2053-
IndexVersionUtils.getFirstVersion(),
2053+
IndexVersionUtils.getLowestWriteCompatibleVersion(),
20542054
IndexVersionUtils.getPreviousVersion(IndexVersions.MERGE_ON_RECOVERY_VERSION)
20552055
)
20562056
)

server/src/main/java/org/elasticsearch/index/IndexVersions.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.apache.lucene.util.Version;
1313
import org.elasticsearch.ReleaseVersions;
1414
import org.elasticsearch.core.Assertions;
15-
import org.elasticsearch.core.UpdateForV9;
1615

1716
import java.lang.reflect.Field;
1817
import java.text.ParseException;
@@ -25,6 +24,7 @@
2524
import java.util.TreeMap;
2625
import java.util.TreeSet;
2726
import java.util.function.IntFunction;
27+
import java.util.stream.Collectors;
2828

2929
@SuppressWarnings("deprecation")
3030
public class IndexVersions {
@@ -58,7 +58,6 @@ private static Version parseUnchecked(String version) {
5858
}
5959
}
6060

61-
@UpdateForV9(owner = UpdateForV9.Owner.SEARCH_FOUNDATIONS) // remove the index versions with which v9 will not need to interact
6261
public static final IndexVersion ZERO = def(0, Version.LATEST);
6362

6463
public static final IndexVersion V_7_0_0 = def(7_00_00_99, parseUnchecked("8.0.0"));
@@ -244,10 +243,12 @@ static NavigableMap<Integer, IndexVersion> getAllVersionIds(Class<?> cls) {
244243
return Collections.unmodifiableNavigableMap(builder);
245244
}
246245

247-
@UpdateForV9(owner = UpdateForV9.Owner.CORE_INFRA)
248-
// We can simplify this once we've removed all references to index versions earlier than MINIMUM_COMPATIBLE
246+
static Collection<IndexVersion> getAllWriteVersions() {
247+
return VERSION_IDS.values().stream().filter(v -> v.onOrAfter(IndexVersions.MINIMUM_COMPATIBLE)).collect(Collectors.toSet());
248+
}
249+
249250
static Collection<IndexVersion> getAllVersions() {
250-
return VERSION_IDS.values().stream().filter(v -> v.onOrAfter(MINIMUM_COMPATIBLE)).toList();
251+
return VERSION_IDS.values();
251252
}
252253

253254
static final IntFunction<String> VERSION_LOOKUP = ReleaseVersions.generateVersionsLookup(IndexVersions.class, LATEST_DEFINED.id());

server/src/test/java/org/elasticsearch/cluster/metadata/HumanReadableIndexSettingsTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
public class HumanReadableIndexSettingsTests extends ESTestCase {
2424
public void testHumanReadableSettings() {
25-
IndexVersion versionCreated = randomVersion(random());
25+
IndexVersion versionCreated = randomVersion();
2626
long created = System.currentTimeMillis();
2727
Settings testSettings = Settings.builder()
2828
.put(IndexMetadata.SETTING_VERSION_CREATED, versionCreated)

0 commit comments

Comments
 (0)