Skip to content

Commit 65a2342

Browse files
authored
Legacy index version to target indices created before N-2 (#118443)
Legacy index versions can only be read via the archive indices functionality. The supported versions are currently 5.x and 6.x. For 9.0, we are not going to add support for indices created in 7.x as archive indices. Rather we will allow reading from N - 2 directly from Lucene, without relying on archive indices. IndexVersion#isLegacyIndexVersion is tied to the archive indices functionality and identifies index versions that can only be present in the cluster as archive. This commit aligns isLegacyIndexVersion to only match versions before N - 2.
1 parent b460f08 commit 65a2342

File tree

6 files changed

+17
-14
lines changed

6 files changed

+17
-14
lines changed

server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,10 +1116,10 @@ public IndexVersion getCreationVersion() {
11161116

11171117
/**
11181118
* Return the {@link IndexVersion} that this index provides compatibility for.
1119-
* This is typically compared to the {@link IndexVersions#MINIMUM_COMPATIBLE} to figure out whether the index can be handled
1120-
* by the cluster.
1121-
* By default, this is equal to the {@link #getCreationVersion()}, but can also be a newer version if the index has been imported as
1122-
* a legacy index from an older snapshot, and its metadata has been converted to be handled by newer version nodes.
1119+
* This is typically compared to the {@link IndexVersions#MINIMUM_COMPATIBLE} or {@link IndexVersions#MINIMUM_READONLY_COMPATIBLE}
1120+
* to figure out whether the index can be handled by the cluster.
1121+
* By default, this is equal to the {@link #getCreationVersion()}, but can also be a newer version if the index has been created by
1122+
* a legacy version, and imported archive, in which case its metadata has been converted to be handled by newer version nodes.
11231123
*/
11241124
public IndexVersion getCompatibilityVersion() {
11251125
return indexCompatibilityVersion;

server/src/main/java/org/elasticsearch/env/NodeEnvironment.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,7 @@ static void checkForIndexCompatibility(Logger logger, DataPath... dataPaths) thr
524524

525525
logger.info("oldest index version recorded in NodeMetadata {}", metadata.oldestIndexVersion());
526526

527-
if (metadata.oldestIndexVersion().isLegacyIndexVersion()) {
528-
527+
if (metadata.oldestIndexVersion().before(IndexVersions.MINIMUM_COMPATIBLE)) {
529528
String bestDowngradeVersion = getBestDowngradeVersion(metadata.previousNodeVersion().toString());
530529
throw new IllegalStateException(
531530
"Cannot start this node because it holds metadata for indices with version ["

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,13 @@ public static IndexVersion current() {
123123
return CurrentHolder.CURRENT;
124124
}
125125

126+
/**
127+
* Returns whether this index version is supported by this node version out-of-the-box.
128+
* This is used to distinguish between ordinary indices and archive indices that may be
129+
* imported into the cluster in read-only mode, and with limited functionality.
130+
*/
126131
public boolean isLegacyIndexVersion() {
127-
return before(IndexVersions.MINIMUM_COMPATIBLE);
132+
return before(IndexVersions.MINIMUM_READONLY_COMPATIBLE);
128133
}
129134

130135
public static IndexVersion getMinimumCompatibleIndexVersion(int versionId) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ private static Version parseUnchecked(String version) {
192192
*/
193193

194194
public static final IndexVersion MINIMUM_COMPATIBLE = V_8_0_0;
195+
public static final IndexVersion MINIMUM_READONLY_COMPATIBLE = V_7_0_0;
195196

196197
static final NavigableMap<Integer, IndexVersion> VERSION_IDS = getAllVersionIds(IndexVersions.class);
197198
static final IndexVersion LATEST_DEFINED;
@@ -207,7 +208,7 @@ static NavigableMap<Integer, IndexVersion> getAllVersionIds(Class<?> cls) {
207208
Map<Integer, String> versionIdFields = new HashMap<>();
208209
NavigableMap<Integer, IndexVersion> builder = new TreeMap<>();
209210

210-
Set<String> ignore = Set.of("ZERO", "MINIMUM_COMPATIBLE");
211+
Set<String> ignore = Set.of("ZERO", "MINIMUM_COMPATIBLE", "MINIMUM_READONLY_COMPATIBLE");
211212

212213
for (Field declaredField : cls.getFields()) {
213214
if (declaredField.getType().equals(IndexVersion.class)) {

server/src/main/java/org/elasticsearch/repositories/RepositoriesModule.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ public RepositoriesModule(
102102
}
103103
if (preRestoreChecks.isEmpty()) {
104104
preRestoreChecks.add((snapshot, version) -> {
105-
if (version.isLegacyIndexVersion()) {
105+
// pre-restore checks will be run against the version in which the snapshot was created as well as
106+
// the version in which the restored index was created
107+
if (version.before(IndexVersions.MINIMUM_COMPATIBLE)) {
106108
throw new SnapshotRestoreException(
107109
snapshot,
108110
"the snapshot was created with Elasticsearch version ["

x-pack/plugin/old-lucene-versions/src/internalClusterTest/java/org/elasticsearch/xpack/lucene/bwc/AbstractArchiveTestCase.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,7 @@ public IndexMetadata getSnapshotIndexMetaData(RepositoryData repositoryData, Sna
9494
.put(
9595
IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(),
9696
metadata.settings()
97-
.getAsVersionId(
98-
"version",
99-
IndexVersion::fromId,
100-
IndexVersion.fromId(randomFrom(5000099, 6000099, 7000099))
101-
)
97+
.getAsVersionId("version", IndexVersion::fromId, IndexVersion.fromId(randomFrom(5000099, 6000099)))
10298
)
10399
)
104100
.build();

0 commit comments

Comments
 (0)