Skip to content

Commit 381132c

Browse files
authored
Restore index versions 7 in lucene_snapshot_10 (#113317)
1 parent 22d88d2 commit 381132c

File tree

64 files changed

+614
-196
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+614
-196
lines changed

modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/CommonAnalysisPlugin.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
import org.apache.lucene.analysis.util.ElisionFilter;
103103
import org.apache.lucene.util.SetOnce;
104104
import org.elasticsearch.common.regex.Regex;
105+
import org.elasticsearch.index.IndexVersions;
105106
import org.elasticsearch.index.analysis.AnalyzerProvider;
106107
import org.elasticsearch.index.analysis.CharFilterFactory;
107108
import org.elasticsearch.index.analysis.PreBuiltAnalyzerProviderFactory;
@@ -480,9 +481,10 @@ public List<PreConfiguredTokenFilter> getPreConfiguredTokenFilters() {
480481
)
481482
);
482483
filters.add(PreConfiguredTokenFilter.indexVersion("word_delimiter_graph", false, false, (input, version) -> {
484+
boolean adjustOffsets = version.onOrAfter(IndexVersions.V_7_3_0);
483485
return new WordDelimiterGraphFilter(
484486
input,
485-
true,
487+
adjustOffsets,
486488
WordDelimiterIterator.DEFAULT_WORD_DELIM_TABLE,
487489
WordDelimiterGraphFilter.GENERATE_WORD_PARTS | WordDelimiterGraphFilter.GENERATE_NUMBER_PARTS
488490
| WordDelimiterGraphFilter.SPLIT_ON_CASE_CHANGE | WordDelimiterGraphFilter.SPLIT_ON_NUMERICS
@@ -515,6 +517,7 @@ public List<PreConfiguredTokenizer> getPreConfiguredTokenizers() {
515517
// This is already broken with normalization, so backwards compat isn't necessary?
516518
tokenizers.add(PreConfiguredTokenizer.singleton("lowercase", XLowerCaseTokenizer::new));
517519
tokenizers.add(PreConfiguredTokenizer.singleton("PathHierarchy", PathHierarchyTokenizer::new));
520+
518521
return tokenizers;
519522
}
520523
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ public void testShingleFilters() {
338338
Settings settings = Settings.builder()
339339
.put(
340340
IndexMetadata.SETTING_VERSION_CREATED,
341-
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.V_8_0_0, IndexVersion.current())
341+
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.MINIMUM_COMPATIBLE, IndexVersion.current())
342342
)
343343
.put("path.home", createTempDir().toString())
344344
.put("index.analysis.filter.synonyms.type", "synonym")
@@ -392,7 +392,7 @@ public void testPreconfiguredTokenFilters() throws IOException {
392392
Settings settings = Settings.builder()
393393
.put(
394394
IndexMetadata.SETTING_VERSION_CREATED,
395-
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.V_8_0_0, IndexVersion.current())
395+
IndexVersionUtils.randomVersionBetween(random(), IndexVersions.MINIMUM_COMPATIBLE, IndexVersion.current())
396396
)
397397
.put("path.home", createTempDir().toString())
398398
.build();

modules/legacy-geo/src/main/java/org/elasticsearch/legacygeo/mapper/LegacyGeoShapeFieldMapper.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.elasticsearch.core.CheckedConsumer;
3131
import org.elasticsearch.geometry.Geometry;
3232
import org.elasticsearch.index.IndexVersion;
33+
import org.elasticsearch.index.IndexVersions;
3334
import org.elasticsearch.index.analysis.NamedAnalyzer;
3435
import org.elasticsearch.index.mapper.AbstractShapeGeometryFieldMapper;
3536
import org.elasticsearch.index.mapper.DocumentParserContext;
@@ -232,7 +233,9 @@ public Builder(String name, IndexVersion version, boolean ignoreMalformedByDefau
232233
});
233234

234235
// Set up serialization
235-
this.strategy.alwaysSerialize();
236+
if (version.onOrAfter(IndexVersions.V_7_0_0)) {
237+
this.strategy.alwaysSerialize();
238+
}
236239
// serialize treeLevels if treeLevels is configured, OR if defaults are requested and precision is not configured
237240
treeLevels.setSerializerCheck((id, ic, v) -> ic || (id && precision.get() == null));
238241
// serialize precision if precision is configured, OR if defaults are requested and treeLevels is not configured

modules/legacy-geo/src/test/java/org/elasticsearch/legacygeo/GeoJsonShapeParserTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.elasticsearch.geometry.MultiLine;
2323
import org.elasticsearch.geometry.MultiPoint;
2424
import org.elasticsearch.index.IndexVersion;
25+
import org.elasticsearch.index.IndexVersions;
2526
import org.elasticsearch.index.mapper.MapperBuilderContext;
2627
import org.elasticsearch.legacygeo.mapper.LegacyGeoShapeFieldMapper;
2728
import org.elasticsearch.legacygeo.parsers.ShapeParser;
@@ -390,7 +391,7 @@ public void testParse3DPolygon() throws IOException, ParseException {
390391

391392
LinearRing shell = GEOMETRY_FACTORY.createLinearRing(shellCoordinates.toArray(new Coordinate[shellCoordinates.size()]));
392393
Polygon expected = GEOMETRY_FACTORY.createPolygon(shell, null);
393-
final IndexVersion version = IndexVersionUtils.randomCompatibleVersion(random());
394+
final IndexVersion version = IndexVersionUtils.randomPreviousCompatibleVersion(random(), IndexVersions.V_8_0_0);
394395
final LegacyGeoShapeFieldMapper mapperBuilder = new LegacyGeoShapeFieldMapper.Builder("test", version, false, true).build(
395396
MapperBuilderContext.root(false, false)
396397
);

modules/legacy-geo/src/test/java/org/elasticsearch/legacygeo/GeoWKTShapeParserTests.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.elasticsearch.geometry.MultiLine;
2121
import org.elasticsearch.geometry.MultiPoint;
2222
import org.elasticsearch.index.IndexVersion;
23+
import org.elasticsearch.index.IndexVersions;
2324
import org.elasticsearch.index.mapper.MapperBuilderContext;
2425
import org.elasticsearch.legacygeo.builders.CoordinatesBuilder;
2526
import org.elasticsearch.legacygeo.builders.EnvelopeBuilder;
@@ -35,6 +36,7 @@
3536
import org.elasticsearch.legacygeo.parsers.GeoWKTParser;
3637
import org.elasticsearch.legacygeo.parsers.ShapeParser;
3738
import org.elasticsearch.legacygeo.test.RandomShapeGenerator;
39+
import org.elasticsearch.test.index.IndexVersionUtils;
3840
import org.elasticsearch.xcontent.XContentBuilder;
3941
import org.elasticsearch.xcontent.XContentFactory;
4042
import org.elasticsearch.xcontent.XContentParser;
@@ -325,6 +327,15 @@ public void testParseMixedDimensionPolyWithHoleStoredZ() throws IOException {
325327
XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().value(builder.toWKT());
326328
XContentParser parser = createParser(xContentBuilder);
327329
parser.nextToken();
330+
331+
final IndexVersion version = IndexVersionUtils.randomPreviousCompatibleVersion(random(), IndexVersions.V_8_0_0);
332+
final LegacyGeoShapeFieldMapper mapperBuilder = new LegacyGeoShapeFieldMapper.Builder("test", version, false, true).build(
333+
MapperBuilderContext.root(false, false)
334+
);
335+
336+
// test store z disabled
337+
ElasticsearchException e = expectThrows(ElasticsearchException.class, () -> ShapeParser.parse(parser, mapperBuilder));
338+
assertThat(e, hasToString(containsString("unable to add coordinate to CoordinateBuilder: coordinate dimensions do not match")));
328339
}
329340

330341
@UpdateForV9
@@ -342,6 +353,14 @@ public void testParsePolyWithStoredZ() throws IOException {
342353
XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().value(builder.toWKT());
343354
XContentParser parser = createParser(xContentBuilder);
344355
parser.nextToken();
356+
357+
final IndexVersion version = IndexVersionUtils.randomPreviousCompatibleVersion(random(), IndexVersions.V_8_0_0);
358+
final LegacyGeoShapeFieldMapper mapperBuilder = new LegacyGeoShapeFieldMapper.Builder("test", version, false, true).build(
359+
MapperBuilderContext.root(false, false)
360+
);
361+
362+
ShapeBuilder<?, ?, ?> shapeBuilder = ShapeParser.parse(parser, mapperBuilder);
363+
assertEquals(shapeBuilder.numDimensions(), 3);
345364
}
346365

347366
@UpdateForV9
@@ -353,6 +372,16 @@ public void testParseOpenPolygon() throws IOException {
353372
XContentParser parser = createParser(xContentBuilder);
354373
parser.nextToken();
355374

375+
final IndexVersion version = IndexVersionUtils.randomPreviousCompatibleVersion(random(), IndexVersions.V_8_0_0);
376+
final LegacyGeoShapeFieldMapper defaultMapperBuilder = new LegacyGeoShapeFieldMapper.Builder("test", version, false, true).coerce(
377+
false
378+
).build(MapperBuilderContext.root(false, false));
379+
ElasticsearchParseException exception = expectThrows(
380+
ElasticsearchParseException.class,
381+
() -> ShapeParser.parse(parser, defaultMapperBuilder)
382+
);
383+
assertEquals("invalid LinearRing found (coordinates are not closed)", exception.getMessage());
384+
356385
final LegacyGeoShapeFieldMapper coercingMapperBuilder = new LegacyGeoShapeFieldMapper.Builder(
357386
"test",
358387
IndexVersion.current(),

modules/legacy-geo/src/test/java/org/elasticsearch/legacygeo/mapper/LegacyGeoShapeFieldMapperTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.elasticsearch.index.query.SearchExecutionContext;
3636
import org.elasticsearch.legacygeo.test.TestLegacyGeoShapeFieldMapperPlugin;
3737
import org.elasticsearch.plugins.Plugin;
38+
import org.elasticsearch.test.index.IndexVersionUtils;
3839
import org.elasticsearch.xcontent.ToXContent;
3940
import org.elasticsearch.xcontent.XContentBuilder;
4041
import org.junit.AssumptionViolatedException;
@@ -54,6 +55,7 @@
5455
import static org.mockito.Mockito.mock;
5556
import static org.mockito.Mockito.when;
5657

58+
@SuppressWarnings("deprecation")
5759
@UpdateForV9
5860
@AwaitsFix(bugUrl = "this is testing legacy functionality so can likely be removed in 9.0")
5961
public class LegacyGeoShapeFieldMapperTests extends MapperTestCase {
@@ -125,7 +127,7 @@ protected boolean supportsMeta() {
125127

126128
@Override
127129
protected IndexVersion getVersion() {
128-
return IndexVersions.V_8_0_0;
130+
return IndexVersionUtils.randomPreviousCompatibleVersion(random(), IndexVersions.V_8_0_0);
129131
}
130132

131133
public void testLegacySwitches() throws IOException {

modules/legacy-geo/src/test/java/org/elasticsearch/legacygeo/mapper/LegacyGeoShapeFieldTypeTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.index.mapper.MappedFieldType;
1818
import org.elasticsearch.index.mapper.MapperBuilderContext;
1919
import org.elasticsearch.legacygeo.mapper.LegacyGeoShapeFieldMapper.GeoShapeFieldType;
20+
import org.elasticsearch.test.index.IndexVersionUtils;
2021

2122
import java.io.IOException;
2223
import java.util.List;
@@ -40,7 +41,7 @@ public void testSetStrategyName() {
4041
}
4142

4243
public void testFetchSourceValue() throws IOException {
43-
IndexVersion version = IndexVersions.V_8_0_0;
44+
IndexVersion version = IndexVersionUtils.randomPreviousCompatibleVersion(random(), IndexVersions.V_8_0_0);
4445
MappedFieldType mapper = new LegacyGeoShapeFieldMapper.Builder("field", version, false, true).build(
4546
MapperBuilderContext.root(false, false)
4647
).fieldType();

modules/repository-s3/src/internalClusterTest/java/org/elasticsearch/repositories/s3/S3BlobStoreRepositoryTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.elasticsearch.core.SuppressForbidden;
4343
import org.elasticsearch.core.TimeValue;
4444
import org.elasticsearch.index.IndexVersion;
45-
import org.elasticsearch.index.IndexVersions;
4645
import org.elasticsearch.indices.recovery.RecoverySettings;
4746
import org.elasticsearch.plugins.Plugin;
4847
import org.elasticsearch.plugins.PluginsService;
@@ -57,6 +56,7 @@
5756
import org.elasticsearch.rest.RestStatus;
5857
import org.elasticsearch.snapshots.SnapshotId;
5958
import org.elasticsearch.snapshots.SnapshotState;
59+
import org.elasticsearch.snapshots.SnapshotsService;
6060
import org.elasticsearch.snapshots.mockstore.BlobStoreWrapper;
6161
import org.elasticsearch.telemetry.Measurement;
6262
import org.elasticsearch.telemetry.TestTelemetryPlugin;
@@ -426,8 +426,7 @@ public void testEnforcedCooldownPeriod() throws IOException {
426426
)
427427
);
428428
final BytesReference serialized = BytesReference.bytes(
429-
// TODO lucene 10 upgrade, we can probably remove the IndexVersions here once we delete all V7 versions
430-
modifiedRepositoryData.snapshotsToXContent(XContentFactory.jsonBuilder(), IndexVersions.V_8_0_0)
429+
modifiedRepositoryData.snapshotsToXContent(XContentFactory.jsonBuilder(), SnapshotsService.OLD_SNAPSHOT_FORMAT)
431430
);
432431
if (randomBoolean()) {
433432
repository.blobStore()

modules/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3Repository.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.elasticsearch.common.util.concurrent.ListenableFuture;
3232
import org.elasticsearch.core.TimeValue;
3333
import org.elasticsearch.index.IndexVersion;
34+
import org.elasticsearch.index.IndexVersions;
3435
import org.elasticsearch.indices.recovery.RecoverySettings;
3536
import org.elasticsearch.monitor.jvm.JvmInfo;
3637
import org.elasticsearch.repositories.FinalizeSnapshotContext;
@@ -155,12 +156,13 @@ class S3Repository extends MeteredBlobStoreRepository {
155156

156157
/**
157158
* Artificial delay to introduce after a snapshot finalization or delete has finished so long as the repository is still using the
158-
* backwards compatible snapshot format from before V_7_6_0. This delay is necessary so that the eventually consistent
159-
* nature of AWS S3 does not randomly result in repository corruption when doing repository operations in rapid succession on a
160-
* repository in the old metadata format.
159+
* backwards compatible snapshot format from before
160+
* {@link org.elasticsearch.snapshots.SnapshotsService#SHARD_GEN_IN_REPO_DATA_VERSION} ({@link IndexVersions#V_7_6_0}).
161+
* This delay is necessary so that the eventually consistent nature of AWS S3 does not randomly result in repository corruption when
162+
* doing repository operations in rapid succession on a repository in the old metadata format.
161163
* This setting should not be adjusted in production when working with an AWS S3 backed repository. Doing so risks the repository
162164
* becoming silently corrupted. To get rid of this waiting period, either create a new S3 repository or remove all snapshots older than
163-
* V_7_6_0 from the repository which will trigger an upgrade of the repository metadata to the new
165+
* {@link IndexVersions#V_7_6_0} from the repository which will trigger an upgrade of the repository metadata to the new
164166
* format and disable the cooldown period.
165167
*/
166168
static final Setting<TimeValue> COOLDOWN_PERIOD = Setting.timeSetting(
@@ -369,12 +371,14 @@ public void onFailure(Exception e) {
369371

370372
private void logCooldownInfo() {
371373
logger.info(
372-
"Sleeping for [{}] after modifying repository [{}] because it contains snapshots older than version [\"7060099\"]"
374+
"Sleeping for [{}] after modifying repository [{}] because it contains snapshots older than version [{}]"
373375
+ " and therefore is using a backwards compatible metadata format that requires this cooldown period to avoid "
374376
+ "repository corruption. To get rid of this message and move to the new repository metadata format, either remove "
375-
+ "all snapshots older than version [\"7060099\"] from the repository or create a new repository at an empty location.",
377+
+ "all snapshots older than version [{}] from the repository or create a new repository at an empty location.",
376378
coolDown,
377-
metadata.name()
379+
metadata.name(),
380+
SnapshotsService.SHARD_GEN_IN_REPO_DATA_VERSION,
381+
SnapshotsService.SHARD_GEN_IN_REPO_DATA_VERSION
378382
);
379383
}
380384

qa/repository-multi-version/src/test/java/org/elasticsearch/upgrades/MultiVersionRepositoryAccessIT.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.common.Strings;
1818
import org.elasticsearch.common.settings.Settings;
1919
import org.elasticsearch.index.IndexVersion;
20+
import org.elasticsearch.index.IndexVersions;
2021
import org.elasticsearch.snapshots.SnapshotsService;
2122
import org.elasticsearch.test.rest.ESRestTestCase;
2223
import org.elasticsearch.test.rest.ObjectPath;
@@ -181,7 +182,9 @@ public void testUpgradeMovesRepoToNewMetaVersion() throws IOException {
181182
// 7.12.0+ will try to load RepositoryData during repo creation if verify is true, which is impossible in case of version
182183
// incompatibility in the downgrade test step. We verify that it is impossible here and then create the repo using verify=false
183184
// to check behavior on other operations below.
184-
final boolean verify = TEST_STEP != TestStep.STEP3_OLD_CLUSTER || SnapshotsService.includesUUIDs(minNodeVersion);
185+
final boolean verify = TEST_STEP != TestStep.STEP3_OLD_CLUSTER
186+
|| SnapshotsService.includesUUIDs(minNodeVersion)
187+
|| minNodeVersion.before(IndexVersions.V_7_12_0);
185188
if (verify == false) {
186189
expectThrowsAnyOf(EXPECTED_BWC_EXCEPTIONS, () -> createRepository(repoName, false, true));
187190
}

0 commit comments

Comments
 (0)