Skip to content

Commit

Permalink
Move text references to index created version to IndexVersion (#98727)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecoop authored Aug 23, 2023
1 parent e58f6c0 commit b67a9e1
Show file tree
Hide file tree
Showing 27 changed files with 73 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.elasticsearch.TransportVersion;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterModule;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.analysis.AnalyzerScope;
import org.elasticsearch.index.analysis.IndexAnalyzers;
import org.elasticsearch.index.analysis.LowercaseNormalizer;
Expand Down Expand Up @@ -44,7 +44,7 @@ public static MapperService create(String mappings) {
Settings settings = Settings.builder()
.put("index.number_of_replicas", 0)
.put("index.number_of_shards", 1)
.put("index.version.created", Version.CURRENT)
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
.put("index.mapping.total_fields.limit", 10000)
.build();
IndexMetadata meta = IndexMetadata.builder("index").settings(settings).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package org.elasticsearch.benchmark.routing.allocation;

import org.elasticsearch.TransportVersion;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
Expand All @@ -19,6 +18,7 @@
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexVersion;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
Expand Down Expand Up @@ -128,7 +128,7 @@ public void setUp() throws Exception {
for (int i = 1; i <= numIndices; i++) {
mb.put(
IndexMetadata.builder("test_" + i)
.settings(Settings.builder().put("index.version.created", Version.CURRENT))
.settings(Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current()))
.numberOfShards(numShards)
.numberOfReplicas(numReplicas)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

package org.elasticsearch.benchmark.routing.allocation;

import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetadata;
Expand All @@ -28,6 +27,7 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.health.HealthIndicatorResult;
import org.elasticsearch.health.node.HealthInfo;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.indices.SystemIndices;
import org.elasticsearch.tasks.TaskManager;
Expand Down Expand Up @@ -121,7 +121,7 @@ public void setUp() throws Exception {
IndexMetadata indexMetadata = IndexMetadata.builder("test_" + i)
.settings(
Settings.builder()
.put("index.version.created", Version.CURRENT)
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
.put(DataTier.TIER_PREFERENCE_SETTING.getKey(), "data_warm")
.put(INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + "data", "warm")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.apache.lucene.store.ByteBuffersDirectory;
import org.apache.lucene.store.Directory;
import org.elasticsearch.TransportVersion;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterModule;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.bytes.BytesArray;
Expand All @@ -28,6 +27,7 @@
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.core.IOUtils;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
import org.elasticsearch.index.mapper.MapperRegistry;
import org.elasticsearch.index.mapper.MapperService;
Expand Down Expand Up @@ -163,7 +163,7 @@ protected final MapperService createMapperService(String mappings) {
Settings settings = Settings.builder()
.put("index.number_of_replicas", 0)
.put("index.number_of_shards", 1)
.put("index.version.created", Version.CURRENT)
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
.build();
IndexMetadata meta = IndexMetadata.builder("index").settings(settings).build();
IndexSettings indexSettings = new IndexSettings(meta, settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void createSystemIndexForDescriptor(SystemIndexDescriptor descriptor) thr
// managed
createRequest.setSettings(
Settings.builder()
.put("index.version.created", Version.CURRENT)
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
.put(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0)
.build()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void testMigrateInternalManagedSystemIndex() throws Exception {
createRequest.setWaitForActiveShards(ActiveShardCount.ALL);
createRequest.setSettings(
Settings.builder()
.put("index.version.created", NEEDS_UPGRADE_VERSION)
.put(IndexMetadata.SETTING_VERSION_CREATED, NEEDS_UPGRADE_INDEX_VERSION)
.put(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0)
.put("index.hidden", true) // So we don't get a warning
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

package org.elasticsearch.example;

import org.elasticsearch.Version;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.cluster.metadata.IndexAbstraction;
import org.elasticsearch.cluster.metadata.IndexAbstraction.ConcreteIndex;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.transport.TransportRequest;
import org.elasticsearch.xpack.core.security.authc.Authentication;
Expand Down Expand Up @@ -118,7 +118,7 @@ public void testAuthorizeIndexAction() {
CustomAuthorizationEngine engine = new CustomAuthorizationEngine();
Map<String, IndexAbstraction> indicesMap = new HashMap<>();
indicesMap.put("index", new ConcreteIndex(IndexMetadata.builder("index")
.settings(Settings.builder().put("index.version.created", Version.CURRENT))
.settings(Settings.builder().put("index.version.created", IndexVersion.current()))
.numberOfShards(1)
.numberOfReplicas(0)
.build(), null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static java.util.stream.Collectors.toList;
import static org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.SYSTEM_INDEX_ENFORCEMENT_INDEX_VERSION;
import static org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.SYSTEM_INDEX_ENFORCEMENT_VERSION;
import static org.elasticsearch.cluster.routing.UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING;
import static org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider.SETTING_ALLOCATION_MAX_RETRY;
Expand Down Expand Up @@ -1730,8 +1731,8 @@ public void testSystemIndexMetadataIsUpgraded() throws Exception {
// If .tasks was created in a 7.x version, it should have an alias on it that we need to make sure got upgraded properly.
final String tasksCreatedVersionString = tasksIndex.get("settings.index.version.created");
assertThat(tasksCreatedVersionString, notNullValue());
final Version tasksCreatedVersion = Version.fromId(Integer.parseInt(tasksCreatedVersionString));
if (tasksCreatedVersion.before(SYSTEM_INDEX_ENFORCEMENT_VERSION)) {
final IndexVersion tasksCreatedVersion = IndexVersion.fromId(Integer.parseInt(tasksCreatedVersionString));
if (tasksCreatedVersion.before(SYSTEM_INDEX_ENFORCEMENT_INDEX_VERSION)) {
// Verify that the alias survived the upgrade
Request getAliasRequest = new Request("GET", "/_alias/test-system-alias");
getAliasRequest.setOptions(expectVersionSpecificWarnings(v -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.core.Booleans;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.test.rest.ObjectPath;
import org.hamcrest.Matchers;

Expand Down Expand Up @@ -427,8 +428,8 @@ public void testRecoveryClosedIndex() throws Exception {
closeIndex(indexName);
}

final Version indexVersionCreated = indexVersionCreated(indexName);
if (indexVersionCreated.onOrAfter(Version.V_7_2_0)) {
final IndexVersion indexVersionCreated = indexVersionCreated(indexName);
if (indexVersionCreated.onOrAfter(IndexVersion.V_7_2_0)) {
// index was created on a version that supports the replication of closed indices,
// so we expect the index to be closed and replicated
ensureGreen(indexName);
Expand Down Expand Up @@ -498,7 +499,7 @@ public void testClosedIndexNoopRecovery() throws Exception {
closeIndex(indexName);
}

if (indexVersionCreated(indexName).onOrAfter(Version.V_7_2_0)) {
if (indexVersionCreated(indexName).onOrAfter(IndexVersion.V_7_2_0)) {
// index was created on a version that supports the replication of closed indices, so we expect it to be closed and replicated
assertTrue(minimumNodeVersion().onOrAfter(Version.V_7_2_0));
ensureGreen(indexName);
Expand All @@ -515,13 +516,13 @@ public void testClosedIndexNoopRecovery() throws Exception {
/**
* Returns the version in which the given index has been created
*/
private static Version indexVersionCreated(final String indexName) throws IOException {
private static IndexVersion indexVersionCreated(final String indexName) throws IOException {
final Request request = new Request("GET", "/" + indexName + "/_settings");
final String versionCreatedSetting = indexName + ".settings.index.version.created";
request.addParameter("filter_path", versionCreatedSetting);

final Response response = client().performRequest(request);
return Version.fromId(Integer.parseInt(ObjectPath.createFromResponse(response).evaluate(versionCreatedSetting)));
return IndexVersion.fromId(Integer.parseInt(ObjectPath.createFromResponse(response).evaluate(versionCreatedSetting)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@

package org.elasticsearch.upgrades;

import org.elasticsearch.Version;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.test.XContentTestUtils.JsonMapView;

import java.util.Map;

import static org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.SYSTEM_INDEX_ENFORCEMENT_INDEX_VERSION;
import static org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.SYSTEM_INDEX_ENFORCEMENT_VERSION;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -116,8 +117,8 @@ public void testSystemIndicesUpgrades() throws Exception {
// If .tasks was created in a 7.x version, it should have an alias on it that we need to make sure got upgraded properly.
final String tasksCreatedVersionString = tasksIndex.get("settings.index.version.created");
assertThat(tasksCreatedVersionString, notNullValue());
final Version tasksCreatedVersion = Version.fromId(Integer.parseInt(tasksCreatedVersionString));
if (tasksCreatedVersion.before(SYSTEM_INDEX_ENFORCEMENT_VERSION)) {
final IndexVersion tasksCreatedVersion = IndexVersion.fromId(Integer.parseInt(tasksCreatedVersionString));
if (tasksCreatedVersion.before(SYSTEM_INDEX_ENFORCEMENT_INDEX_VERSION)) {
// Verify that the alias survived the upgrade
Request getAliasRequest = new Request("GET", "/_alias/test-system-alias");
getAliasRequest.setOptions(expectVersionSpecificWarnings(v -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ static SystemIndexMigrationInfo build(
if (descriptor.isAutomaticallyManaged()) {
Settings.Builder settingsBuilder = Settings.builder();
settingsBuilder.put(descriptor.getSettings());
settingsBuilder.remove("index.version.created"); // Simplifies testing, should never impact real uses.
settingsBuilder.remove(IndexMetadata.SETTING_VERSION_CREATED); // Simplifies testing, should never impact real uses.
settings = settingsBuilder.build();

mapping = descriptor.getMappings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public void testProhibitCustomRoutingOnDataStream() throws Exception {

public void testOnlySystem() {
SortedMap<String, IndexAbstraction> indicesLookup = new TreeMap<>();
Settings settings = Settings.builder().put("index.version.created", Version.CURRENT).build();
Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current()).build();
indicesLookup.put(
".foo",
new ConcreteIndex(IndexMetadata.builder(".foo").settings(settings).system(true).numberOfShards(1).numberOfReplicas(0).build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.ResourceAlreadyExistsException;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.create.CreateIndexClusterStateUpdateRequest;
Expand Down Expand Up @@ -1088,7 +1087,7 @@ public void testParseMappingsWithTypelessTemplate() throws Exception {

public void testBuildIndexMetadata() {
IndexMetadata sourceIndexMetadata = IndexMetadata.builder("parent")
.settings(Settings.builder().put("index.version.created", Version.CURRENT).build())
.settings(Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current()).build())
.numberOfShards(1)
.numberOfReplicas(0)
.primaryTerm(0, 3L)
Expand All @@ -1105,7 +1104,7 @@ public void testBuildIndexMetadata() {

public void testGetIndexNumberOfRoutingShardsWithNullSourceIndex() {
Settings indexSettings = Settings.builder()
.put("index.version.created", Version.CURRENT)
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
.put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 3)
.build();
int targetRoutingNumberOfShards = getIndexNumberOfRoutingShards(indexSettings, null);
Expand Down Expand Up @@ -1149,7 +1148,7 @@ public void testGetIndexNumberOfRoutingShardsYieldsSourceNumberOfShards() {
Settings indexSettings = Settings.builder().put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 3).build();

IndexMetadata sourceIndexMetadata = IndexMetadata.builder("parent")
.settings(Settings.builder().put("index.version.created", Version.CURRENT).build())
.settings(Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current()).build())
.numberOfShards(6)
.numberOfReplicas(0)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.elasticsearch.snapshots.SnapshotInfoTestUtils;
import org.elasticsearch.test.ClusterServiceUtils;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.VersionUtils;
import org.elasticsearch.test.index.IndexVersionUtils;
import org.junit.Before;

Expand Down Expand Up @@ -145,7 +144,7 @@ public void testDeleteIndexWithAnAlias() {
String alias = randomAlphaOfLength(5);

IndexMetadata idxMetadata = IndexMetadata.builder(index)
.settings(Settings.builder().put("index.version.created", VersionUtils.randomVersion(random())))
.settings(Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersionUtils.randomVersion(random())))
.putAlias(AliasMetadata.builder(alias).writeIndex(true).build())
.numberOfShards(1)
.numberOfReplicas(1)
Expand Down Expand Up @@ -234,7 +233,7 @@ public void testDeleteCurrentWriteIndexForDataStream() {

private ClusterState clusterState(String index) {
IndexMetadata indexMetadata = IndexMetadata.builder(index)
.settings(Settings.builder().put("index.version.created", VersionUtils.randomVersion(random())))
.settings(Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersionUtils.randomVersion(random())))
.numberOfShards(1)
.numberOfReplicas(1)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.VersionUtils;
import org.elasticsearch.test.index.IndexVersionUtils;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -730,7 +730,7 @@ private ClusterState applyHiddenAliasMix(ClusterState before, Boolean isHidden1,

private ClusterState createIndex(ClusterState state, String index) {
IndexMetadata indexMetadata = IndexMetadata.builder(index)
.settings(Settings.builder().put("index.version.created", VersionUtils.randomVersion(random())))
.settings(Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersionUtils.randomVersion(random())))
.numberOfShards(1)
.numberOfReplicas(1)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import joptsimple.OptionSet;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.Version;
import org.elasticsearch.cli.MockTerminal;
import org.elasticsearch.cli.Terminal;
import org.elasticsearch.cluster.ClusterName;
Expand All @@ -25,6 +24,7 @@
import org.elasticsearch.core.CheckedRunnable;
import org.elasticsearch.gateway.PersistedClusterStateService;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.test.ESTestCase;
import org.hamcrest.Matcher;
import org.junit.Before;
Expand Down Expand Up @@ -240,7 +240,7 @@ private void createIndexDataFiles(Settings settings, int shardCount, boolean wri
IndexMetadata.builder(INDEX.getName())
.settings(
Settings.builder()
.put("index.version.created", Version.CURRENT)
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
.put(IndexMetadata.SETTING_INDEX_UUID, INDEX.getUUID())
)
.numberOfShards(1)
Expand Down
Loading

0 comments on commit b67a9e1

Please sign in to comment.