Skip to content

Commit f6b3a37

Browse files
authored
Skip archive settings on upgrade (elastic#139297)
We are removing archiving and validation of index settings during startup. We are doing so because, the work is redundant, as during a rolling upgrade, the Master node will send the updated metadata. In the case of a full cluster restart, the index settings won't be archived, but the cluster will still be healthy; validation is still present when opening the index.
1 parent 708b12d commit f6b3a37

File tree

6 files changed

+59
-73
lines changed

6 files changed

+59
-73
lines changed

server/src/internalClusterTest/java/org/elasticsearch/gateway/GatewayIndexStateIT.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,6 @@ public void testRecoverBrokenIndexMetadata() throws Exception {
389389
Settings.builder()
390390
.put(metadata.getSettings())
391391
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersions.MINIMUM_COMPATIBLE)
392-
// this is invalid but should be archived
393-
.put("index.similarity.BM25.type", "boolean")
394392
// this one is not validated ahead of time and breaks allocation
395393
.put("index.analysis.filter.myCollator.type", "icu_collation")
396394
);
@@ -415,10 +413,6 @@ public void testRecoverBrokenIndexMetadata() throws Exception {
415413

416414
state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState();
417415
assertEquals(IndexMetadata.State.CLOSE, state.getMetadata().getProject().index(metadata.getIndex()).getState());
418-
assertEquals(
419-
"boolean",
420-
state.getMetadata().getProject().index(metadata.getIndex()).getSettings().get("archived.index.similarity.BM25.type")
421-
);
422416
// try to open it with the broken setting - fail again!
423417
ElasticsearchException ex = expectThrows(ElasticsearchException.class, indicesAdmin().prepareOpen("test"));
424418
assertEquals(ex.getMessage(), "Failed to verify index " + metadata.getIndex());

server/src/internalClusterTest/java/org/elasticsearch/index/IndexSettingsIT.java

Lines changed: 0 additions & 60 deletions
This file was deleted.

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

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,33 @@ public IndexMetadataVerifier(
8484
}
8585

8686
/**
87-
* Checks that the index can be upgraded to the current version of the master node.
87+
* Checks that the index can be upgraded to the current version as provided.
8888
*
8989
* <p>
9090
* If the index does not need upgrade it returns the index metadata unchanged, otherwise it returns a modified index metadata. If index
91-
* cannot be updated the method throws an exception.
91+
* cannot be updated the method throws an exception. Also archives or deletes unsupported settings.
9292
*/
9393
public IndexMetadata verifyIndexMetadata(
9494
IndexMetadata indexMetadata,
9595
IndexVersion minimumIndexCompatibilityVersion,
9696
IndexVersion minimumReadOnlyIndexCompatibilityVersion
97+
) {
98+
return verifyIndexMetadata(indexMetadata, minimumIndexCompatibilityVersion, minimumReadOnlyIndexCompatibilityVersion, true);
99+
}
100+
101+
/**
102+
* Checks that the index can be upgraded to the current version as provided.
103+
*
104+
* <p>
105+
* If the index does not need upgrade it returns the index metadata unchanged, otherwise it returns a modified index metadata. If index
106+
* cannot be updated the method throws an exception. If {@code archiveOrDeleteBrokenIndexSettings} is {@code true},
107+
* unsupported settings will be either archived or deleted.
108+
*/
109+
public IndexMetadata verifyIndexMetadata(
110+
IndexMetadata indexMetadata,
111+
IndexVersion minimumIndexCompatibilityVersion,
112+
IndexVersion minimumReadOnlyIndexCompatibilityVersion,
113+
boolean archiveOrDeleteBrokenIndexSettings
97114
) {
98115
checkSupportedVersion(indexMetadata, minimumIndexCompatibilityVersion, minimumReadOnlyIndexCompatibilityVersion);
99116

@@ -103,10 +120,12 @@ public IndexMetadata verifyIndexMetadata(
103120
// invalid settings, since they are now removed the FilterAllocationDecider treats them as
104121
// regular attribute filters, and shards cannot be allocated.
105122
newMetadata = removeTierFiltering(newMetadata);
106-
// Next we have to run this otherwise if we try to create IndexSettings
107-
// with broken settings it would fail in checkMappingsCompatibility
108-
newMetadata = archiveOrDeleteBrokenIndexSettings(newMetadata);
109-
checkMappingsCompatibility(newMetadata);
123+
if (archiveOrDeleteBrokenIndexSettings) {
124+
// Next we have to run this otherwise if we try to create IndexSettings
125+
// with broken settings it would fail in checkMappingsCompatibility
126+
newMetadata = archiveOrDeleteBrokenIndexSettings(newMetadata);
127+
checkMappingsCompatibility(newMetadata);
128+
}
110129
return newMetadata;
111130
}
112131

@@ -315,6 +334,7 @@ IndexMetadata archiveOrDeleteBrokenIndexSettings(IndexMetadata indexMetadata) {
315334
final Settings newSettings;
316335

317336
if (indexMetadata.isSystem()) {
337+
// TODO This is also skipped if the upgrade/archive step is skipped. To be discussed
318338
newSettings = indexScopedSettings.deleteUnknownOrInvalidSettings(
319339
settings,
320340
e -> logger.warn(

server/src/main/java/org/elasticsearch/gateway/GatewayMetaState.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ private static ProjectMetadata upgradeProjectMetadata(
318318
IndexMetadata newMetadata = indexMetadataVerifier.verifyIndexMetadata(
319319
indexMetadata,
320320
IndexVersions.MINIMUM_COMPATIBLE,
321-
IndexVersions.MINIMUM_READONLY_COMPATIBLE
321+
IndexVersions.MINIMUM_READONLY_COMPATIBLE,
322+
false
322323
);
323324
changed |= indexMetadata != newMetadata;
324325
upgradedMetadata.put(newMetadata, false);

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,27 @@ public void testReadOnlyVersionCompatibility() {
294294
}
295295
}
296296

297+
public void testSkippingArchiveOrDeletePreservesBrokenSettings() {
298+
IndexMetadataVerifier service = getIndexMetadataVerifier();
299+
IndexMetadata src = newIndexMeta(
300+
"foo",
301+
Settings.builder()
302+
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
303+
.put("index.refresh_interval", "-200")
304+
.build()
305+
);
306+
307+
IndexMetadata result = service.verifyIndexMetadata(
308+
src,
309+
IndexVersions.MINIMUM_COMPATIBLE,
310+
IndexVersions.MINIMUM_READONLY_COMPATIBLE,
311+
false
312+
);
313+
314+
assertEquals("-200", result.getSettings().get("index.refresh_interval"));
315+
assertNull(result.getSettings().get("archived.index.refresh_interval"));
316+
}
317+
297318
private IndexMetadataVerifier getIndexMetadataVerifier() {
298319
return new IndexMetadataVerifier(
299320
Settings.EMPTY,

server/src/test/java/org/elasticsearch/gateway/GatewayMetaStateTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,16 @@ public IndexMetadata verifyIndexMetadata(
302302
) {
303303
return upgrade ? IndexMetadata.builder(indexMetadata).build() : indexMetadata;
304304
}
305+
306+
@Override
307+
public IndexMetadata verifyIndexMetadata(
308+
IndexMetadata indexMetadata,
309+
IndexVersion minimumIndexCompatibilityVersion,
310+
IndexVersion minimumReadOnlyIndexCompatibilityVersion,
311+
boolean archiveOrDeleteBrokenIndexSettings
312+
) {
313+
return upgrade ? IndexMetadata.builder(indexMetadata).build() : indexMetadata;
314+
}
305315
}
306316

307317
private static class CustomMetadata1 extends TestClusterCustomMetadata {

0 commit comments

Comments
 (0)