From 802476f805f31a5764233fb04485e66cca4bf72f Mon Sep 17 00:00:00 2001 From: Nick Knize Date: Fri, 21 Apr 2023 04:46:49 +0000 Subject: [PATCH] [Refactor] Metadata members from ImmutableOpenMap to j.u.Map (#7165) Refactors Metadata.{indices, templates, customs} member variables from ImmutableOpenMap to use jdk Maps. Usage of these variables across the codebase is also refactored to use jdk maps. Signed-off-by: Nicholas Walter Knize --- CHANGELOG.md | 1 + .../client/indices/GetIndexResponseTests.java | 6 +- .../indices/GetMappingsResponseTests.java | 7 +- .../admin/indices/create/CreateIndexIT.java | 4 +- .../action/admin/indices/get/GetIndexIT.java | 5 +- .../cluster/ClusterStateDiffIT.java | 13 +- .../cluster/SimpleClusterStateIT.java | 10 +- .../opensearch/gateway/MetadataNodesIT.java | 5 +- .../gateway/RecoveryFromGatewayIT.java | 5 +- .../SegmentReplicationAllocationIT.java | 1 - .../DestructiveOperationsIT.java | 9 +- .../org/opensearch/recovery/RelocationIT.java | 5 +- .../search/SearchWeightedRoutingIT.java | 1 - .../state/TransportClusterStateAction.java | 7 +- .../TransportDeleteDanglingIndexAction.java | 5 +- .../admin/indices/get/GetIndexResponse.java | 26 +-- .../indices/get/TransportGetIndexAction.java | 3 +- .../mapping/get/GetMappingsResponse.java | 39 ++-- .../get/TransportGetMappingsAction.java | 5 +- .../get/TransportGetIndexTemplatesAction.java | 10 +- .../cluster/ClusterChangedEvent.java | 28 ++- .../org/opensearch/cluster/ClusterModule.java | 2 +- .../org/opensearch/cluster/ClusterState.java | 6 +- .../coordination/RemoveCustomsCommand.java | 6 +- .../UnsafeBootstrapClusterManagerCommand.java | 4 +- .../opensearch/cluster/metadata/Metadata.java | 174 +++++++++--------- .../MetadataIndexTemplateService.java | 15 +- .../SystemIndexMetadataUpgradeService.java | 23 ++- .../metadata/TemplateUpgradeService.java | 18 +- .../opensearch/env/NodeRepurposeCommand.java | 9 +- .../gateway/ClusterStateUpdaters.java | 5 +- .../gateway/DanglingIndicesState.java | 5 +- .../java/org/opensearch/gateway/Gateway.java | 5 +- .../opensearch/gateway/GatewayMetaState.java | 8 +- .../gateway/PersistedClusterStateService.java | 10 +- .../RemoveCorruptedShardDataCommand.java | 7 - .../rest/action/cat/RestTemplatesAction.java | 4 +- .../opensearch/snapshots/RestoreService.java | 12 +- .../opensearch/snapshots/SnapshotUtils.java | 7 +- .../reroute/ClusterRerouteResponseTests.java | 5 +- .../indices/get/GetIndexResponseTests.java | 13 +- .../mapping/get/GetMappingsResponseTests.java | 11 +- .../bulk/TransportBulkActionIngestTests.java | 59 +++--- .../cluster/ClusterChangedEventTests.java | 15 +- .../MetadataCreateIndexServiceTests.java | 5 +- .../cluster/metadata/MetadataTests.java | 54 +++--- .../metadata/TemplateUpgradeServiceTests.java | 3 +- .../allocation/AddIncrementallyTests.java | 4 +- .../allocation/BalanceConfigurationTests.java | 8 +- .../allocation/ThrottlingAllocationTests.java | 7 +- .../EnableAllocationShortCircuitTests.java | 4 +- .../gateway/DanglingIndicesStateTests.java | 7 +- .../mapper/FieldFilterMapperPluginTests.java | 3 +- .../indices/ShardLimitValidatorTests.java | 10 +- ...ClusterStateServiceRandomUpdatesTests.java | 8 +- .../snapshots/SnapshotUtilsTests.java | 4 +- 56 files changed, 331 insertions(+), 404 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2fd4fde8e93e..c200863be7ce2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Allow insecure string settings to warn-log usage and advise to migration of a newer secure variant ([#5496](https://github.com/opensearch-project/OpenSearch/pull/5496)) - Pass localNode info to all plugins on node start ([#7919](https://github.com/opensearch-project/OpenSearch/pull/7919) - Compress and cache cluster state during validate join request ([#7321](https://github.com/opensearch-project/OpenSearch/pull/7321)) +- [Refactor] Metadata members from ImmutableOpenMap to j.u.Map ([#7165](https://github.com/opensearch-project/OpenSearch/pull/7165)) ### Deprecated diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/indices/GetIndexResponseTests.java b/client/rest-high-level/src/test/java/org/opensearch/client/indices/GetIndexResponseTests.java index 63586bdbe4783..db2d327e50a65 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/indices/GetIndexResponseTests.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/indices/GetIndexResponseTests.java @@ -62,7 +62,7 @@ public class GetIndexResponseTests extends AbstractResponseTestCase< @Override protected org.opensearch.action.admin.indices.get.GetIndexResponse createServerTestInstance(XContentType xContentType) { String[] indices = generateRandomStringArray(5, 5, false, false); - ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(); + final Map mappings = new HashMap<>(); ImmutableOpenMap.Builder> aliases = ImmutableOpenMap.builder(); ImmutableOpenMap.Builder settings = ImmutableOpenMap.builder(); ImmutableOpenMap.Builder defaultSettings = ImmutableOpenMap.builder(); @@ -94,7 +94,7 @@ protected org.opensearch.action.admin.indices.get.GetIndexResponse createServerT } return new org.opensearch.action.admin.indices.get.GetIndexResponse( indices, - mappings.build(), + mappings, aliases.build(), settings.build(), defaultSettings.build(), @@ -113,7 +113,7 @@ protected void assertInstances( GetIndexResponse clientInstance ) { assertArrayEquals(serverTestInstance.getIndices(), clientInstance.getIndices()); - assertMapEquals(serverTestInstance.getMappings(), clientInstance.getMappings()); + assertEquals(serverTestInstance.getMappings(), clientInstance.getMappings()); assertMapEquals(serverTestInstance.getSettings(), clientInstance.getSettings()); assertMapEquals(serverTestInstance.defaultSettings(), clientInstance.getDefaultSettings()); assertMapEquals(serverTestInstance.getAliases(), clientInstance.getAliases()); diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/indices/GetMappingsResponseTests.java b/client/rest-high-level/src/test/java/org/opensearch/client/indices/GetMappingsResponseTests.java index 8158dc1ca4e2b..fe87e0fe6aac9 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/indices/GetMappingsResponseTests.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/indices/GetMappingsResponseTests.java @@ -34,7 +34,6 @@ import org.opensearch.client.AbstractResponseTestCase; import org.opensearch.cluster.metadata.MappingMetadata; -import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentType; import org.opensearch.index.mapper.MapperService; @@ -50,12 +49,12 @@ public class GetMappingsResponseTests extends AbstractResponseTestCase< @Override protected org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse createServerTestInstance(XContentType xContentType) { - ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(); + final Map mappings = new HashMap<>(); int numberOfIndexes = randomIntBetween(1, 5); for (int i = 0; i < numberOfIndexes; i++) { mappings.put("index-" + randomAlphaOfLength(5), randomMappingMetadata()); } - return new org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse(mappings.build()); + return new org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse(mappings); } @Override @@ -68,7 +67,7 @@ protected void assertInstances( org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse serverTestInstance, GetMappingsResponse clientInstance ) { - assertMapEquals(serverTestInstance.getMappings(), clientInstance.mappings()); + assertEquals(serverTestInstance.getMappings(), clientInstance.mappings()); } public static MappingMetadata randomMappingMetadata() { diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/CreateIndexIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/CreateIndexIT.java index 51ef63ae9e9c1..f6c016828f884 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/CreateIndexIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/CreateIndexIT.java @@ -45,7 +45,6 @@ import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.cluster.metadata.MappingMetadata; import org.opensearch.cluster.metadata.Metadata; -import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; import org.opensearch.common.xcontent.XContentFactory; @@ -59,6 +58,7 @@ import org.opensearch.test.OpenSearchIntegTestCase.ClusterScope; import org.opensearch.test.OpenSearchIntegTestCase.Scope; +import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.BiFunction; @@ -100,7 +100,7 @@ public void testCreationDateGenerated() { assertThat(state, notNullValue()); Metadata metadata = state.getMetadata(); assertThat(metadata, notNullValue()); - ImmutableOpenMap indices = metadata.getIndices(); + final Map indices = metadata.getIndices(); assertThat(indices, notNullValue()); assertThat(indices.size(), equalTo(1)); IndexMetadata index = indices.get("test"); diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/get/GetIndexIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/get/GetIndexIT.java index ffc738ac98de5..2bc661d85b4d9 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/get/GetIndexIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/get/GetIndexIT.java @@ -46,6 +46,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_METADATA_BLOCK; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_METADATA; @@ -271,7 +272,7 @@ private void assertNonEmptySettings(GetIndexResponse response, String indexName) } private void assertMappings(GetIndexResponse response, String indexName) { - ImmutableOpenMap mappings = response.mappings(); + final Map mappings = response.mappings(); assertThat(mappings, notNullValue()); assertThat(mappings.size(), equalTo(1)); MappingMetadata indexMappings = mappings.get(indexName); @@ -279,7 +280,7 @@ private void assertMappings(GetIndexResponse response, String indexName) { } private void assertEmptyOrOnlyDefaultMappings(GetIndexResponse response, String indexName) { - ImmutableOpenMap mappings = response.mappings(); + final Map mappings = response.mappings(); assertThat(mappings, notNullValue()); assertThat(mappings.size(), equalTo(1)); MappingMetadata indexMappings = mappings.get(indexName); diff --git a/server/src/internalClusterTest/java/org/opensearch/cluster/ClusterStateDiffIT.java b/server/src/internalClusterTest/java/org/opensearch/cluster/ClusterStateDiffIT.java index d7275598a2e06..ad886f8574c1e 100644 --- a/server/src/internalClusterTest/java/org/opensearch/cluster/ClusterStateDiffIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/cluster/ClusterStateDiffIT.java @@ -75,6 +75,7 @@ import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Set; import static java.util.Collections.emptyList; @@ -526,7 +527,7 @@ private interface RandomPart { /** * Returns list of parts from metadata */ - ImmutableOpenMap parts(Metadata metadata); + Map parts(Metadata metadata); /** * Puts the part back into metadata @@ -556,10 +557,10 @@ private interface RandomPart { */ private Metadata randomParts(Metadata metadata, String prefix, RandomPart randomPart) { Metadata.Builder builder = Metadata.builder(metadata); - ImmutableOpenMap parts = randomPart.parts(metadata); + final Map parts = randomPart.parts(metadata); int partCount = parts.size(); if (partCount > 0) { - List randomParts = randomSubsetOf(randomInt(partCount - 1), randomPart.parts(metadata).keys().toArray(String.class)); + List randomParts = randomSubsetOf(randomInt(partCount - 1), randomPart.parts(metadata).keySet().toArray(new String[0])); for (String part : randomParts) { if (randomBoolean()) { randomPart.remove(builder, part); @@ -583,7 +584,7 @@ private Metadata randomIndices(Metadata metadata) { return randomParts(metadata, "index", new RandomPart() { @Override - public ImmutableOpenMap parts(Metadata metadata) { + public Map parts(Metadata metadata) { return metadata.indices(); } @@ -645,7 +646,7 @@ public IndexMetadata randomChange(IndexMetadata part) { private Metadata randomTemplates(Metadata metadata) { return randomParts(metadata, "template", new RandomPart() { @Override - public ImmutableOpenMap parts(Metadata metadata) { + public Map parts(Metadata metadata) { return metadata.templates(); } @@ -702,7 +703,7 @@ private Metadata randomMetadataCustoms(final Metadata metadata) { return randomParts(metadata, "custom", new RandomPart() { @Override - public ImmutableOpenMap parts(Metadata metadata) { + public Map parts(Metadata metadata) { return metadata.customs(); } diff --git a/server/src/internalClusterTest/java/org/opensearch/cluster/SimpleClusterStateIT.java b/server/src/internalClusterTest/java/org/opensearch/cluster/SimpleClusterStateIT.java index fbc5ec85cb84e..c1cfbbbf1fda4 100644 --- a/server/src/internalClusterTest/java/org/opensearch/cluster/SimpleClusterStateIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/cluster/SimpleClusterStateIT.java @@ -47,7 +47,6 @@ import org.opensearch.common.Priority; import org.opensearch.common.Strings; import org.opensearch.common.UUIDs; -import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; @@ -65,7 +64,6 @@ import org.opensearch.repositories.RepositoriesService; import org.opensearch.script.ScriptService; import org.opensearch.test.OpenSearchIntegTestCase; -import org.opensearch.test.hamcrest.CollectionAssertions; import org.opensearch.threadpool.ThreadPool; import org.opensearch.watcher.ResourceWatcherService; @@ -76,6 +74,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Supplier; @@ -83,6 +82,7 @@ import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertIndexTemplateExists; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasKey; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.is; @@ -238,14 +238,14 @@ private void testFilteringByIndexWorks(String[] indices, String[] expected) { .setIndices(indices) .get(); - ImmutableOpenMap metadata = clusterState.getState().getMetadata().indices(); + final Map metadata = clusterState.getState().getMetadata().indices(); assertThat(metadata.size(), is(expected.length)); RoutingTable routingTable = clusterState.getState().getRoutingTable(); assertThat(routingTable.indicesRouting().size(), is(expected.length)); - for (String expectedIndex : expected) { - assertThat(metadata, CollectionAssertions.hasKey(expectedIndex)); + for (final String expectedIndex : expected) { + assertThat(metadata, hasKey(expectedIndex)); assertThat(routingTable.hasIndex(expectedIndex), is(true)); } } diff --git a/server/src/internalClusterTest/java/org/opensearch/gateway/MetadataNodesIT.java b/server/src/internalClusterTest/java/org/opensearch/gateway/MetadataNodesIT.java index 4bbd968d851b8..cfd1dd7f9a008 100644 --- a/server/src/internalClusterTest/java/org/opensearch/gateway/MetadataNodesIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/gateway/MetadataNodesIT.java @@ -36,7 +36,6 @@ import org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.opensearch.cluster.coordination.Coordinator; import org.opensearch.cluster.metadata.IndexMetadata; -import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.common.settings.Settings; import org.opensearch.discovery.Discovery; import org.opensearch.env.NodeEnvironment; @@ -152,7 +151,7 @@ public void testMetaWrittenWhenIndexIsClosedAndMetaUpdated() throws Exception { ); // make sure it was also written on red node although index is closed - ImmutableOpenMap indicesMetadata = getIndicesMetadataOnNode(dataNode); + Map indicesMetadata = getIndicesMetadataOnNode(dataNode); assertNotNull(((Map) (indicesMetadata.get(index).mapping().getSourceAsMap().get("properties"))).get("integer_field")); assertThat(indicesMetadata.get(index).getState(), equalTo(IndexMetadata.State.CLOSE)); @@ -239,7 +238,7 @@ private boolean indexDirectoryExists(String nodeName, Index index) { return false; } - private ImmutableOpenMap getIndicesMetadataOnNode(String nodeName) { + private Map getIndicesMetadataOnNode(String nodeName) { final Coordinator coordinator = (Coordinator) internalCluster().getInstance(Discovery.class, nodeName); return coordinator.getApplierState().getMetadata().getIndices(); } diff --git a/server/src/internalClusterTest/java/org/opensearch/gateway/RecoveryFromGatewayIT.java b/server/src/internalClusterTest/java/org/opensearch/gateway/RecoveryFromGatewayIT.java index 11af1fb3cbfab..298ec5a8efc10 100644 --- a/server/src/internalClusterTest/java/org/opensearch/gateway/RecoveryFromGatewayIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/gateway/RecoveryFromGatewayIT.java @@ -32,8 +32,6 @@ package org.opensearch.gateway; -import com.carrotsearch.hppc.cursors.ObjectCursor; - import org.opensearch.action.admin.cluster.configuration.AddVotingConfigExclusionsAction; import org.opensearch.action.admin.cluster.configuration.AddVotingConfigExclusionsRequest; import org.opensearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsAction; @@ -181,8 +179,7 @@ private Map assertAndCapturePrimaryTerms(Map pre } final Map result = new HashMap<>(); final ClusterState state = client().admin().cluster().prepareState().get().getState(); - for (ObjectCursor cursor : state.metadata().indices().values()) { - final IndexMetadata indexMetadata = cursor.value; + for (final IndexMetadata indexMetadata : state.metadata().indices().values()) { final String index = indexMetadata.getIndex().getName(); final long[] previous = previousTerms.get(index); final long[] current = IntStream.range(0, indexMetadata.getNumberOfShards()).mapToLong(indexMetadata::primaryTerm).toArray(); diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationAllocationIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationAllocationIT.java index 04f0a2c4bfb13..f2c760638b54b 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationAllocationIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationAllocationIT.java @@ -61,7 +61,6 @@ public void enablePreferPrimaryBalance() { /** * This test verifies that the overall primary balance is attained during allocation. This test verifies primary * balance per index and across all indices is maintained. - * @throws Exception */ public void testGlobalPrimaryAllocation() throws Exception { internalCluster().startClusterManagerOnlyNode(); diff --git a/server/src/internalClusterTest/java/org/opensearch/operateAllIndices/DestructiveOperationsIT.java b/server/src/internalClusterTest/java/org/opensearch/operateAllIndices/DestructiveOperationsIT.java index 7a19f3c832312..4732456cb092e 100644 --- a/server/src/internalClusterTest/java/org/opensearch/operateAllIndices/DestructiveOperationsIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/operateAllIndices/DestructiveOperationsIT.java @@ -32,7 +32,6 @@ package org.opensearch.operateAllIndices; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.opensearch.action.support.DestructiveOperations; import org.opensearch.cluster.ClusterState; import org.opensearch.cluster.metadata.IndexMetadata; @@ -109,8 +108,8 @@ public void testCloseIndexDefaultBehaviour() throws Exception { } ClusterState state = client().admin().cluster().prepareState().get().getState(); - for (ObjectObjectCursor indexMetadataObjectObjectCursor : state.getMetadata().indices()) { - assertEquals(IndexMetadata.State.CLOSE, indexMetadataObjectObjectCursor.value.getState()); + for (final IndexMetadata indexMetadataObjectObjectCursor : state.getMetadata().indices().values()) { + assertEquals(IndexMetadata.State.CLOSE, indexMetadataObjectObjectCursor.getState()); } } @@ -141,8 +140,8 @@ public void testOpenIndexDefaultBehaviour() throws Exception { } ClusterState state = client().admin().cluster().prepareState().get().getState(); - for (ObjectObjectCursor indexMetadataObjectObjectCursor : state.getMetadata().indices()) { - assertEquals(IndexMetadata.State.OPEN, indexMetadataObjectObjectCursor.value.getState()); + for (final IndexMetadata indexMetadataObjectObjectCursor : state.getMetadata().indices().values()) { + assertEquals(IndexMetadata.State.OPEN, indexMetadataObjectObjectCursor.getState()); } } } diff --git a/server/src/internalClusterTest/java/org/opensearch/recovery/RelocationIT.java b/server/src/internalClusterTest/java/org/opensearch/recovery/RelocationIT.java index 1f16cc0363686..515d1ace8d492 100644 --- a/server/src/internalClusterTest/java/org/opensearch/recovery/RelocationIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/recovery/RelocationIT.java @@ -32,7 +32,6 @@ package org.opensearch.recovery; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.tests.util.English; import org.opensearch.action.ActionFuture; @@ -771,8 +770,8 @@ public void testRelocationEstablishedPeerRecoveryRetentionLeases() throws Except private void assertActiveCopiesEstablishedPeerRecoveryRetentionLeases() throws Exception { assertBusy(() -> { - for (ObjectCursor it : client().admin().cluster().prepareState().get().getState().metadata().indices().keys()) { - Map> byShardId = Stream.of(client().admin().indices().prepareStats(it.value).get().getShards()) + for (final String it : client().admin().cluster().prepareState().get().getState().metadata().indices().keySet()) { + Map> byShardId = Stream.of(client().admin().indices().prepareStats(it).get().getShards()) .collect(Collectors.groupingBy(l -> l.getShardRouting().shardId())); for (List shardStats : byShardId.values()) { Set expectedLeaseIds = shardStats.stream() diff --git a/server/src/internalClusterTest/java/org/opensearch/search/SearchWeightedRoutingIT.java b/server/src/internalClusterTest/java/org/opensearch/search/SearchWeightedRoutingIT.java index a4cf5ebb028e3..d8e9c74e97d56 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/SearchWeightedRoutingIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/SearchWeightedRoutingIT.java @@ -663,7 +663,6 @@ public void testStrictWeightedRoutingWithCustomString_FailOpenDisabled() throws /** * Should failopen shards even if failopen enabled with custom search preference. - * @throws Exception */ public void testStrictWeightedRoutingWithShardPrefNetworkDisruption_FailOpenEnabled() throws Exception { Settings commonSettings = Settings.builder() diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/state/TransportClusterStateAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/state/TransportClusterStateAction.java index 9d65146716496..88f94cacf3a81 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/state/TransportClusterStateAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/state/TransportClusterStateAction.java @@ -57,6 +57,7 @@ import java.io.IOException; import java.util.function.Predicate; +import java.util.Map; /** * Transport action for obtaining cluster state @@ -212,9 +213,9 @@ private ClusterStateResponse buildResponse(final ClusterStateRequest request, fi } // filter out metadata that shouldn't be returned by the API - for (ObjectObjectCursor custom : currentState.metadata().customs()) { - if (custom.value.context().contains(Metadata.XContentContext.API) == false) { - mdBuilder.removeCustom(custom.key); + for (final Map.Entry custom : currentState.metadata().customs().entrySet()) { + if (custom.getValue().context().contains(Metadata.XContentContext.API) == false) { + mdBuilder.removeCustom(custom.getKey()); } } } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/dangling/delete/TransportDeleteDanglingIndexAction.java b/server/src/main/java/org/opensearch/action/admin/indices/dangling/delete/TransportDeleteDanglingIndexAction.java index e14125c21af9c..23f5f3e177df6 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/dangling/delete/TransportDeleteDanglingIndexAction.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/dangling/delete/TransportDeleteDanglingIndexAction.java @@ -32,7 +32,6 @@ package org.opensearch.action.admin.indices.dangling.delete; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.OpenSearchException; @@ -186,8 +185,8 @@ public void onFailure(Exception e) { private ClusterState deleteDanglingIndex(ClusterState currentState, Index indexToDelete) { final Metadata metaData = currentState.getMetadata(); - for (ObjectObjectCursor each : metaData.indices()) { - if (indexToDelete.getUUID().equals(each.value.getIndexUUID())) { + for (final IndexMetadata each : metaData.indices().values()) { + if (indexToDelete.getUUID().equals(each.getIndexUUID())) { throw new IllegalArgumentException( "Refusing to delete dangling index " + indexToDelete diff --git a/server/src/main/java/org/opensearch/action/admin/indices/get/GetIndexResponse.java b/server/src/main/java/org/opensearch/action/admin/indices/get/GetIndexResponse.java index 5f98c184c95f7..b2a312f557778 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/get/GetIndexResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/get/GetIndexResponse.java @@ -52,7 +52,9 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; /** @@ -62,7 +64,7 @@ */ public class GetIndexResponse extends ActionResponse implements ToXContentObject { - private ImmutableOpenMap mappings = ImmutableOpenMap.of(); + private Map mappings = Map.of(); private ImmutableOpenMap> aliases = ImmutableOpenMap.of(); private ImmutableOpenMap settings = ImmutableOpenMap.of(); private ImmutableOpenMap defaultSettings = ImmutableOpenMap.of(); @@ -71,7 +73,7 @@ public class GetIndexResponse extends ActionResponse implements ToXContentObject public GetIndexResponse( String[] indices, - ImmutableOpenMap mappings, + Map mappings, ImmutableOpenMap> aliases, ImmutableOpenMap settings, ImmutableOpenMap defaultSettings, @@ -102,7 +104,7 @@ public GetIndexResponse( this.indices = in.readStringArray(); int mappingsSize = in.readVInt(); - ImmutableOpenMap.Builder mappingsMapBuilder = ImmutableOpenMap.builder(); + Map mappingsMapBuilder = new HashMap<>(); for (int i = 0; i < mappingsSize; i++) { String index = in.readString(); if (in.getVersion().before(Version.V_2_0_0)) { @@ -123,7 +125,7 @@ public GetIndexResponse( mappingsMapBuilder.put(index, metadata != null ? metadata : MappingMetadata.EMPTY_MAPPINGS); } } - mappings = mappingsMapBuilder.build(); + mappings = Collections.unmodifiableMap(mappingsMapBuilder); int aliasesSize = in.readVInt(); ImmutableOpenMap.Builder> aliasesMapBuilder = ImmutableOpenMap.builder(); @@ -171,11 +173,11 @@ public String[] getIndices() { return indices(); } - public ImmutableOpenMap mappings() { + public Map mappings() { return mappings; } - public ImmutableOpenMap getMappings() { + public Map getMappings() { return mappings(); } @@ -243,16 +245,16 @@ public String getSetting(String index, String setting) { public void writeTo(StreamOutput out) throws IOException { out.writeStringArray(indices); out.writeVInt(mappings.size()); - for (ObjectObjectCursor indexEntry : mappings) { - out.writeString(indexEntry.key); + for (final Map.Entry indexEntry : mappings.entrySet()) { + out.writeString(indexEntry.getKey()); if (out.getVersion().before(Version.V_2_0_0)) { - out.writeVInt(indexEntry.value == MappingMetadata.EMPTY_MAPPINGS ? 0 : 1); - if (indexEntry.value != MappingMetadata.EMPTY_MAPPINGS) { + out.writeVInt(indexEntry.getValue() == MappingMetadata.EMPTY_MAPPINGS ? 0 : 1); + if (indexEntry.getValue() != MappingMetadata.EMPTY_MAPPINGS) { out.writeString(MapperService.SINGLE_MAPPING_NAME); - indexEntry.value.writeTo(out); + indexEntry.getValue().writeTo(out); } } else { - out.writeOptionalWriteable(indexEntry.value); + out.writeOptionalWriteable(indexEntry.getValue()); } } out.writeVInt(aliases.size()); diff --git a/server/src/main/java/org/opensearch/action/admin/indices/get/TransportGetIndexAction.java b/server/src/main/java/org/opensearch/action/admin/indices/get/TransportGetIndexAction.java index de272bab332a7..dbd9afd58a1fa 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/get/TransportGetIndexAction.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/get/TransportGetIndexAction.java @@ -53,6 +53,7 @@ import java.io.IOException; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import java.util.stream.StreamSupport; @@ -104,7 +105,7 @@ protected void doClusterManagerOperation( final ClusterState state, final ActionListener listener ) { - ImmutableOpenMap mappingsResult = ImmutableOpenMap.of(); + Map mappingsResult = Map.of(); ImmutableOpenMap> aliasesResult = ImmutableOpenMap.of(); ImmutableOpenMap settings = ImmutableOpenMap.of(); ImmutableOpenMap defaultSettings = ImmutableOpenMap.of(); diff --git a/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/GetMappingsResponse.java b/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/GetMappingsResponse.java index b8415a3e95ac8..757e6e350a60b 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/GetMappingsResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/GetMappingsResponse.java @@ -32,12 +32,10 @@ package org.opensearch.action.admin.indices.mapping.get; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.opensearch.Version; import org.opensearch.action.ActionResponse; import org.opensearch.cluster.metadata.MappingMetadata; import org.opensearch.common.Strings; -import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.xcontent.XContentType; @@ -47,6 +45,9 @@ import org.opensearch.index.mapper.MapperService; import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; /** * Transport response to get field mappings. @@ -57,16 +58,16 @@ public class GetMappingsResponse extends ActionResponse implements ToXContentFra private static final ParseField MAPPINGS = new ParseField("mappings"); - private final ImmutableOpenMap mappings; + private final Map mappings; - public GetMappingsResponse(ImmutableOpenMap mappings) { - this.mappings = mappings; + public GetMappingsResponse(final Map mappings) { + this.mappings = Collections.unmodifiableMap(mappings); } GetMappingsResponse(StreamInput in) throws IOException { super(in); int size = in.readVInt(); - ImmutableOpenMap.Builder indexMapBuilder = ImmutableOpenMap.builder(); + final Map indexMapBuilder = new HashMap<>(); for (int i = 0; i < size; i++) { String index = in.readString(); if (in.getVersion().before(Version.V_2_0_0)) { @@ -87,40 +88,40 @@ public GetMappingsResponse(ImmutableOpenMap mappings) { indexMapBuilder.put(index, hasMapping ? new MappingMetadata(in) : MappingMetadata.EMPTY_MAPPINGS); } } - mappings = indexMapBuilder.build(); + mappings = Collections.unmodifiableMap(indexMapBuilder); } - public ImmutableOpenMap mappings() { + public Map mappings() { return mappings; } - public ImmutableOpenMap getMappings() { + public Map getMappings() { return mappings(); } @Override public void writeTo(StreamOutput out) throws IOException { out.writeVInt(mappings.size()); - for (ObjectObjectCursor indexEntry : mappings) { - out.writeString(indexEntry.key); + for (Map.Entry indexEntry : mappings.entrySet()) { + out.writeString(indexEntry.getKey()); if (out.getVersion().before(Version.V_2_0_0)) { - out.writeVInt(indexEntry.value == MappingMetadata.EMPTY_MAPPINGS ? 0 : 1); - if (indexEntry.value != MappingMetadata.EMPTY_MAPPINGS) { + out.writeVInt(indexEntry.getValue() == MappingMetadata.EMPTY_MAPPINGS ? 0 : 1); + if (indexEntry.getValue() != MappingMetadata.EMPTY_MAPPINGS) { out.writeString(MapperService.SINGLE_MAPPING_NAME); - indexEntry.value.writeTo(out); + indexEntry.getValue().writeTo(out); } } else { - out.writeOptionalWriteable(indexEntry.value); + out.writeOptionalWriteable(indexEntry.getValue()); } } } @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - for (final ObjectObjectCursor indexEntry : getMappings()) { - builder.startObject(indexEntry.key); - if (indexEntry.value != null) { - builder.field(MAPPINGS.getPreferredName(), indexEntry.value.sourceAsMap()); + for (final Map.Entry indexEntry : getMappings().entrySet()) { + builder.startObject(indexEntry.getKey()); + if (indexEntry.getValue() != null) { + builder.field(MAPPINGS.getPreferredName(), indexEntry.getValue().sourceAsMap()); } else { builder.startObject(MAPPINGS.getPreferredName()).endObject(); } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/TransportGetMappingsAction.java b/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/TransportGetMappingsAction.java index e724320728b66..933d598cd4dd8 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/TransportGetMappingsAction.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/mapping/get/TransportGetMappingsAction.java @@ -41,7 +41,6 @@ import org.opensearch.cluster.metadata.IndexNameExpressionResolver; import org.opensearch.cluster.metadata.MappingMetadata; import org.opensearch.cluster.service.ClusterService; -import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.common.inject.Inject; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.indices.IndicesService; @@ -49,6 +48,7 @@ import org.opensearch.transport.TransportService; import java.io.IOException; +import java.util.Map; /** * Transport action to get field mappings. @@ -96,8 +96,7 @@ protected void doClusterManagerOperation( ) { logger.trace("serving getMapping request based on version {}", state.version()); try { - ImmutableOpenMap result = state.metadata() - .findMappings(concreteIndices, indicesService.getFieldFilter()); + final Map result = state.metadata().findMappings(concreteIndices, indicesService.getFieldFilter()); listener.onResponse(new GetMappingsResponse(result)); } catch (IOException e) { listener.onFailure(e); diff --git a/server/src/main/java/org/opensearch/action/admin/indices/template/get/TransportGetIndexTemplatesAction.java b/server/src/main/java/org/opensearch/action/admin/indices/template/get/TransportGetIndexTemplatesAction.java index d74ff9e309842..2a511e60eaf7b 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/template/get/TransportGetIndexTemplatesAction.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/template/get/TransportGetIndexTemplatesAction.java @@ -31,7 +31,6 @@ package org.opensearch.action.admin.indices.template.get; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.opensearch.action.ActionListener; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.clustermanager.TransportClusterManagerNodeReadAction; @@ -51,6 +50,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; /** * Transport action to retrieve one or more Index templates @@ -105,16 +105,16 @@ protected void clusterManagerOperation( // If we did not ask for a specific name, then we return all templates if (request.names().length == 0) { - results = Arrays.asList(state.metadata().templates().values().toArray(IndexTemplateMetadata.class)); + results = Arrays.asList(state.metadata().templates().values().toArray(new IndexTemplateMetadata[0])); } else { results = new ArrayList<>(); } for (String name : request.names()) { if (Regex.isSimpleMatchPattern(name)) { - for (ObjectObjectCursor entry : state.metadata().templates()) { - if (Regex.simpleMatch(name, entry.key)) { - results.add(entry.value); + for (final Map.Entry entry : state.metadata().templates().entrySet()) { + if (Regex.simpleMatch(name, entry.getKey())) { + results.add(entry.getValue()); } } } else if (state.metadata().templates().containsKey(name)) { diff --git a/server/src/main/java/org/opensearch/cluster/ClusterChangedEvent.java b/server/src/main/java/org/opensearch/cluster/ClusterChangedEvent.java index 7e5de435267b4..28085dd6e3860 100644 --- a/server/src/main/java/org/opensearch/cluster/ClusterChangedEvent.java +++ b/server/src/main/java/org/opensearch/cluster/ClusterChangedEvent.java @@ -32,14 +32,11 @@ package org.opensearch.cluster; -import com.carrotsearch.hppc.cursors.ObjectCursor; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.opensearch.cluster.metadata.IndexGraveyard; import org.opensearch.cluster.metadata.IndexGraveyard.IndexGraveyardDiff; import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.cluster.metadata.Metadata; import org.opensearch.cluster.node.DiscoveryNodes; -import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.gateway.GatewayService; import org.opensearch.index.Index; @@ -47,6 +44,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; @@ -129,8 +127,7 @@ public List indicesCreated() { return Collections.emptyList(); } List created = null; - for (ObjectCursor cursor : state.metadata().indices().keys()) { - String index = cursor.value; + for (final String index : state.metadata().indices().keySet()) { if (!previousState.metadata().hasIndex(index)) { if (created == null) { created = new ArrayList<>(); @@ -170,20 +167,20 @@ public boolean metadataChanged() { */ public Set changedCustomMetadataSet() { Set result = new HashSet<>(); - ImmutableOpenMap currentCustoms = state.metadata().customs(); - ImmutableOpenMap previousCustoms = previousState.metadata().customs(); + Map currentCustoms = state.metadata().customs(); + Map previousCustoms = previousState.metadata().customs(); if (currentCustoms.equals(previousCustoms) == false) { - for (ObjectObjectCursor currentCustomMetadata : currentCustoms) { + for (Map.Entry currentCustomMetadata : currentCustoms.entrySet()) { // new custom md added or existing custom md changed - if (previousCustoms.containsKey(currentCustomMetadata.key) == false - || currentCustomMetadata.value.equals(previousCustoms.get(currentCustomMetadata.key)) == false) { - result.add(currentCustomMetadata.key); + if (previousCustoms.containsKey(currentCustomMetadata.getKey()) == false + || currentCustomMetadata.getValue().equals(previousCustoms.get(currentCustomMetadata.getKey())) == false) { + result.add(currentCustomMetadata.getKey()); } } // existing custom md deleted - for (ObjectObjectCursor previousCustomMetadata : previousCustoms) { - if (currentCustoms.containsKey(previousCustomMetadata.key) == false) { - result.add(previousCustomMetadata.key); + for (Map.Entry previousCustomMetadata : previousCustoms.entrySet()) { + if (currentCustoms.containsKey(previousCustomMetadata.getKey()) == false) { + result.add(previousCustomMetadata.getKey()); } } } @@ -286,8 +283,7 @@ private List indicesDeletedFromClusterState() { final Metadata previousMetadata = previousState.metadata(); final Metadata currentMetadata = state.metadata(); - for (ObjectCursor cursor : previousMetadata.indices().values()) { - IndexMetadata index = cursor.value; + for (final IndexMetadata index : previousMetadata.indices().values()) { IndexMetadata current = currentMetadata.index(index.getIndex()); if (current == null) { if (deleted == null) { diff --git a/server/src/main/java/org/opensearch/cluster/ClusterModule.java b/server/src/main/java/org/opensearch/cluster/ClusterModule.java index 8a4e17e5c0dc3..011a3d988c7f9 100644 --- a/server/src/main/java/org/opensearch/cluster/ClusterModule.java +++ b/server/src/main/java/org/opensearch/cluster/ClusterModule.java @@ -230,7 +230,7 @@ public static ClusterState filterCustomsForPre63Clients(ClusterState clusterStat } }); final Metadata.Builder metaBuilder = Metadata.builder(clusterState.metadata()); - clusterState.metadata().customs().keysIt().forEachRemaining(name -> { + clusterState.metadata().customs().keySet().iterator().forEachRemaining(name -> { if (PRE_6_3_METADATA_CUSTOMS_WHITE_LIST.contains(name) == false) { metaBuilder.removeCustom(name); } diff --git a/server/src/main/java/org/opensearch/cluster/ClusterState.java b/server/src/main/java/org/opensearch/cluster/ClusterState.java index 98d1e9c6db0e5..5d32d2edb8494 100644 --- a/server/src/main/java/org/opensearch/cluster/ClusterState.java +++ b/server/src/main/java/org/opensearch/cluster/ClusterState.java @@ -375,9 +375,9 @@ public String toString() { } if (metadata.customs().isEmpty() == false) { sb.append("metadata customs:\n"); - for (final ObjectObjectCursor cursor : metadata.customs()) { - final String type = cursor.key; - final Metadata.Custom custom = cursor.value; + for (final Map.Entry cursor : metadata.customs().entrySet()) { + final String type = cursor.getKey(); + final Metadata.Custom custom = cursor.getValue(); sb.append(TAB).append(type).append(": ").append(custom); } sb.append("\n"); diff --git a/server/src/main/java/org/opensearch/cluster/coordination/RemoveCustomsCommand.java b/server/src/main/java/org/opensearch/cluster/coordination/RemoveCustomsCommand.java index 5e7614d86cecd..8dad8e3836635 100644 --- a/server/src/main/java/org/opensearch/cluster/coordination/RemoveCustomsCommand.java +++ b/server/src/main/java/org/opensearch/cluster/coordination/RemoveCustomsCommand.java @@ -31,7 +31,6 @@ package org.opensearch.cluster.coordination; -import com.carrotsearch.hppc.cursors.ObjectCursor; import joptsimple.OptionSet; import joptsimple.OptionSpec; import org.opensearch.cli.ExitCodes; @@ -84,12 +83,11 @@ protected void processNodePaths(Terminal terminal, Path[] dataPaths, int nodeLoc terminal.println(Terminal.Verbosity.VERBOSE, "Loading cluster state"); final Tuple termAndClusterState = loadTermAndClusterState(persistedClusterStateService, env); final ClusterState oldClusterState = termAndClusterState.v2(); - terminal.println(Terminal.Verbosity.VERBOSE, "custom metadata names: " + oldClusterState.metadata().customs().keys()); + terminal.println(Terminal.Verbosity.VERBOSE, "custom metadata names: " + oldClusterState.metadata().customs().keySet()); final Metadata.Builder metadataBuilder = Metadata.builder(oldClusterState.metadata()); for (String customToRemove : customsToRemove) { boolean matched = false; - for (ObjectCursor customKeyCur : oldClusterState.metadata().customs().keys()) { - final String customKey = customKeyCur.value; + for (final String customKey : oldClusterState.metadata().customs().keySet()) { if (Regex.simpleMatch(customToRemove, customKey)) { metadataBuilder.removeCustom(customKey); if (matched == false) { diff --git a/server/src/main/java/org/opensearch/cluster/coordination/UnsafeBootstrapClusterManagerCommand.java b/server/src/main/java/org/opensearch/cluster/coordination/UnsafeBootstrapClusterManagerCommand.java index 229c20b8dea17..188ea1325e806 100644 --- a/server/src/main/java/org/opensearch/cluster/coordination/UnsafeBootstrapClusterManagerCommand.java +++ b/server/src/main/java/org/opensearch/cluster/coordination/UnsafeBootstrapClusterManagerCommand.java @@ -31,7 +31,6 @@ package org.opensearch.cluster.coordination; -import com.carrotsearch.hppc.cursors.ObjectCursor; import joptsimple.OptionSet; import joptsimple.OptionSpec; import org.opensearch.OpenSearchException; @@ -151,8 +150,7 @@ protected void processNodePaths(Terminal terminal, Path[] dataPaths, int nodeLoc .clusterUUIDCommitted(true) .persistentSettings(persistentSettings) .coordinationMetadata(newCoordinationMetadata); - for (ObjectCursor idx : metadata.indices().values()) { - IndexMetadata indexMetadata = idx.value; + for (final IndexMetadata indexMetadata : metadata.indices().values()) { newMetadata.put( IndexMetadata.builder(indexMetadata) .settings( diff --git a/server/src/main/java/org/opensearch/cluster/metadata/Metadata.java b/server/src/main/java/org/opensearch/cluster/metadata/Metadata.java index af84bfd2cb864..1eaec1519e790 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/Metadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/Metadata.java @@ -32,10 +32,9 @@ package org.opensearch.cluster.metadata; -import com.carrotsearch.hppc.ObjectHashSet; import com.carrotsearch.hppc.cursors.ObjectCursor; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; +import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; import org.apache.lucene.util.CollectionUtil; @@ -55,7 +54,6 @@ import org.opensearch.common.Nullable; import org.opensearch.common.Strings; import org.opensearch.common.UUIDs; -import org.opensearch.common.collect.HppcMaps; import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; @@ -90,6 +88,7 @@ import java.util.Optional; import java.util.Set; import java.util.SortedMap; +import java.util.Spliterators; import java.util.TreeMap; import java.util.function.Function; import java.util.function.Predicate; @@ -244,9 +243,9 @@ public interface Custom extends NamedDiffable, ToXContentFragment, Clust private final Settings persistentSettings; private final Settings settings; private final DiffableStringMap hashesOfConsistentSettings; - private final ImmutableOpenMap indices; - private final ImmutableOpenMap templates; - private final ImmutableOpenMap customs; + private final Map indices; + private final Map templates; + private final Map customs; private final transient int totalNumberOfShards; // Transient ? not serializable anyway? private final int totalOpenIndexShards; @@ -268,9 +267,9 @@ public interface Custom extends NamedDiffable, ToXContentFragment, Clust Settings transientSettings, Settings persistentSettings, DiffableStringMap hashesOfConsistentSettings, - ImmutableOpenMap indices, - ImmutableOpenMap templates, - ImmutableOpenMap customs, + final Map indices, + final Map templates, + final Map customs, String[] allIndices, String[] visibleIndices, String[] allOpenIndices, @@ -287,15 +286,15 @@ public interface Custom extends NamedDiffable, ToXContentFragment, Clust this.persistentSettings = persistentSettings; this.settings = Settings.builder().put(persistentSettings).put(transientSettings).build(); this.hashesOfConsistentSettings = hashesOfConsistentSettings; - this.indices = indices; - this.customs = customs; - this.templates = templates; + this.indices = Collections.unmodifiableMap(indices); + this.customs = Collections.unmodifiableMap(customs); + this.templates = Collections.unmodifiableMap(templates); int totalNumberOfShards = 0; int totalOpenIndexShards = 0; - for (ObjectCursor cursor : indices.values()) { - totalNumberOfShards += cursor.value.getTotalNumberOfShards(); - if (IndexMetadata.State.OPEN.equals(cursor.value.getState())) { - totalOpenIndexShards += cursor.value.getTotalNumberOfShards(); + for (IndexMetadata cursor : indices.values()) { + totalNumberOfShards += cursor.getTotalNumberOfShards(); + if (IndexMetadata.State.OPEN.equals(cursor.getState())) { + totalOpenIndexShards += cursor.getTotalNumberOfShards(); } } this.totalNumberOfShards = totalNumberOfShards; @@ -359,8 +358,7 @@ public boolean hasAlias(String alias) { } public boolean equalsAliases(Metadata other) { - for (ObjectCursor cursor : other.indices().values()) { - IndexMetadata otherIndex = cursor.value; + for (IndexMetadata otherIndex : other.indices().values()) { IndexMetadata thisIndex = index(otherIndex.getIndex()); if (thisIndex == null) { return false; @@ -469,21 +467,19 @@ private ImmutableOpenMap> findAliases(final String[] * @see MapperPlugin#getFieldFilter() * */ - public ImmutableOpenMap findMappings(String[] concreteIndices, Function> fieldFilter) + public Map findMappings(String[] concreteIndices, Function> fieldFilter) throws IOException { assert concreteIndices != null; if (concreteIndices.length == 0) { - return ImmutableOpenMap.of(); + return Map.of(); } - ImmutableOpenMap.Builder indexMapBuilder = ImmutableOpenMap.builder(); - Iterable intersection = HppcMaps.intersection(ObjectHashSet.from(concreteIndices), indices.keys()); - for (String index : intersection) { - IndexMetadata indexMetadata = indices.get(index); - Predicate fieldPredicate = fieldFilter.apply(index); - indexMapBuilder.put(index, filterFields(indexMetadata.mapping(), fieldPredicate)); - } - return indexMapBuilder.build(); + final Map indexMapBuilder = new HashMap<>(); + Arrays.stream(concreteIndices) + .filter(indices.keySet()::contains) + .forEach((idx) -> indexMapBuilder.put(idx, filterFields(indices.get(idx).mapping(), fieldFilter.apply(idx)))); + + return Collections.unmodifiableMap(indexMapBuilder); } /** @@ -786,20 +782,20 @@ public IndexMetadata getIndexSafe(Index index) { throw new IndexNotFoundException(index); } - public ImmutableOpenMap indices() { + public Map indices() { return this.indices; } - public ImmutableOpenMap getIndices() { + public Map getIndices() { return indices(); } - public ImmutableOpenMap templates() { + public Map templates() { return this.templates; } - public ImmutableOpenMap getTemplates() { - return this.templates; + public Map getTemplates() { + return templates(); } public Map componentTemplates() { @@ -824,12 +820,12 @@ public DecommissionAttributeMetadata decommissionAttributeMetadata() { return custom(DecommissionAttributeMetadata.TYPE); } - public ImmutableOpenMap customs() { + public Map customs() { return this.customs; } - public ImmutableOpenMap getCustoms() { - return this.customs; + public Map getCustoms() { + return this.customs(); } /** @@ -908,7 +904,7 @@ public boolean routingRequired(String concreteIndex) { @Override public Iterator iterator() { - return indices.valuesIt(); + return indices.values().iterator(); } public static boolean isGlobalStateEquals(Metadata metadata1, Metadata metadata2) { @@ -932,15 +928,15 @@ public static boolean isGlobalStateEquals(Metadata metadata1, Metadata metadata2 } // Check if any persistent metadata needs to be saved int customCount1 = 0; - for (ObjectObjectCursor cursor : metadata1.customs) { - if (cursor.value.context().contains(XContentContext.GATEWAY)) { - if (!cursor.value.equals(metadata2.custom(cursor.key))) return false; + for (Map.Entry cursor : metadata1.customs.entrySet()) { + if (cursor.getValue().context().contains(XContentContext.GATEWAY)) { + if (!cursor.getValue().equals(metadata2.custom(cursor.getKey()))) return false; customCount1++; } } int customCount2 = 0; - for (ObjectCursor cursor : metadata2.customs.values()) { - if (cursor.value.context().contains(XContentContext.GATEWAY)) { + for (final Custom cursor : metadata2.customs.values()) { + if (cursor.context().contains(XContentContext.GATEWAY)) { customCount2++; } } @@ -981,9 +977,9 @@ private static class MetadataDiff implements Diff { private final Settings transientSettings; private final Settings persistentSettings; private final Diff hashesOfConsistentSettings; - private final Diff> indices; - private final Diff> templates; - private final Diff> customs; + private final Diff> indices; + private final Diff> templates; + private final Diff> customs; MetadataDiff(Metadata before, Metadata after) { clusterUUID = after.clusterUUID; @@ -1021,9 +1017,9 @@ private static class MetadataDiff implements Diff { } else { hashesOfConsistentSettings = DiffableStringMap.DiffableStringMapDiff.EMPTY; } - indices = DiffableUtils.readImmutableOpenMapDiff(in, DiffableUtils.getStringKeySerializer(), INDEX_METADATA_DIFF_VALUE_READER); - templates = DiffableUtils.readImmutableOpenMapDiff(in, DiffableUtils.getStringKeySerializer(), TEMPLATES_DIFF_VALUE_READER); - customs = DiffableUtils.readImmutableOpenMapDiff(in, DiffableUtils.getStringKeySerializer(), CUSTOM_VALUE_SERIALIZER); + indices = DiffableUtils.readJdkMapDiff(in, DiffableUtils.getStringKeySerializer(), INDEX_METADATA_DIFF_VALUE_READER); + templates = DiffableUtils.readJdkMapDiff(in, DiffableUtils.getStringKeySerializer(), TEMPLATES_DIFF_VALUE_READER); + customs = DiffableUtils.readJdkMapDiff(in, DiffableUtils.getStringKeySerializer(), CUSTOM_VALUE_SERIALIZER); } @Override @@ -1114,20 +1110,20 @@ public void writeTo(StreamOutput out) throws IOException { indexMetadata.writeTo(out); } out.writeVInt(templates.size()); - for (ObjectCursor cursor : templates.values()) { - cursor.value.writeTo(out); + for (final IndexTemplateMetadata cursor : templates.values()) { + cursor.writeTo(out); } // filter out custom states not supported by the other node int numberOfCustoms = 0; - for (final ObjectCursor cursor : customs.values()) { - if (FeatureAware.shouldSerialize(out, cursor.value)) { + for (final Custom cursor : customs.values()) { + if (FeatureAware.shouldSerialize(out, cursor)) { numberOfCustoms++; } } out.writeVInt(numberOfCustoms); - for (final ObjectCursor cursor : customs.values()) { - if (FeatureAware.shouldSerialize(out, cursor.value)) { - out.writeNamedWriteable(cursor.value); + for (final Custom cursor : customs.values()) { + if (FeatureAware.shouldSerialize(out, cursor)) { + out.writeNamedWriteable(cursor); } } } @@ -1156,15 +1152,15 @@ public static class Builder { private Settings persistentSettings = Settings.Builder.EMPTY_SETTINGS; private DiffableStringMap hashesOfConsistentSettings = new DiffableStringMap(Collections.emptyMap()); - private final ImmutableOpenMap.Builder indices; - private final ImmutableOpenMap.Builder templates; - private final ImmutableOpenMap.Builder customs; + private final Map indices; + private final Map templates; + private final Map customs; public Builder() { clusterUUID = UNKNOWN_CLUSTER_UUID; - indices = ImmutableOpenMap.builder(); - templates = ImmutableOpenMap.builder(); - customs = ImmutableOpenMap.builder(); + indices = new HashMap<>(); + templates = new HashMap<>(); + customs = new HashMap<>(); indexGraveyard(IndexGraveyard.builder().build()); // create new empty index graveyard to initialize } @@ -1176,9 +1172,9 @@ public Builder(Metadata metadata) { this.persistentSettings = metadata.persistentSettings; this.hashesOfConsistentSettings = metadata.hashesOfConsistentSettings; this.version = metadata.version; - this.indices = ImmutableOpenMap.builder(metadata.indices); - this.templates = ImmutableOpenMap.builder(metadata.templates); - this.customs = ImmutableOpenMap.builder(metadata.customs); + this.indices = new HashMap<>(metadata.indices); + this.templates = new HashMap<>(metadata.templates); + this.customs = new HashMap<>(metadata.customs); } public Builder put(IndexMetadata.Builder indexMetadataBuilder) { @@ -1231,7 +1227,7 @@ public Builder removeAllIndices() { return this; } - public Builder indices(ImmutableOpenMap indices) { + public Builder indices(final Map indices) { this.indices.putAll(indices); return this; } @@ -1250,7 +1246,7 @@ public Builder removeTemplate(String templateName) { return this; } - public Builder templates(ImmutableOpenMap templates) { + public Builder templates(Map templates) { this.templates.putAll(templates); return this; } @@ -1349,8 +1345,9 @@ public Builder removeCustom(String type) { return this; } - public Builder customs(ImmutableOpenMap customs) { - StreamSupport.stream(customs.spliterator(), false).forEach(cursor -> Objects.requireNonNull(cursor.value, cursor.key)); + public Builder customs(Map customs) { + StreamSupport.stream(Spliterators.spliterator(customs.entrySet(), 0), false) + .forEach(cursor -> Objects.requireNonNull(cursor.getValue(), cursor.getKey())); this.customs.putAll(customs); return this; } @@ -1376,7 +1373,7 @@ public DecommissionAttributeMetadata decommissionAttributeMetadata() { public Builder updateSettings(Settings settings, String... indices) { if (indices == null || indices.length == 0) { - indices = this.indices.keys().toArray(String.class); + indices = this.indices.keySet().toArray(new String[0]); } for (String index : indices) { IndexMetadata indexMetadata = this.indices.get(index); @@ -1478,8 +1475,7 @@ public Metadata build() { final List allClosedIndices = new ArrayList<>(); final List visibleClosedIndices = new ArrayList<>(); final Set allAliases = new HashSet<>(); - for (ObjectCursor cursor : indices.values()) { - final IndexMetadata indexMetadata = cursor.value; + for (final IndexMetadata indexMetadata : indices.values()) { final String name = indexMetadata.getIndex().getName(); boolean added = allIndices.add(name); assert added : "double index named [" + name + "]"; @@ -1514,10 +1510,10 @@ public Metadata build() { ArrayList duplicates = new ArrayList<>(); if (aliasDuplicatesWithIndices.isEmpty() == false) { // iterate again and constructs a helpful message - for (ObjectCursor cursor : indices.values()) { + for (final IndexMetadata cursor : indices.values()) { for (String alias : aliasDuplicatesWithIndices) { - if (cursor.value.getAliases().containsKey(alias)) { - duplicates.add(alias + " (alias of " + cursor.value.getIndex() + ") conflicts with index"); + if (cursor.getAliases().containsKey(alias)) { + duplicates.add(alias + " (alias of " + cursor.getIndex() + ") conflicts with index"); } } } @@ -1527,10 +1523,10 @@ public Metadata build() { aliasDuplicatesWithDataStreams.retainAll(allDataStreams); if (aliasDuplicatesWithDataStreams.isEmpty() == false) { // iterate again and constructs a helpful message - for (ObjectCursor cursor : indices.values()) { + for (final IndexMetadata cursor : indices.values()) { for (String alias : aliasDuplicatesWithDataStreams) { - if (cursor.value.getAliases().containsKey(alias)) { - duplicates.add(alias + " (alias of " + cursor.value.getIndex() + ") conflicts with data stream"); + if (cursor.getAliases().containsKey(alias)) { + duplicates.add(alias + " (alias of " + cursor.getIndex() + ") conflicts with data stream"); } } } @@ -1576,9 +1572,9 @@ public Metadata build() { transientSettings, persistentSettings, hashesOfConsistentSettings, - indices.build(), - templates.build(), - customs.build(), + indices, + templates, + customs, allIndicesArray, visibleIndicesArray, allOpenIndicesArray, @@ -1615,9 +1611,7 @@ private SortedMap buildIndicesLookup() { } } - for (ObjectCursor cursor : indices.values()) { - IndexMetadata indexMetadata = cursor.value; - + for (final IndexMetadata indexMetadata : indices.values()) { IndexAbstraction.Index index; DataStream parent = indexToDataStreamLookup.get(indexMetadata.getIndex().getName()); if (parent != null) { @@ -1630,7 +1624,7 @@ private SortedMap buildIndicesLookup() { IndexAbstraction existing = indicesLookup.put(indexMetadata.getIndex().getName(), index); assert existing == null : "duplicate for " + indexMetadata.getIndex(); - for (ObjectObjectCursor aliasCursor : indexMetadata.getAliases()) { + for (final ObjectObjectCursor aliasCursor : indexMetadata.getAliases()) { AliasMetadata aliasMetadata = aliasCursor.value; indicesLookup.compute(aliasMetadata.getAlias(), (aliasName, alias) -> { if (alias == null) { @@ -1714,8 +1708,8 @@ public static void toXContent(Metadata metadata, XContentBuilder builder, ToXCon } builder.startObject("templates"); - for (ObjectCursor cursor : metadata.templates().values()) { - IndexTemplateMetadata.Builder.toXContentWithTypes(cursor.value, builder, params); + for (final IndexTemplateMetadata cursor : metadata.templates().values()) { + IndexTemplateMetadata.Builder.toXContentWithTypes(cursor, builder, params); } builder.endObject(); @@ -1727,10 +1721,10 @@ public static void toXContent(Metadata metadata, XContentBuilder builder, ToXCon builder.endObject(); } - for (ObjectObjectCursor cursor : metadata.customs()) { - if (cursor.value.context().contains(context)) { - builder.startObject(cursor.key); - cursor.value.toXContent(builder, params); + for (final Map.Entry cursor : metadata.customs().entrySet()) { + if (cursor.getValue().context().contains(context)) { + builder.startObject(cursor.getKey()); + cursor.getValue().toXContent(builder, params); builder.endObject(); } } diff --git a/server/src/main/java/org/opensearch/cluster/metadata/MetadataIndexTemplateService.java b/server/src/main/java/org/opensearch/cluster/metadata/MetadataIndexTemplateService.java index 25cde7685b5e5..5ec718687dad9 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/MetadataIndexTemplateService.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/MetadataIndexTemplateService.java @@ -31,7 +31,6 @@ package org.opensearch.cluster.metadata; -import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -170,8 +169,7 @@ public ClusterManagerTaskThrottler.ThrottlingKey getClusterManagerThrottlingKey( @Override public ClusterState execute(ClusterState currentState) { Set templateNames = new HashSet<>(); - for (ObjectCursor cursor : currentState.metadata().templates().keys()) { - String templateName = cursor.value; + for (final String templateName : currentState.metadata().templates().keySet()) { if (Regex.simpleMatch(request.name, templateName)) { templateNames.add(templateName); } @@ -713,9 +711,9 @@ public static Map> findConflictingV1Templates( ) { Automaton v2automaton = Regex.simpleMatchToAutomaton(indexPatterns.toArray(Strings.EMPTY_ARRAY)); Map> overlappingTemplates = new HashMap<>(); - for (ObjectObjectCursor cursor : state.metadata().templates()) { - String name = cursor.key; - IndexTemplateMetadata template = cursor.value; + for (final Map.Entry cursor : state.metadata().templates().entrySet()) { + String name = cursor.getKey(); + IndexTemplateMetadata template = cursor.getValue(); Automaton v1automaton = Regex.simpleMatchToAutomaton(template.patterns().toArray(Strings.EMPTY_ARRAY)); if (Operations.isEmpty(Operations.intersection(v2automaton, v1automaton)) == false) { logger.debug( @@ -1014,8 +1012,7 @@ static ClusterState innerPutTemplate( public static List findV1Templates(Metadata metadata, String indexName, @Nullable Boolean isHidden) { final Predicate patternMatchPredicate = pattern -> Regex.simpleMatch(pattern, indexName); final List matchedTemplates = new ArrayList<>(); - for (ObjectCursor cursor : metadata.templates().values()) { - final IndexTemplateMetadata template = cursor.value; + for (final IndexTemplateMetadata template : metadata.templates().values()) { if (isHidden == null || isHidden == Boolean.FALSE) { final boolean matched = template.patterns().stream().anyMatch(patternMatchPredicate); if (matched) { @@ -1238,7 +1235,7 @@ public static List> resolveAliases(final List { if (template.aliases() != null) { Map aliasMeta = new HashMap<>(); - for (ObjectObjectCursor cursor : template.aliases()) { + for (final ObjectObjectCursor cursor : template.aliases()) { aliasMeta.put(cursor.key, cursor.value); } resolvedAliases.add(aliasMeta); diff --git a/server/src/main/java/org/opensearch/cluster/metadata/SystemIndexMetadataUpgradeService.java b/server/src/main/java/org/opensearch/cluster/metadata/SystemIndexMetadataUpgradeService.java index b1dd490a032b0..22d7235fd1f98 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/SystemIndexMetadataUpgradeService.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/SystemIndexMetadataUpgradeService.java @@ -32,7 +32,6 @@ package org.opensearch.cluster.metadata; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.cluster.ClusterChangedEvent; @@ -40,11 +39,11 @@ import org.opensearch.cluster.ClusterStateListener; import org.opensearch.cluster.ClusterStateUpdateTask; import org.opensearch.cluster.service.ClusterService; -import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.indices.SystemIndices; import java.util.ArrayList; import java.util.List; +import java.util.Map; /** * A service responsible for updating the metadata used by system indices. @@ -60,7 +59,7 @@ public class SystemIndexMetadataUpgradeService implements ClusterStateListener { private boolean clusterManager = false; - private volatile ImmutableOpenMap lastIndexMetadataMap = ImmutableOpenMap.of(); + private volatile Map lastIndexMetadataMap = Map.of(); private volatile boolean updateTaskPending = false; public SystemIndexMetadataUpgradeService(SystemIndices systemIndices, ClusterService clusterService) { @@ -75,12 +74,12 @@ public void clusterChanged(ClusterChangedEvent event) { } if (clusterManager && updateTaskPending == false) { - final ImmutableOpenMap indexMetadataMap = event.state().metadata().indices(); + final Map indexMetadataMap = event.state().metadata().indices(); if (lastIndexMetadataMap != indexMetadataMap) { - for (ObjectObjectCursor cursor : indexMetadataMap) { - if (cursor.value != lastIndexMetadataMap.get(cursor.key)) { - if (systemIndices.isSystemIndex(cursor.value.getIndex()) != cursor.value.isSystem()) { + for (final Map.Entry cursor : indexMetadataMap.entrySet()) { + if (cursor.getValue() != lastIndexMetadataMap.get(cursor.getKey())) { + if (systemIndices.isSystemIndex(cursor.getValue().getIndex()) != cursor.getValue().isSystem()) { updateTaskPending = true; clusterService.submitStateUpdateTask( "system_index_metadata_upgrade_service {system metadata change}", @@ -103,12 +102,12 @@ public class SystemIndexMetadataUpdateTask extends ClusterStateUpdateTask { @Override public ClusterState execute(ClusterState currentState) throws Exception { - final ImmutableOpenMap indexMetadataMap = currentState.metadata().indices(); + final Map indexMetadataMap = currentState.metadata().indices(); final List updatedMetadata = new ArrayList<>(); - for (ObjectObjectCursor cursor : indexMetadataMap) { - if (cursor.value != lastIndexMetadataMap.get(cursor.key)) { - if (systemIndices.isSystemIndex(cursor.value.getIndex()) != cursor.value.isSystem()) { - updatedMetadata.add(IndexMetadata.builder(cursor.value).system(!cursor.value.isSystem()).build()); + for (Map.Entry cursor : indexMetadataMap.entrySet()) { + if (cursor.getValue() != lastIndexMetadataMap.get(cursor.getKey())) { + if (systemIndices.isSystemIndex(cursor.getValue().getIndex()) != cursor.getValue().isSystem()) { + updatedMetadata.add(IndexMetadata.builder(cursor.getValue()).system(!cursor.getValue().isSystem()).build()); } } } diff --git a/server/src/main/java/org/opensearch/cluster/metadata/TemplateUpgradeService.java b/server/src/main/java/org/opensearch/cluster/metadata/TemplateUpgradeService.java index 2f1fdc1d010b2..b7c9c1512956d 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/TemplateUpgradeService.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/TemplateUpgradeService.java @@ -32,7 +32,6 @@ package org.opensearch.cluster.metadata; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; @@ -48,7 +47,6 @@ import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.common.collect.Tuple; import org.opensearch.common.unit.TimeValue; import org.opensearch.core.xcontent.ToXContent; @@ -91,7 +89,7 @@ public class TemplateUpgradeService implements ClusterStateListener { final AtomicInteger upgradesInProgress = new AtomicInteger(); - private ImmutableOpenMap lastTemplateMetadata; + private Map lastTemplateMetadata; public TemplateUpgradeService( Client client, @@ -131,7 +129,7 @@ public void clusterChanged(ClusterChangedEvent event) { return; } - ImmutableOpenMap templates = state.getMetadata().getTemplates(); + final Map templates = state.getMetadata().getTemplates(); if (templates == lastTemplateMetadata) { // we already checked these sets of templates - no reason to check it again @@ -225,9 +223,7 @@ void tryFinishUpgrade(AtomicBoolean anyUpgradeFailed) { // Check upgraders are satisfied after the update completed. If they still // report that changes are required, this might indicate a bug or that something // else tinkering with the templates during the upgrade. - final ImmutableOpenMap upgradedTemplates = clusterService.state() - .getMetadata() - .getTemplates(); + final Map upgradedTemplates = clusterService.state().getMetadata().getTemplates(); final boolean changesRequired = calculateTemplateChanges(upgradedTemplates).isPresent(); if (changesRequired) { logger.warn("Templates are still reported as out of date after the upgrade. The template upgrade will be retried."); @@ -239,13 +235,11 @@ void tryFinishUpgrade(AtomicBoolean anyUpgradeFailed) { } } - Optional, Set>> calculateTemplateChanges( - ImmutableOpenMap templates - ) { + Optional, Set>> calculateTemplateChanges(final Map templates) { // collect current templates Map existingMap = new HashMap<>(); - for (ObjectObjectCursor customCursor : templates) { - existingMap.put(customCursor.key, customCursor.value); + for (Map.Entry customCursor : templates.entrySet()) { + existingMap.put(customCursor.getKey(), customCursor.getValue()); } // upgrade global custom meta data Map upgradedMap = indexTemplateMetadataUpgraders.apply(existingMap); diff --git a/server/src/main/java/org/opensearch/env/NodeRepurposeCommand.java b/server/src/main/java/org/opensearch/env/NodeRepurposeCommand.java index f505a27a5624c..e56f7a838d85f 100644 --- a/server/src/main/java/org/opensearch/env/NodeRepurposeCommand.java +++ b/server/src/main/java/org/opensearch/env/NodeRepurposeCommand.java @@ -31,7 +31,6 @@ package org.opensearch.env; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import joptsimple.OptionParser; import joptsimple.OptionSet; import org.opensearch.OpenSearchException; @@ -158,7 +157,7 @@ private void processNoClusterManagerRepurposeNode( Sets.union( indexUUIDsFor(indexPaths), StreamSupport.stream(metadata.indices().values().spliterator(), false) - .map(imd -> imd.value.getIndexUUID()) + .map(imd -> imd.getIndexUUID()) .collect(Collectors.toSet()) ) ); @@ -302,9 +301,9 @@ private void outputHowToSeeVerboseInformation(Terminal terminal) { private String toIndexName(String uuid, Metadata metadata) { if (metadata != null) { - for (ObjectObjectCursor indexMetadata : metadata.indices()) { - if (indexMetadata.value.getIndexUUID().equals(uuid)) { - return indexMetadata.value.getIndex().getName(); + for (final IndexMetadata indexMetadata : metadata.indices().values()) { + if (indexMetadata.getIndexUUID().equals(uuid)) { + return indexMetadata.getIndex().getName(); } } } diff --git a/server/src/main/java/org/opensearch/gateway/ClusterStateUpdaters.java b/server/src/main/java/org/opensearch/gateway/ClusterStateUpdaters.java index 4402da155ff5a..1563ac84bdd1c 100644 --- a/server/src/main/java/org/opensearch/gateway/ClusterStateUpdaters.java +++ b/server/src/main/java/org/opensearch/gateway/ClusterStateUpdaters.java @@ -32,7 +32,6 @@ package org.opensearch.gateway; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; @@ -120,8 +119,8 @@ static ClusterState recoverClusterBlocks(final ClusterState state) { static ClusterState updateRoutingTable(final ClusterState state) { // initialize all index routing tables as empty final RoutingTable.Builder routingTableBuilder = RoutingTable.builder(state.routingTable()); - for (final ObjectCursor cursor : state.metadata().indices().values()) { - routingTableBuilder.addAsRecovery(cursor.value); + for (final IndexMetadata cursor : state.metadata().indices().values()) { + routingTableBuilder.addAsRecovery(cursor); } // start with 0 based versions for routing table routingTableBuilder.version(0); diff --git a/server/src/main/java/org/opensearch/gateway/DanglingIndicesState.java b/server/src/main/java/org/opensearch/gateway/DanglingIndicesState.java index 8c2a55fda3742..5e0c32751befb 100644 --- a/server/src/main/java/org/opensearch/gateway/DanglingIndicesState.java +++ b/server/src/main/java/org/opensearch/gateway/DanglingIndicesState.java @@ -32,7 +32,6 @@ package org.opensearch.gateway; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.action.ActionListener; @@ -191,8 +190,8 @@ void findNewAndAddDanglingIndices(final Metadata metadata) { */ public Map findNewDanglingIndices(Map existingDanglingIndices, final Metadata metadata) { final Set excludeIndexPathIds = new HashSet<>(metadata.indices().size() + danglingIndices.size()); - for (ObjectCursor cursor : metadata.indices().values()) { - excludeIndexPathIds.add(cursor.value.getIndex().getUUID()); + for (final IndexMetadata indexMetadata : metadata.indices().values()) { + excludeIndexPathIds.add(indexMetadata.getIndex().getUUID()); } for (Index index : existingDanglingIndices.keySet()) { excludeIndexPathIds.add(index.getUUID()); diff --git a/server/src/main/java/org/opensearch/gateway/Gateway.java b/server/src/main/java/org/opensearch/gateway/Gateway.java index 413c08569c64a..2648af4b73be3 100644 --- a/server/src/main/java/org/opensearch/gateway/Gateway.java +++ b/server/src/main/java/org/opensearch/gateway/Gateway.java @@ -33,7 +33,6 @@ package org.opensearch.gateway; import com.carrotsearch.hppc.ObjectFloatHashMap; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.action.FailedNodeException; @@ -95,8 +94,8 @@ public void performStateRecovery(final GatewayStateRecoveredListener listener) t } else if (nodeState.metadata().version() > electedGlobalState.version()) { electedGlobalState = nodeState.metadata(); } - for (final ObjectCursor cursor : nodeState.metadata().indices().values()) { - indices.addTo(cursor.value.getIndex(), 1); + for (final IndexMetadata cursor : nodeState.metadata().indices().values()) { + indices.addTo(cursor.getIndex(), 1); } } if (found < requiredAllocation) { diff --git a/server/src/main/java/org/opensearch/gateway/GatewayMetaState.java b/server/src/main/java/org/opensearch/gateway/GatewayMetaState.java index 9ac1248269589..f2ac2d56a9a26 100644 --- a/server/src/main/java/org/opensearch/gateway/GatewayMetaState.java +++ b/server/src/main/java/org/opensearch/gateway/GatewayMetaState.java @@ -32,7 +32,6 @@ package org.opensearch.gateway; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.lucene.store.AlreadyClosedException; @@ -55,7 +54,6 @@ import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.SetOnce; -import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.common.collect.Tuple; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.concurrent.AbstractRunnable; @@ -271,15 +269,15 @@ static Metadata upgradeMetadata( } private static boolean applyPluginUpgraders( - ImmutableOpenMap existingData, + final Map existingData, UnaryOperator> upgrader, Consumer removeData, BiConsumer putData ) { // collect current data Map existingMap = new HashMap<>(); - for (ObjectObjectCursor customCursor : existingData) { - existingMap.put(customCursor.key, customCursor.value); + for (Map.Entry customCursor : existingData.entrySet()) { + existingMap.put(customCursor.getKey(), customCursor.getValue()); } // upgrade global custom meta data Map upgradedCustoms = upgrader.apply(existingMap); diff --git a/server/src/main/java/org/opensearch/gateway/PersistedClusterStateService.java b/server/src/main/java/org/opensearch/gateway/PersistedClusterStateService.java index d874b4a9375b8..54c5d88918e45 100644 --- a/server/src/main/java/org/opensearch/gateway/PersistedClusterStateService.java +++ b/server/src/main/java/org/opensearch/gateway/PersistedClusterStateService.java @@ -31,7 +31,6 @@ package org.opensearch.gateway; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; @@ -745,8 +744,7 @@ private WriterStats updateMetadata(Metadata previouslyWrittenMetadata, Metadata } final Map indexMetadataVersionByUUID = new HashMap<>(previouslyWrittenMetadata.indices().size()); - for (ObjectCursor cursor : previouslyWrittenMetadata.indices().values()) { - final IndexMetadata indexMetadata = cursor.value; + for (final IndexMetadata indexMetadata : previouslyWrittenMetadata.indices().values()) { final Long previousValue = indexMetadataVersionByUUID.putIfAbsent( indexMetadata.getIndexUUID(), indexMetadata.getVersion() @@ -756,8 +754,7 @@ private WriterStats updateMetadata(Metadata previouslyWrittenMetadata, Metadata int numIndicesUpdated = 0; int numIndicesUnchanged = 0; - for (ObjectCursor cursor : metadata.indices().values()) { - final IndexMetadata indexMetadata = cursor.value; + for (final IndexMetadata indexMetadata : metadata.indices().values()) { final Long previousVersion = indexMetadataVersionByUUID.get(indexMetadata.getIndexUUID()); if (previousVersion == null || indexMetadata.getVersion() != previousVersion) { logger.trace( @@ -817,8 +814,7 @@ private WriterStats addMetadata(Metadata metadata) throws IOException { metadataIndexWriter.updateGlobalMetadata(globalMetadataDocument); } - for (ObjectCursor cursor : metadata.indices().values()) { - final IndexMetadata indexMetadata = cursor.value; + for (final IndexMetadata indexMetadata : metadata.indices().values()) { final Document indexMetadataDocument = makeIndexMetadataDocument(indexMetadata, documentBuffer); for (MetadataIndexWriter metadataIndexWriter : metadataIndexWriters) { metadataIndexWriter.updateIndexMetadataDocument(indexMetadataDocument, indexMetadata.getIndex()); diff --git a/server/src/main/java/org/opensearch/index/shard/RemoveCorruptedShardDataCommand.java b/server/src/main/java/org/opensearch/index/shard/RemoveCorruptedShardDataCommand.java index e2ff76e872a5e..bd4cbd6573961 100644 --- a/server/src/main/java/org/opensearch/index/shard/RemoveCorruptedShardDataCommand.java +++ b/server/src/main/java/org/opensearch/index/shard/RemoveCorruptedShardDataCommand.java @@ -144,8 +144,6 @@ protected void findAndProcessShardPath( final IndexMetadata indexMetadata; final int shardId; - final int fromNodeId; - final int toNodeId; if (options.has(folderOption)) { final Path path = getPath(folderOption.value(options)).getParent(); @@ -166,10 +164,7 @@ protected void findAndProcessShardPath( && NodeEnvironment.NODES_FOLDER.equals(shardParentParent.getParent().getParent().getFileName().toString()) // `nodes` check ) { shardId = Integer.parseInt(shardIdFileName); - fromNodeId = Integer.parseInt(nodeIdFileName); - toNodeId = fromNodeId + 1; indexMetadata = StreamSupport.stream(clusterState.metadata().indices().values().spliterator(), false) - .map(imd -> imd.value) .filter(imd -> imd.getIndexUUID().equals(indexUUIDFolderName)) .findFirst() .orElse(null); @@ -249,11 +244,9 @@ protected void dropCorruptMarkerFiles(Terminal terminal, Path path, Directory di ); } String[] files = directory.listAll(); - boolean found = false; for (String file : files) { if (file.startsWith(Store.CORRUPTED_MARKER_NAME_PREFIX)) { directory.deleteFile(file); - terminal.println("Deleted corrupt marker " + file + " from " + path); } } diff --git a/server/src/main/java/org/opensearch/rest/action/cat/RestTemplatesAction.java b/server/src/main/java/org/opensearch/rest/action/cat/RestTemplatesAction.java index 3e8c68391b9e3..c4d632f81cfcb 100644 --- a/server/src/main/java/org/opensearch/rest/action/cat/RestTemplatesAction.java +++ b/server/src/main/java/org/opensearch/rest/action/cat/RestTemplatesAction.java @@ -32,7 +32,6 @@ package org.opensearch.rest.action.cat; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.opensearch.action.admin.cluster.state.ClusterStateRequest; import org.opensearch.action.admin.cluster.state.ClusterStateResponse; import org.opensearch.client.node.NodeClient; @@ -112,8 +111,7 @@ protected Table getTableWithHeader(RestRequest request) { private Table buildTable(RestRequest request, ClusterStateResponse clusterStateResponse, String patternString) { Table table = getTableWithHeader(request); Metadata metadata = clusterStateResponse.getState().metadata(); - for (ObjectObjectCursor entry : metadata.templates()) { - IndexTemplateMetadata indexData = entry.value; + for (final IndexTemplateMetadata indexData : metadata.templates().values()) { if (patternString == null || Regex.simpleMatch(patternString, indexData.name())) { table.startRow(); table.addCell(indexData.name()); diff --git a/server/src/main/java/org/opensearch/snapshots/RestoreService.java b/server/src/main/java/org/opensearch/snapshots/RestoreService.java index 9e1fda3a06779..d4aef452a8cc2 100644 --- a/server/src/main/java/org/opensearch/snapshots/RestoreService.java +++ b/server/src/main/java/org/opensearch/snapshots/RestoreService.java @@ -646,18 +646,18 @@ public ClusterState execute(ClusterState currentState) { } if (metadata.templates() != null) { // TODO: Should all existing templates be deleted first? - for (ObjectCursor cursor : metadata.templates().values()) { - mdBuilder.put(cursor.value); + for (final IndexTemplateMetadata cursor : metadata.templates().values()) { + mdBuilder.put(cursor); } } if (metadata.customs() != null) { - for (ObjectObjectCursor cursor : metadata.customs()) { - if (RepositoriesMetadata.TYPE.equals(cursor.key) == false - && DataStreamMetadata.TYPE.equals(cursor.key) == false) { + for (final Map.Entry cursor : metadata.customs().entrySet()) { + if (RepositoriesMetadata.TYPE.equals(cursor.getKey()) == false + && DataStreamMetadata.TYPE.equals(cursor.getKey()) == false) { // Don't restore repositories while we are working with them // TODO: Should we restore them at the end? // Also, don't restore data streams here, we already added them to the metadata builder above - mdBuilder.putCustom(cursor.key, cursor.value); + mdBuilder.putCustom(cursor.getKey(), cursor.getValue()); } } } diff --git a/server/src/main/java/org/opensearch/snapshots/SnapshotUtils.java b/server/src/main/java/org/opensearch/snapshots/SnapshotUtils.java index 2be7cf9d4dbb3..e8115a97ac98a 100644 --- a/server/src/main/java/org/opensearch/snapshots/SnapshotUtils.java +++ b/server/src/main/java/org/opensearch/snapshots/SnapshotUtils.java @@ -31,11 +31,9 @@ package org.opensearch.snapshots; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.opensearch.action.support.IndicesOptions; import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; -import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.common.regex.Regex; import org.opensearch.index.IndexModule; import org.opensearch.index.IndexNotFoundException; @@ -162,7 +160,7 @@ public static List filterIndices(List availableIndices, String[] * @param repoName repo name for which the verification is being done */ public static void validateSnapshotsBackingAnyIndex( - ImmutableOpenMap metadata, + final Map metadata, List snapshotIds, String repoName ) { @@ -170,8 +168,7 @@ public static void validateSnapshotsBackingAnyIndex( final Set snapshotsToBeNotDeleted = new HashSet<>(); snapshotIds.forEach(snapshotId -> uuidToSnapshotId.put(snapshotId.getUUID(), snapshotId)); - for (ObjectCursor cursor : metadata.values()) { - IndexMetadata indexMetadata = cursor.value; + for (final IndexMetadata indexMetadata : metadata.values()) { String storeType = indexMetadata.getSettings().get(IndexModule.INDEX_STORE_TYPE_SETTING.getKey()); if (IndexModule.Type.REMOTE_SNAPSHOT.match(storeType)) { String snapshotId = indexMetadata.getSettings().get(IndexSettings.SEARCHABLE_SNAPSHOT_ID_UUID.getKey()); diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/reroute/ClusterRerouteResponseTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/reroute/ClusterRerouteResponseTests.java index d466e5bba4d20..5571eb020b9e0 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/reroute/ClusterRerouteResponseTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/reroute/ClusterRerouteResponseTests.java @@ -44,7 +44,6 @@ import org.opensearch.cluster.routing.allocation.command.AllocateReplicaAllocationCommand; import org.opensearch.cluster.routing.allocation.decider.Decision; import org.opensearch.common.Strings; -import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.common.settings.Settings; import org.opensearch.common.transport.TransportAddress; import org.opensearch.core.xcontent.ToXContent; @@ -73,9 +72,9 @@ public void testToXContent() throws IOException { .build() ) .build(); - ImmutableOpenMap.Builder openMapBuilder = ImmutableOpenMap.builder(); + final HashMap openMapBuilder = new HashMap<>(); openMapBuilder.put("index", indexMetadata); - Metadata metadata = Metadata.builder().indices(openMapBuilder.build()).build(); + Metadata metadata = Metadata.builder().indices(openMapBuilder).build(); ClusterState clusterState = ClusterState.builder(new ClusterName("test")).nodes(nodes).metadata(metadata).build(); RoutingExplanations routingExplanations = new RoutingExplanations(); diff --git a/server/src/test/java/org/opensearch/action/admin/indices/get/GetIndexResponseTests.java b/server/src/test/java/org/opensearch/action/admin/indices/get/GetIndexResponseTests.java index f712b93b409dc..225c435ee1106 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/get/GetIndexResponseTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/get/GetIndexResponseTests.java @@ -47,6 +47,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; +import java.util.Map; import java.util.List; import java.util.Locale; @@ -60,7 +62,7 @@ protected Writeable.Reader instanceReader() { @Override protected GetIndexResponse createTestInstance() { String[] indices = generateRandomStringArray(5, 5, false, false); - ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(); + final Map mappings = new HashMap<>(); ImmutableOpenMap.Builder> aliases = ImmutableOpenMap.builder(); ImmutableOpenMap.Builder settings = ImmutableOpenMap.builder(); ImmutableOpenMap.Builder defaultSettings = ImmutableOpenMap.builder(); @@ -90,13 +92,6 @@ protected GetIndexResponse createTestInstance() { dataStreams.put(index, randomAlphaOfLength(5).toLowerCase(Locale.ROOT)); } } - return new GetIndexResponse( - indices, - mappings.build(), - aliases.build(), - settings.build(), - defaultSettings.build(), - dataStreams.build() - ); + return new GetIndexResponse(indices, mappings, aliases.build(), settings.build(), defaultSettings.build(), dataStreams.build()); } } diff --git a/server/src/test/java/org/opensearch/action/admin/indices/mapping/get/GetMappingsResponseTests.java b/server/src/test/java/org/opensearch/action/admin/indices/mapping/get/GetMappingsResponseTests.java index 5dd05789429bf..99a4315b3acee 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/mapping/get/GetMappingsResponseTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/mapping/get/GetMappingsResponseTests.java @@ -33,7 +33,6 @@ package org.opensearch.action.admin.indices.mapping.get; import org.opensearch.cluster.metadata.MappingMetadata; -import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.Writeable; import org.opensearch.index.mapper.MapperService; import org.opensearch.test.AbstractWireSerializingTestCase; @@ -57,11 +56,11 @@ protected Writeable.Reader instanceReader() { } private static GetMappingsResponse mutate(GetMappingsResponse original) { - ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(original.mappings()); - String indexKey = original.mappings().keys().iterator().next().value; + final Map builder = new HashMap<>(original.mappings()); + String indexKey = original.mappings().keySet().iterator().next(); builder.put(indexKey + "1", createMappingsForIndex()); - return new GetMappingsResponse(builder.build()); + return new GetMappingsResponse(builder); } @Override @@ -84,9 +83,9 @@ public static MappingMetadata createMappingsForIndex() { @Override protected GetMappingsResponse createTestInstance() { - ImmutableOpenMap.Builder indexBuilder = ImmutableOpenMap.builder(); + final Map indexBuilder = new HashMap<>(); indexBuilder.put("index-" + randomAlphaOfLength(5), createMappingsForIndex()); - GetMappingsResponse resp = new GetMappingsResponse(indexBuilder.build()); + GetMappingsResponse resp = new GetMappingsResponse(indexBuilder); logger.debug("--> created: {}", resp); return resp; } diff --git a/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionIngestTests.java b/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionIngestTests.java index 5b96c2a71dbf8..5881c72587756 100644 --- a/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionIngestTests.java +++ b/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionIngestTests.java @@ -82,6 +82,7 @@ import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.concurrent.ExecutorService; @@ -245,32 +246,30 @@ public void setupAction() { when(state.getNodes()).thenReturn(nodes); Metadata metadata = Metadata.builder() .indices( - ImmutableOpenMap.builder() - .putAll( - MapBuilder.newMapBuilder() - .put( - WITH_DEFAULT_PIPELINE, - IndexMetadata.builder(WITH_DEFAULT_PIPELINE) - .settings( - settings(Version.CURRENT).put(IndexSettings.DEFAULT_PIPELINE.getKey(), "default_pipeline").build() - ) - .putAlias(AliasMetadata.builder(WITH_DEFAULT_PIPELINE_ALIAS).build()) - .numberOfShards(1) - .numberOfReplicas(1) - .build() - ) - .put( - ".system", - IndexMetadata.builder(".system") - .settings(settings(Version.CURRENT)) - .system(true) - .numberOfShards(1) - .numberOfReplicas(0) - .build() - ) - .map() - ) - .build() + new HashMap<>( + MapBuilder.newMapBuilder() + .put( + WITH_DEFAULT_PIPELINE, + IndexMetadata.builder(WITH_DEFAULT_PIPELINE) + .settings( + settings(Version.CURRENT).put(IndexSettings.DEFAULT_PIPELINE.getKey(), "default_pipeline").build() + ) + .putAlias(AliasMetadata.builder(WITH_DEFAULT_PIPELINE_ALIAS).build()) + .numberOfShards(1) + .numberOfReplicas(1) + .build() + ) + .put( + ".system", + IndexMetadata.builder(".system") + .settings(settings(Version.CURRENT)) + .system(true) + .numberOfShards(1) + .numberOfReplicas(0) + .build() + ) + .map() + ) ) .build(); when(state.getMetadata()).thenReturn(metadata); @@ -659,7 +658,7 @@ public void testFindDefaultPipelineFromTemplateMatch() { Exception exception = new Exception("fake exception"); ClusterState state = clusterService.state(); - ImmutableOpenMap.Builder templateMetadataBuilder = ImmutableOpenMap.builder(); + final Map templateMetadataBuilder = new HashMap<>(); templateMetadataBuilder.put( "template1", IndexTemplateMetadata.builder("template1") @@ -692,9 +691,9 @@ public void testFindDefaultPipelineFromTemplateMatch() { Metadata metadata = mock(Metadata.class); when(state.metadata()).thenReturn(metadata); when(state.getMetadata()).thenReturn(metadata); - when(metadata.templates()).thenReturn(templateMetadataBuilder.build()); - when(metadata.getTemplates()).thenReturn(templateMetadataBuilder.build()); - when(metadata.indices()).thenReturn(ImmutableOpenMap.of()); + when(metadata.templates()).thenReturn(templateMetadataBuilder); + when(metadata.getTemplates()).thenReturn(templateMetadataBuilder); + when(metadata.indices()).thenReturn(Map.of()); IndexRequest indexRequest = new IndexRequest("missing_index").id("id"); indexRequest.source(emptyMap()); diff --git a/server/src/test/java/org/opensearch/cluster/ClusterChangedEventTests.java b/server/src/test/java/org/opensearch/cluster/ClusterChangedEventTests.java index df7c10cd1acd8..9a5866a21dab6 100644 --- a/server/src/test/java/org/opensearch/cluster/ClusterChangedEventTests.java +++ b/server/src/test/java/org/opensearch/cluster/ClusterChangedEventTests.java @@ -32,8 +32,6 @@ package org.opensearch.cluster; -import com.carrotsearch.hppc.cursors.ObjectCursor; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.opensearch.Version; import org.opensearch.cluster.block.ClusterBlocks; import org.opensearch.cluster.metadata.IndexGraveyard; @@ -57,6 +55,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -411,9 +410,9 @@ private static ClusterState nextState(final ClusterState previousState, List customMetadata : previousState.metadata().customs()) { - if (customMetadata.value instanceof TestCustomMetadata) { - metadataBuilder.removeCustom(customMetadata.key); + for (Map.Entry customMetadata : previousState.metadata().customs().entrySet()) { + if (customMetadata.getValue() instanceof TestCustomMetadata) { + metadataBuilder.removeCustom(customMetadata.getKey()); } } for (TestCustomMetadata testCustomMetadata : customMetadataList) { @@ -550,8 +549,8 @@ private static IndexMetadata createIndexMetadata(final Index index, final long v // Create the routing table for a cluster state. private static RoutingTable createRoutingTable(final long version, final Metadata metadata) { final RoutingTable.Builder builder = RoutingTable.builder().version(version); - for (ObjectCursor cursor : metadata.indices().values()) { - builder.addAsNew(cursor.value); + for (final IndexMetadata cursor : metadata.indices().values()) { + builder.addAsNew(cursor); } return builder.build(); } @@ -582,7 +581,7 @@ private static ClusterState executeIndicesChangesTest( ) { final int numAdd = randomIntBetween(0, 5); // add random # of indices to the next cluster state final List stateIndices = new ArrayList<>(); - for (Iterator iter = previousState.metadata().indices().valuesIt(); iter.hasNext();) { + for (Iterator iter = previousState.metadata().indices().values().iterator(); iter.hasNext();) { stateIndices.add(iter.next().getIndex()); } final int numDel; diff --git a/server/src/test/java/org/opensearch/cluster/metadata/MetadataCreateIndexServiceTests.java b/server/src/test/java/org/opensearch/cluster/metadata/MetadataCreateIndexServiceTests.java index 21fab839fe5c6..b9b5a08096619 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/MetadataCreateIndexServiceTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/MetadataCreateIndexServiceTests.java @@ -59,7 +59,6 @@ import org.opensearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.Strings; -import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.IndexScopedSettings; @@ -812,9 +811,9 @@ public void testAggregateSettingsAppliesSettingsFromTemplatesAndRequest() { IndexTemplateMetadata templateMetadata = addMatchingTemplate(builder -> { builder.settings(Settings.builder().put("template_setting", "value1")); }); - ImmutableOpenMap.Builder templatesBuilder = ImmutableOpenMap.builder(); + final Map templatesBuilder = new HashMap<>(); templatesBuilder.put("template_1", templateMetadata); - Metadata metadata = new Metadata.Builder().templates(templatesBuilder.build()).build(); + Metadata metadata = new Metadata.Builder().templates(templatesBuilder).build(); ClusterState clusterState = ClusterState.builder(org.opensearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) .metadata(metadata) .build(); diff --git a/server/src/test/java/org/opensearch/cluster/metadata/MetadataTests.java b/server/src/test/java/org/opensearch/cluster/metadata/MetadataTests.java index cb675cb9308af..8c2422c7dcf3b 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/MetadataTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/MetadataTests.java @@ -659,19 +659,16 @@ public void testFindMappings() throws IOException { .build(); { - ImmutableOpenMap mappings = metadata.findMappings(Strings.EMPTY_ARRAY, MapperPlugin.NOOP_FIELD_FILTER); + final Map mappings = metadata.findMappings(Strings.EMPTY_ARRAY, MapperPlugin.NOOP_FIELD_FILTER); assertEquals(0, mappings.size()); } { - ImmutableOpenMap mappings = metadata.findMappings( - new String[] { "index1" }, - MapperPlugin.NOOP_FIELD_FILTER - ); + final Map mappings = metadata.findMappings(new String[] { "index1" }, MapperPlugin.NOOP_FIELD_FILTER); assertEquals(1, mappings.size()); assertIndexMappingsNotFiltered(mappings, "index1"); } { - ImmutableOpenMap mappings = metadata.findMappings( + final Map mappings = metadata.findMappings( new String[] { "index1", "index2" }, MapperPlugin.NOOP_FIELD_FILTER ); @@ -701,15 +698,12 @@ public void testFindMappingsNoOpFilters() throws IOException { .build(); { - ImmutableOpenMap mappings = metadata.findMappings( - new String[] { "index1" }, - MapperPlugin.NOOP_FIELD_FILTER - ); + final Map mappings = metadata.findMappings(new String[] { "index1" }, MapperPlugin.NOOP_FIELD_FILTER); MappingMetadata mappingMetadata = mappings.get("index1"); assertSame(originalMappingMetadata, mappingMetadata); } { - ImmutableOpenMap mappings = metadata.findMappings( + final Map mappings = metadata.findMappings( new String[] { "index1" }, index -> field -> randomBoolean() ); @@ -764,21 +758,18 @@ public void testFindMappingsWithFilters() throws IOException { .build(); { - ImmutableOpenMap mappings = metadata.findMappings( - new String[] { "index1", "index2", "index3" }, - index -> { - if (index.equals("index1")) { - return field -> field.startsWith("name.") == false - && field.startsWith("properties.key.") == false - && field.equals("age") == false - && field.equals("address.location") == false; - } - if (index.equals("index2")) { - return field -> false; - } - return MapperPlugin.NOOP_FIELD_PREDICATE; + final Map mappings = metadata.findMappings(new String[] { "index1", "index2", "index3" }, index -> { + if (index.equals("index1")) { + return field -> field.startsWith("name.") == false + && field.startsWith("properties.key.") == false + && field.equals("age") == false + && field.equals("address.location") == false; } - ); + if (index.equals("index2")) { + return field -> false; + } + return MapperPlugin.NOOP_FIELD_PREDICATE; + }); assertIndexMappingsNoFields(mappings, "index2"); assertIndexMappingsNotFiltered(mappings, "index3"); @@ -825,7 +816,7 @@ public void testFindMappingsWithFilters() throws IOException { } { - ImmutableOpenMap mappings = metadata.findMappings( + final Map mappings = metadata.findMappings( new String[] { "index1", "index2", "index3" }, index -> field -> (index.equals("index3") && field.endsWith("keyword")) ); @@ -860,7 +851,7 @@ public void testFindMappingsWithFilters() throws IOException { } { - ImmutableOpenMap mappings = metadata.findMappings( + final Map mappings = metadata.findMappings( new String[] { "index1", "index2", "index3" }, index -> field -> (index.equals("index2")) ); @@ -881,7 +872,7 @@ private static IndexMetadata.Builder buildIndexMetadata(String name, String alia } @SuppressWarnings("unchecked") - private static void assertIndexMappingsNoFields(ImmutableOpenMap mappings, String index) { + private static void assertIndexMappingsNoFields(final Map mappings, String index) { MappingMetadata docMapping = mappings.get(index); assertNotNull(docMapping); Map sourceAsMap = docMapping.getSourceAsMap(); @@ -893,7 +884,7 @@ private static void assertIndexMappingsNoFields(ImmutableOpenMap mappings, String index) { + private static void assertIndexMappingsNotFiltered(final Map mappings, String index) { MappingMetadata docMapping = mappings.get(index); assertNotNull(docMapping); @@ -1050,10 +1041,9 @@ public void testBuilderRejectsNullCustom() { public void testBuilderRejectsNullInCustoms() { final Metadata.Builder builder = Metadata.builder(); final String key = randomAlphaOfLength(10); - final ImmutableOpenMap.Builder mapBuilder = ImmutableOpenMap.builder(); + final Map mapBuilder = new HashMap<>(); mapBuilder.put(key, null); - final ImmutableOpenMap map = mapBuilder.build(); - assertThat(expectThrows(NullPointerException.class, () -> builder.customs(map)).getMessage(), containsString(key)); + assertThat(expectThrows(NullPointerException.class, () -> builder.customs(mapBuilder)).getMessage(), containsString(key)); } public void testBuilderRejectsDataStreamThatConflictsWithIndex() { diff --git a/server/src/test/java/org/opensearch/cluster/metadata/TemplateUpgradeServiceTests.java b/server/src/test/java/org/opensearch/cluster/metadata/TemplateUpgradeServiceTests.java index d3e47c3e42f25..1219e684ce5ac 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/TemplateUpgradeServiceTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/TemplateUpgradeServiceTests.java @@ -48,7 +48,6 @@ import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.common.collect.Tuple; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.test.OpenSearchTestCase; @@ -345,7 +344,7 @@ void upgradeTemplates(Map changes, Set deletions @Override Optional, Set>> calculateTemplateChanges( - ImmutableOpenMap templates + final Map templates ) { final Optional, Set>> ans = super.calculateTemplateChanges(templates); calculateInvocation.release(); diff --git a/server/src/test/java/org/opensearch/cluster/routing/allocation/AddIncrementallyTests.java b/server/src/test/java/org/opensearch/cluster/routing/allocation/AddIncrementallyTests.java index c1959a96bffcd..c2be6dfa60b51 100644 --- a/server/src/test/java/org/opensearch/cluster/routing/allocation/AddIncrementallyTests.java +++ b/server/src/test/java/org/opensearch/cluster/routing/allocation/AddIncrementallyTests.java @@ -294,8 +294,8 @@ private ClusterState initCluster( Metadata metadata = metadataBuilder.build(); - for (ObjectCursor cursor : metadata.indices().values()) { - routingTableBuilder.addAsNew(cursor.value); + for (final IndexMetadata cursor : metadata.indices().values()) { + routingTableBuilder.addAsNew(cursor); } RoutingTable initialRoutingTable = routingTableBuilder.build(); diff --git a/server/src/test/java/org/opensearch/cluster/routing/allocation/BalanceConfigurationTests.java b/server/src/test/java/org/opensearch/cluster/routing/allocation/BalanceConfigurationTests.java index a163897bf508d..7a08f0e75faf0 100644 --- a/server/src/test/java/org/opensearch/cluster/routing/allocation/BalanceConfigurationTests.java +++ b/server/src/test/java/org/opensearch/cluster/routing/allocation/BalanceConfigurationTests.java @@ -655,8 +655,8 @@ private ClusterState initCluster( } Metadata metadata = metadataBuilder.build(); - for (ObjectCursor cursor : metadata.indices().values()) { - routingTableBuilder.addAsNew(cursor.value); + for (final IndexMetadata cursor : metadata.indices().values()) { + routingTableBuilder.addAsNew(cursor); } RoutingTable initialRoutingTable = routingTableBuilder.build(); @@ -910,8 +910,8 @@ public ShardAllocationDecision decideShardAllocation(ShardRouting shard, Routing .numberOfReplicas(1); metadataBuilder = metadataBuilder.put(indexMeta); Metadata metadata = metadataBuilder.build(); - for (ObjectCursor cursor : metadata.indices().values()) { - routingTableBuilder.addAsNew(cursor.value); + for (final IndexMetadata cursor : metadata.indices().values()) { + routingTableBuilder.addAsNew(cursor); } RoutingTable routingTable = routingTableBuilder.build(); DiscoveryNodes.Builder nodes = DiscoveryNodes.builder(); diff --git a/server/src/test/java/org/opensearch/cluster/routing/allocation/ThrottlingAllocationTests.java b/server/src/test/java/org/opensearch/cluster/routing/allocation/ThrottlingAllocationTests.java index 47111fae31d28..ab6042513af94 100644 --- a/server/src/test/java/org/opensearch/cluster/routing/allocation/ThrottlingAllocationTests.java +++ b/server/src/test/java/org/opensearch/cluster/routing/allocation/ThrottlingAllocationTests.java @@ -33,7 +33,6 @@ package org.opensearch.cluster.routing.allocation; import com.carrotsearch.hppc.IntHashSet; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.Version; @@ -774,9 +773,9 @@ private ClusterState createRecoveryStateAndInitializeAllocations( Snapshot snapshot = new Snapshot("repo", new SnapshotId("snap", "randomId")); Set snapshotIndices = new HashSet<>(); String restoreUUID = UUIDs.randomBase64UUID(); - for (ObjectCursor cursor : metadata.indices().values()) { - Index index = cursor.value.getIndex(); - IndexMetadata.Builder indexMetadataBuilder = IndexMetadata.builder(cursor.value); + for (final IndexMetadata cursor : metadata.indices().values()) { + Index index = cursor.getIndex(); + IndexMetadata.Builder indexMetadataBuilder = IndexMetadata.builder(cursor); final int recoveryType = inputRecoveryType == null ? randomInt(5) : inputRecoveryType.intValue(); if (recoveryType <= 4) { diff --git a/server/src/test/java/org/opensearch/cluster/routing/allocation/decider/EnableAllocationShortCircuitTests.java b/server/src/test/java/org/opensearch/cluster/routing/allocation/decider/EnableAllocationShortCircuitTests.java index 6a1b3c912ad4a..d688c5a7edfb3 100644 --- a/server/src/test/java/org/opensearch/cluster/routing/allocation/decider/EnableAllocationShortCircuitTests.java +++ b/server/src/test/java/org/opensearch/cluster/routing/allocation/decider/EnableAllocationShortCircuitTests.java @@ -135,7 +135,7 @@ public void testRebalancingSkippedIfDisabled() { public void testRebalancingSkippedIfDisabledIncludingOnSpecificIndices() { ClusterState clusterState = createClusterStateWithAllShardsAssigned(); - final IndexMetadata indexMetadata = randomFrom(clusterState.metadata().indices().values().toArray(IndexMetadata.class)); + final IndexMetadata indexMetadata = randomFrom(clusterState.metadata().indices().values().toArray(new IndexMetadata[0])); clusterState = ClusterState.builder(clusterState) .metadata( Metadata.builder(clusterState.metadata()) @@ -162,7 +162,7 @@ public void testRebalancingSkippedIfDisabledIncludingOnSpecificIndices() { public void testRebalancingAttemptedIfDisabledButOverridenOnSpecificIndices() { ClusterState clusterState = createClusterStateWithAllShardsAssigned(); - final IndexMetadata indexMetadata = randomFrom(clusterState.metadata().indices().values().toArray(IndexMetadata.class)); + final IndexMetadata indexMetadata = randomFrom(clusterState.metadata().indices().values().toArray(new IndexMetadata[0])); clusterState = ClusterState.builder(clusterState) .metadata( Metadata.builder(clusterState.metadata()) diff --git a/server/src/test/java/org/opensearch/gateway/DanglingIndicesStateTests.java b/server/src/test/java/org/opensearch/gateway/DanglingIndicesStateTests.java index 9534a53dbe77f..1934307f88792 100644 --- a/server/src/test/java/org/opensearch/gateway/DanglingIndicesStateTests.java +++ b/server/src/test/java/org/opensearch/gateway/DanglingIndicesStateTests.java @@ -37,7 +37,6 @@ import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.cluster.metadata.Metadata; import org.opensearch.cluster.service.ClusterService; -import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.common.settings.Settings; import org.opensearch.env.NodeEnvironment; import org.opensearch.index.Index; @@ -47,6 +46,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -233,9 +233,8 @@ public void testDanglingIndicesNotImportedWhenIndexNameIsAlreadyUsed() throws Ex IndexMetadata existingIndex = IndexMetadata.builder("test_index").settings(existingSettings).build(); metaStateService.writeIndex("test_write", existingIndex); - final ImmutableOpenMap indices = ImmutableOpenMap.builder() - .fPut(dangledIndex.getIndex().getName(), existingIndex) - .build(); + final Map indices = new HashMap<>(); + indices.put(dangledIndex.getIndex().getName(), existingIndex); final Metadata metadata = Metadata.builder().indices(indices).build(); // All dangling indices should be found... diff --git a/server/src/test/java/org/opensearch/index/mapper/FieldFilterMapperPluginTests.java b/server/src/test/java/org/opensearch/index/mapper/FieldFilterMapperPluginTests.java index 1e5a212c59825..2c825401ab94a 100644 --- a/server/src/test/java/org/opensearch/index/mapper/FieldFilterMapperPluginTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/FieldFilterMapperPluginTests.java @@ -40,7 +40,6 @@ import org.opensearch.action.fieldcaps.FieldCapabilitiesRequest; import org.opensearch.action.fieldcaps.FieldCapabilitiesResponse; import org.opensearch.cluster.metadata.MappingMetadata; -import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.common.xcontent.XContentType; import org.opensearch.indices.IndicesModule; import org.opensearch.plugins.MapperPlugin; @@ -166,7 +165,7 @@ private static void assertFieldMappings( assertEquals("Some unexpected fields were returned: " + fields.keySet(), 0, fields.size()); } - private void assertExpectedMappings(ImmutableOpenMap mappings) { + private void assertExpectedMappings(Map mappings) { assertEquals(2, mappings.size()); assertNotFiltered(mappings.get("index1")); MappingMetadata filtered = mappings.get("filtered"); diff --git a/server/src/test/java/org/opensearch/indices/ShardLimitValidatorTests.java b/server/src/test/java/org/opensearch/indices/ShardLimitValidatorTests.java index 8edd62438fb1d..ef3e85b0da775 100644 --- a/server/src/test/java/org/opensearch/indices/ShardLimitValidatorTests.java +++ b/server/src/test/java/org/opensearch/indices/ShardLimitValidatorTests.java @@ -331,7 +331,7 @@ public void testNonSystemIndexOpeningFails() { counts.getFailingIndexReplicas() ); - Index[] indices = Arrays.stream(state.metadata().indices().values().toArray(IndexMetadata.class)) + Index[] indices = Arrays.stream(state.metadata().indices().values().toArray(new IndexMetadata[0])) .map(IndexMetadata::getIndex) .collect(Collectors.toList()) .toArray(new Index[2]); @@ -373,7 +373,7 @@ public void testSystemIndexOpeningSucceeds() { counts.getFailingIndexReplicas() ); - Index[] indices = Arrays.stream(state.metadata().indices().values().toArray(IndexMetadata.class)) + Index[] indices = Arrays.stream(state.metadata().indices().values().toArray(new IndexMetadata[0])) .map(IndexMetadata::getIndex) .collect(Collectors.toList()) .toArray(new Index[2]); @@ -401,7 +401,7 @@ public void testDotIndexOpeningSucceeds() { counts.getFailingIndexReplicas() ); - Index[] indices = Arrays.stream(state.metadata().indices().values().toArray(IndexMetadata.class)) + Index[] indices = Arrays.stream(state.metadata().indices().values().toArray(new IndexMetadata[0])) .map(IndexMetadata::getIndex) .collect(Collectors.toList()) .toArray(new Index[2]); @@ -429,7 +429,7 @@ public void testDotIndexOpeningFails() { counts.getFailingIndexReplicas() ); - Index[] indices = Arrays.stream(state.metadata().indices().values().toArray(IndexMetadata.class)) + Index[] indices = Arrays.stream(state.metadata().indices().values().toArray(new IndexMetadata[0])) .map(IndexMetadata::getIndex) .collect(Collectors.toList()) .toArray(new Index[2]); @@ -472,7 +472,7 @@ public void testDataStreamIndexOpeningFails() { counts.getFailingIndexReplicas() ); - Index[] indices = Arrays.stream(state.metadata().indices().values().toArray(IndexMetadata.class)) + Index[] indices = Arrays.stream(state.metadata().indices().values().toArray(new IndexMetadata[0])) .map(IndexMetadata::getIndex) .collect(Collectors.toList()) .toArray(new Index[2]); diff --git a/server/src/test/java/org/opensearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java b/server/src/test/java/org/opensearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java index 6506bff9ad60e..6080233c3a759 100644 --- a/server/src/test/java/org/opensearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java +++ b/server/src/test/java/org/opensearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java @@ -416,7 +416,7 @@ public ClusterState randomlyUpdateClusterState( // randomly delete indices Set indicesToDelete = new HashSet<>(); int numberOfIndicesToDelete = randomInt(Math.min(2, state.metadata().indices().size())); - for (String index : randomSubsetOf(numberOfIndicesToDelete, state.metadata().indices().keys().toArray(String.class))) { + for (String index : randomSubsetOf(numberOfIndicesToDelete, state.metadata().indices().keySet().toArray(new String[0]))) { indicesToDelete.add(state.metadata().index(index).getIndex().getName()); } if (indicesToDelete.isEmpty() == false) { @@ -429,14 +429,14 @@ public ClusterState randomlyUpdateClusterState( // randomly close indices int numberOfIndicesToClose = randomInt(Math.min(1, state.metadata().indices().size())); - for (String index : randomSubsetOf(numberOfIndicesToClose, state.metadata().indices().keys().toArray(String.class))) { + for (String index : randomSubsetOf(numberOfIndicesToClose, state.metadata().indices().keySet().toArray(new String[0]))) { CloseIndexRequest closeIndexRequest = new CloseIndexRequest(state.metadata().index(index).getIndex().getName()); state = cluster.closeIndices(state, closeIndexRequest); } // randomly open indices int numberOfIndicesToOpen = randomInt(Math.min(1, state.metadata().indices().size())); - for (String index : randomSubsetOf(numberOfIndicesToOpen, state.metadata().indices().keys().toArray(String.class))) { + for (String index : randomSubsetOf(numberOfIndicesToOpen, state.metadata().indices().keySet().toArray(new String[0]))) { OpenIndexRequest openIndexRequest = new OpenIndexRequest(state.metadata().index(index).getIndex().getName()); state = cluster.openIndices(state, openIndexRequest); } @@ -445,7 +445,7 @@ public ClusterState randomlyUpdateClusterState( Set indicesToUpdate = new HashSet<>(); boolean containsClosedIndex = false; int numberOfIndicesToUpdate = randomInt(Math.min(2, state.metadata().indices().size())); - for (String index : randomSubsetOf(numberOfIndicesToUpdate, state.metadata().indices().keys().toArray(String.class))) { + for (String index : randomSubsetOf(numberOfIndicesToUpdate, state.metadata().indices().keySet().toArray(new String[0]))) { indicesToUpdate.add(state.metadata().index(index).getIndex().getName()); if (state.metadata().index(index).getState() == IndexMetadata.State.CLOSE) { containsClosedIndex = true; diff --git a/server/src/test/java/org/opensearch/snapshots/SnapshotUtilsTests.java b/server/src/test/java/org/opensearch/snapshots/SnapshotUtilsTests.java index 4a378acc39b6d..417bc4d0421a0 100644 --- a/server/src/test/java/org/opensearch/snapshots/SnapshotUtilsTests.java +++ b/server/src/test/java/org/opensearch/snapshots/SnapshotUtilsTests.java @@ -35,7 +35,6 @@ import org.opensearch.action.support.IndicesOptions; import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.cluster.metadata.Metadata; -import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.common.settings.Settings; import org.opensearch.index.Index; import org.opensearch.index.IndexModule; @@ -44,6 +43,7 @@ import java.util.Arrays; import java.util.List; +import java.util.Map; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_VERSION_CREATED; @@ -114,7 +114,7 @@ public void testValidateSnapshotsBackingAnyIndexThrowsException() { ); } - private static ImmutableOpenMap getIndexMetadata(SnapshotId snapshotId, String repoName) { + private static Map getIndexMetadata(SnapshotId snapshotId, String repoName) { final String index = "test-index"; Snapshot snapshot = new Snapshot(repoName, snapshotId); final Metadata.Builder builder = Metadata.builder();