-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…#71129) This commit converts the index metadata of searchable snapshot indices using the `shared_cache` storage type to: - Remove all the `index.routing.allocation.(include|exclude|require)._tier` settings - Sets `index.routing.allocation.include._tier_preference` to `data_frozen` automatically when the index metadata is read This is in preperation to enforcing that the `_tier_preference` setting is always set to `data_frozen` for shared cache SBIs. Relates to #70846, #71013, #70786, #70141
- Loading branch information
Showing
3 changed files
with
128 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
...n/core/src/test/java/org/elasticsearch/cluster/metadata/IndexMetadataConversionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.cluster.metadata; | ||
|
||
import org.elasticsearch.common.UUIDs; | ||
import org.elasticsearch.common.settings.IndexScopedSettings; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.index.IndexModule; | ||
import org.elasticsearch.index.mapper.MapperRegistry; | ||
import org.elasticsearch.plugins.MapperPlugin; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshotsConstants; | ||
|
||
import java.util.Collections; | ||
|
||
import static org.elasticsearch.test.VersionUtils.randomIndexCompatibleVersion; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class IndexMetadataConversionTests extends ESTestCase { | ||
|
||
public void testConvertSearchableSnapshotSettings() { | ||
IndexMetadataVerifier service = getIndexMetadataVerifier(); | ||
IndexMetadata src = newIndexMeta("foo", Settings.EMPTY); | ||
IndexMetadata indexMetadata = service.convertSharedCacheTierPreference(src); | ||
assertSame(indexMetadata, src); | ||
|
||
// A full_copy searchable snapshot (settings should be untouched) | ||
src = newIndexMeta("foo", Settings.builder() | ||
.put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), "snapshot") | ||
.put(SearchableSnapshotsConstants.SNAPSHOT_PARTIAL_SETTING.getKey(), false) | ||
.put("index.routing.allocation.include._tier", "data_hot") | ||
.put("index.routing.allocation.exclude._tier", "data_warm") | ||
.put("index.routing.allocation.require._tier", "data_hot") | ||
.put("index.routing.allocation.include._tier_preference", "data_cold") | ||
.build()); | ||
indexMetadata = service.convertSharedCacheTierPreference(src); | ||
assertSame(indexMetadata, src); | ||
|
||
// A shared_cache searchable snapshot with valid settings (metadata should be untouched) | ||
src = newIndexMeta("foo", Settings.builder() | ||
.put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), "snapshot") | ||
.put(SearchableSnapshotsConstants.SNAPSHOT_PARTIAL_SETTING.getKey(), false) | ||
.put("index.routing.allocation.include._tier_preference", "data_frozen") | ||
.build()); | ||
indexMetadata = service.convertSharedCacheTierPreference(src); | ||
assertSame(indexMetadata, src); | ||
|
||
// A shared_cache searchable snapshot (should have its settings converted) | ||
src = newIndexMeta("foo", Settings.builder() | ||
.put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), "snapshot") | ||
.put(SearchableSnapshotsConstants.SNAPSHOT_PARTIAL_SETTING.getKey(), true) | ||
.put("index.routing.allocation.include._tier", "data_hot") | ||
.put("index.routing.allocation.exclude._tier", "data_warm") | ||
.put("index.routing.allocation.require._tier", "data_hot") | ||
.put("index.routing.allocation.include._tier_preference", "data_frozen,data_cold") | ||
.build()); | ||
indexMetadata = service.convertSharedCacheTierPreference(src); | ||
assertNotSame(indexMetadata, src); | ||
Settings newSettings = indexMetadata.getSettings(); | ||
assertNull(newSettings.get("index.routing.allocation.include._tier")); | ||
assertNull(newSettings.get("index.routing.allocation.exclude._tier")); | ||
assertNull(newSettings.get("index.routing.allocation.require._tier")); | ||
assertThat(newSettings.get("index.routing.allocation.include._tier_preference"), equalTo("data_frozen")); | ||
} | ||
|
||
private IndexMetadataVerifier getIndexMetadataVerifier() { | ||
return new IndexMetadataVerifier( | ||
Settings.EMPTY, | ||
xContentRegistry(), | ||
new MapperRegistry(Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), | ||
MapperPlugin.NOOP_FIELD_FILTER), IndexScopedSettings.DEFAULT_SCOPED_SETTINGS, | ||
null | ||
); | ||
} | ||
|
||
public static IndexMetadata newIndexMeta(String name, Settings indexSettings) { | ||
final Settings settings = Settings.builder() | ||
.put(IndexMetadata.SETTING_VERSION_CREATED, randomIndexCompatibleVersion(random())) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, between(0, 5)) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, between(1, 5)) | ||
.put(IndexMetadata.SETTING_CREATION_DATE, randomNonNegativeLong()) | ||
.put(IndexMetadata.SETTING_INDEX_UUID, UUIDs.randomBase64UUID(random())) | ||
.put(indexSettings) | ||
.build(); | ||
final IndexMetadata.Builder indexMetadataBuilder = IndexMetadata.builder(name).settings(settings); | ||
if (randomBoolean()) { | ||
indexMetadataBuilder.state(IndexMetadata.State.CLOSE); | ||
} | ||
return indexMetadataBuilder.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters