Skip to content

Commit dd98bcf

Browse files
committed
Fail node containing ancient closed index
Today we fail the node at startup if it contains an index that is too old to be compatible with the current version, unless that index is closed. If the index is closed then the node will start up and this puts us into a bad state: the index cannot be opened and must be reindexed using an earlier version, but we offer no way to get that index into a node running an earlier version so that it can be reindexed. Downgrading the node in-place is decidedly unsupported and cannot be expected to work since the node already started up and upgraded the rest of its metadata. Since elastic#41731 we actively reject downgrades to versions ≥ v7.2.0 too. This commit prevents the node from starting in the presence of any too-old indices (closed or not). In particular, it does not write any upgraded metadata in this situation, increasing the chances an in-place downgrade might be successful. We still actively reject the downgrade using elastic#41731, because we wrote the node metadata file before checking the index metadata, but at least there is a way to override this check. Relates elastic#21830, elastic#44230
1 parent 873e9f9 commit dd98bcf

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,15 @@ boolean isUpgraded(IndexMetaData indexMetaData) {
115115
}
116116

117117
/**
118-
* Elasticsearch v6.0 no longer supports indices created pre v5.0. All indices
119-
* that were created before Elasticsearch v5.0 should be re-indexed in Elasticsearch 5.x
120-
* before they can be opened by this version of elasticsearch.
118+
* Elasticsearch does not support indices created before the previous major version. They must be reindexed using an earlier version
119+
* before they can be opened here.
121120
*/
122121
private void checkSupportedVersion(IndexMetaData indexMetaData, Version minimumIndexCompatibilityVersion) {
123-
if (indexMetaData.getState() == IndexMetaData.State.OPEN && isSupportedVersion(indexMetaData,
124-
minimumIndexCompatibilityVersion) == false) {
125-
throw new IllegalStateException("The index [" + indexMetaData.getIndex() + "] was created with version ["
122+
if (isSupportedVersion(indexMetaData, minimumIndexCompatibilityVersion) == false) {
123+
throw new IllegalStateException("The index " + indexMetaData.getIndex() + " was created with version ["
126124
+ indexMetaData.getCreationVersion() + "] but the minimum compatible version is ["
127-
128-
+ minimumIndexCompatibilityVersion + "]. It should be re-indexed in Elasticsearch " + minimumIndexCompatibilityVersion.major
129-
+ ".x before upgrading to " + Version.CURRENT + ".");
125+
+ minimumIndexCompatibilityVersion + "]. It should be re-indexed in Elasticsearch "
126+
+ minimumIndexCompatibilityVersion.major + ".x before upgrading to " + Version.CURRENT + ".");
130127
}
131128
}
132129

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.elasticsearch.cluster.metadata;
2020

2121
import org.elasticsearch.Version;
22+
import org.elasticsearch.common.UUIDs;
2223
import org.elasticsearch.common.settings.IndexScopedSettings;
2324
import org.elasticsearch.common.settings.Settings;
2425
import org.elasticsearch.indices.mapper.MapperRegistry;
@@ -106,9 +107,9 @@ public void testFailUpgrade() {
106107
.build());
107108
String message = expectThrows(IllegalStateException.class, () -> service.upgradeIndexMetaData(metaData,
108109
Version.CURRENT.minimumIndexCompatibilityVersion())).getMessage();
109-
assertEquals(message, "The index [[foo/BOOM]] was created with version [" + indexCreated + "] " +
110+
assertThat(message, equalTo("The index [foo/" + metaData.getIndexUUID() + "] was created with version [" + indexCreated + "] " +
110111
"but the minimum compatible version is [" + minCompat + "]." +
111-
" It should be re-indexed in Elasticsearch " + minCompat.major + ".x before upgrading to " + Version.CURRENT.toString() + ".");
112+
" It should be re-indexed in Elasticsearch " + minCompat.major + ".x before upgrading to " + Version.CURRENT.toString() + "."));
112113

113114
indexCreated = VersionUtils.randomVersionBetween(random(), minCompat, Version.CURRENT);
114115
indexUpgraded = VersionUtils.randomVersionBetween(random(), indexCreated, Version.CURRENT);
@@ -159,16 +160,25 @@ private MetaDataIndexUpgradeService getMetaDataIndexUpgradeService() {
159160
Collections.emptyList());
160161
}
161162

162-
public static IndexMetaData newIndexMeta(String name, Settings indexSettings) {
163-
Settings build = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
164-
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)
165-
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
166-
.put(IndexMetaData.SETTING_CREATION_DATE, 1)
167-
.put(IndexMetaData.SETTING_INDEX_UUID, "BOOM")
168-
.put(IndexMetaData.SETTING_VERSION_UPGRADED, Version.CURRENT.minimumIndexCompatibilityVersion())
163+
public IndexMetaData newIndexMeta(String name, Settings indexSettings) {
164+
final Version createdVersion = VersionUtils.randomVersionBetween(random(),
165+
Version.CURRENT.minimumIndexCompatibilityVersion(), VersionUtils.getPreviousVersion());
166+
final Version upgradedVersion = VersionUtils.randomVersionBetween(random(), createdVersion, VersionUtils.getPreviousVersion());
167+
168+
final Settings settings = Settings.builder()
169+
.put(IndexMetaData.SETTING_VERSION_CREATED, createdVersion)
170+
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, between(0, 5))
171+
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, between(1, 5))
172+
.put(IndexMetaData.SETTING_CREATION_DATE, randomNonNegativeLong())
173+
.put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID(random()))
174+
.put(IndexMetaData.SETTING_VERSION_UPGRADED, upgradedVersion)
169175
.put(indexSettings)
170176
.build();
171-
return IndexMetaData.builder(name).settings(build).build();
177+
final IndexMetaData.Builder indexMetaDataBuilder = IndexMetaData.builder(name).settings(settings);
178+
if (randomBoolean()) {
179+
indexMetaDataBuilder.state(IndexMetaData.State.CLOSE);
180+
}
181+
return indexMetaDataBuilder.build();
172182
}
173183

174184
}

0 commit comments

Comments
 (0)