From e3d7163d2b1d7838cb02eb197d4ed8e2b98eed7a Mon Sep 17 00:00:00 2001 From: Nicholas Walter Knize Date: Wed, 5 Apr 2023 12:32:52 -0500 Subject: [PATCH 1/3] [Refactor] ImmutableOpenMap and ImmutableOpenIntMap to core lib This commit refactors the heavily dependent ImmutableOpenMap and ImmutableOpenIntMap from the :server module to the :core library in preparation for refactoring other core foundation classes (e.g., StreamInput, StreamOutput, Version). It also encapsulates the hppc library dependency by implementing the java Iterator API contracts in place of the hppc specific ObjectObjectCursor and IntObjectCursor iterators and cuts over usage to the java.util.iterator. Microbenchmarks are included to compare cpu and memory allocations. Signed-off-by: Nicholas Walter Knize --- .../collect/ImmutableOpenMapBenchmark.java | 72 +++++++ .../client/indices/IndexTemplateMetadata.java | 2 +- .../client/AbstractResponseTestCase.java | 2 +- .../client/indices/GetIndexResponseTests.java | 2 +- libs/core/build.gradle | 11 + libs/core/licenses/hppc-0.8.1.jar.sha1 | 1 + libs/core/licenses/hppc-LICENSE.txt | 203 ++++++++++++++++++ libs/core/licenses/hppc-NOTICE.txt | 11 + .../common/collect/ImmutableOpenIntMap.java | 93 +++++++- .../common/collect/ImmutableOpenMap.java | 91 +++++++- .../core/common/collect/package-info.java | 10 + .../opensearch/core/common/package-info.java | 15 ++ .../admin/indices/create/ShrinkIndexIT.java | 2 +- .../action/admin/indices/get/GetIndexIT.java | 7 +- .../shards/IndicesShardStoreRequestIT.java | 23 +- .../opensearch/aliases/IndexAliasesIT.java | 5 +- .../cluster/ClusterStateDiffIT.java | 2 +- .../cluster/routing/PrimaryAllocationIT.java | 10 +- .../RemoveCorruptedShardDataCommandIT.java | 17 +- .../index/store/CorruptedFileIT.java | 10 +- .../SegmentReplicationAllocationIT.java | 14 +- .../search/SearchWeightedRoutingIT.java | 2 +- .../TransportClusterRerouteAction.java | 4 +- .../restore/RestoreClusterStateListener.java | 2 +- .../TransportSnapshotsStatusAction.java | 19 +- .../state/TransportClusterStateAction.java | 7 +- .../cluster/stats/ClusterStatsIndices.java | 11 +- .../alias/TransportIndicesAliasesAction.java | 2 +- .../indices/alias/get/GetAliasesResponse.java | 2 +- .../alias/get/TransportGetAliasesAction.java | 2 +- .../admin/indices/get/GetIndexResponse.java | 29 ++- .../indices/get/TransportGetIndexAction.java | 2 +- .../settings/get/GetSettingsResponse.java | 13 +- .../get/TransportGetSettingsAction.java | 2 +- .../shards/IndicesShardStoresResponse.java | 23 +- .../TransportIndicesShardStoresAction.java | 4 +- .../action/support/ActiveShardCount.java | 7 +- .../TransportBroadcastReplicationAction.java | 9 +- .../support/tasks/TransportTasksAction.java | 2 +- .../org/opensearch/cluster/ClusterState.java | 21 +- .../org/opensearch/cluster/DiffableUtils.java | 30 ++- .../opensearch/cluster/RestoreInProgress.java | 10 +- .../cluster/SnapshotsInProgress.java | 21 +- .../ClusterAwarenessAttributesHealth.java | 2 +- .../cluster/block/ClusterBlocks.java | 21 +- .../cluster/metadata/IndexMetadata.java | 34 ++- .../metadata/IndexNameExpressionResolver.java | 2 +- .../metadata/IndexTemplateMetadata.java | 9 +- .../opensearch/cluster/metadata/Metadata.java | 4 +- .../metadata/MetadataDeleteIndexService.java | 2 +- .../metadata/MetadataIndexStateService.java | 11 +- .../SystemIndexMetadataUpgradeService.java | 2 +- .../cluster/node/DiscoveryNodes.java | 21 +- .../cluster/routing/IndexRoutingTable.java | 8 +- .../cluster/routing/RoutingTable.java | 7 +- .../routing/allocation/AllocationService.java | 2 +- .../routing/allocation/RoutingAllocation.java | 2 +- .../common/io/stream/StreamInput.java | 2 +- .../common/io/stream/StreamOutput.java | 9 +- .../opensearch/gateway/AsyncShardFetch.java | 5 +- .../opensearch/gateway/GatewayAllocator.java | 6 +- .../opensearch/index/mapper/FieldMapper.java | 13 +- .../admin/indices/RestGetAliasesAction.java | 18 +- .../rest/action/cat/RestAliasAction.java | 8 +- .../search/internal/ShardSearchRequest.java | 2 +- .../snapshots/EmptySnapshotsInfoService.java | 2 +- .../InFlightShardSnapshotStates.java | 13 +- .../InternalSnapshotsInfoService.java | 2 +- .../opensearch/snapshots/RestoreService.java | 13 +- .../snapshots/SnapshotShardSizeInfo.java | 2 +- .../snapshots/SnapshotShardsService.java | 17 +- .../snapshots/SnapshotsService.java | 49 +++-- .../alias/get/GetAliasesResponseTests.java | 2 +- .../get/TransportGetAliasesActionTests.java | 2 +- .../DeleteDataStreamRequestTests.java | 2 +- .../indices/get/GetIndexResponseTests.java | 2 +- .../get/GetSettingsResponseTests.java | 2 +- .../IndicesShardStoreResponseTests.java | 4 +- .../bulk/TransportBulkActionIngestTests.java | 2 +- .../opensearch/cluster/ClusterStateTests.java | 2 +- .../cluster/block/ClusterBlockTests.java | 2 +- .../health/ClusterStateHealthTests.java | 21 +- .../cluster/metadata/IndexMetadataTests.java | 2 +- .../metadata/IndexTemplateMetadataTests.java | 2 +- .../MetadataDeleteIndexServiceTests.java | 2 +- .../MetadataIndexStateServiceTests.java | 2 +- .../cluster/metadata/MetadataTests.java | 2 +- .../allocation/BalanceConfigurationTests.java | 12 +- .../NodeVersionAllocationDeciderTests.java | 2 +- .../allocation/ThrottlingAllocationTests.java | 2 +- .../decider/DiskThresholdDeciderTests.java | 2 +- ...storeInProgressAllocationDeciderTests.java | 2 +- .../ClusterSerializationTests.java | 2 +- .../cluster/serialization/DiffableTests.java | 4 +- .../common/io/stream/BytesStreamsTests.java | 2 +- .../gateway/PrimaryShardAllocatorTests.java | 2 +- .../indices/ShardLimitValidatorTests.java | 2 +- .../indices/RestGetAliasesActionTests.java | 2 +- .../InternalSnapshotsInfoServiceTests.java | 2 +- ...SnapshotsInProgressSerializationTests.java | 2 +- .../snapshots/SnapshotsServiceTests.java | 2 +- .../cluster/OpenSearchAllocationTestCase.java | 2 +- .../opensearch/test/InternalTestCluster.java | 18 +- .../test/hamcrest/CollectionAssertions.java | 2 +- .../test/hamcrest/CollectionMatchers.java | 2 +- 105 files changed, 854 insertions(+), 376 deletions(-) create mode 100644 benchmarks/src/main/java/org/opensearch/benchmark/core/common/collect/ImmutableOpenMapBenchmark.java create mode 100644 libs/core/licenses/hppc-0.8.1.jar.sha1 create mode 100644 libs/core/licenses/hppc-LICENSE.txt create mode 100644 libs/core/licenses/hppc-NOTICE.txt rename {server/src/main/java/org/opensearch => libs/core/src/main/java/org/opensearch/core}/common/collect/ImmutableOpenIntMap.java (80%) rename {server/src/main/java/org/opensearch => libs/core/src/main/java/org/opensearch/core}/common/collect/ImmutableOpenMap.java (81%) create mode 100644 libs/core/src/main/java/org/opensearch/core/common/collect/package-info.java create mode 100644 libs/core/src/main/java/org/opensearch/core/common/package-info.java diff --git a/benchmarks/src/main/java/org/opensearch/benchmark/core/common/collect/ImmutableOpenMapBenchmark.java b/benchmarks/src/main/java/org/opensearch/benchmark/core/common/collect/ImmutableOpenMapBenchmark.java new file mode 100644 index 0000000000000..84504b894cd5f --- /dev/null +++ b/benchmarks/src/main/java/org/opensearch/benchmark/core/common/collect/ImmutableOpenMapBenchmark.java @@ -0,0 +1,72 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.benchmark.core.common.collect; + +import com.carrotsearch.hppc.cursors.ObjectObjectCursor; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Param; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.infra.Blackhole; +import org.opensearch.core.common.collect.ImmutableOpenMap; + +import java.util.Map; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.TimeUnit; + +@Fork(2) +@Warmup(iterations = 1) +@Measurement(iterations = 5) +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.NANOSECONDS) +@State(Scope.Benchmark) +public class ImmutableOpenMapBenchmark { + ImmutableOpenMap map; + + @Param({ "10000" }) + public int count; + + @Setup + public void buildMaps() { + ImmutableOpenMap.Builder mb = new ImmutableOpenMap.Builder(count); + for (int i = 0; i < count; ++i) { + mb.put(i, ThreadLocalRandom.current().nextDouble()); + } + map = mb.build(); + } + + @Benchmark + public void put(Blackhole blackhole) { + ImmutableOpenMap.Builder mb = new ImmutableOpenMap.Builder(count); + for (int i = 0; i < count; ++i) { + blackhole.consume(mb.put(i, ThreadLocalRandom.current().nextDouble())); + } + } + + @Benchmark + public void getHPPC(Blackhole blackhole) { + for (ObjectObjectCursor cursor : map) { + blackhole.consume(cursor.value); + } + } + + @Benchmark + public void getJavaMap(Blackhole blackhole) { + for (Map.Entry entry : map.entrySet()) { + blackhole.consume(entry.getValue()); + } + } +} diff --git a/client/rest-high-level/src/main/java/org/opensearch/client/indices/IndexTemplateMetadata.java b/client/rest-high-level/src/main/java/org/opensearch/client/indices/IndexTemplateMetadata.java index d22a5ec58d033..68d25e4b03b39 100644 --- a/client/rest-high-level/src/main/java/org/opensearch/client/indices/IndexTemplateMetadata.java +++ b/client/rest-high-level/src/main/java/org/opensearch/client/indices/IndexTemplateMetadata.java @@ -36,7 +36,7 @@ import org.opensearch.cluster.metadata.MappingMetadata; import org.opensearch.common.Nullable; import org.opensearch.core.ParseField; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.settings.Settings; import org.opensearch.core.xcontent.ConstructingObjectParser; import org.opensearch.core.xcontent.XContentParser; diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/AbstractResponseTestCase.java b/client/rest-high-level/src/test/java/org/opensearch/client/AbstractResponseTestCase.java index 3f3d8178dc9b2..2264b65e0e4a9 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/AbstractResponseTestCase.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/AbstractResponseTestCase.java @@ -32,7 +32,7 @@ package org.opensearch.client; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.xcontent.LoggingDeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; 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 db2d327e50a65..2f1ed796898b2 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 @@ -37,7 +37,7 @@ import org.opensearch.client.GetAliasesResponseTests; import org.opensearch.cluster.metadata.AliasMetadata; import org.opensearch.cluster.metadata.MappingMetadata; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.settings.IndexScopedSettings; import org.opensearch.common.settings.Settings; import org.opensearch.core.xcontent.XContentParser; diff --git a/libs/core/build.gradle b/libs/core/build.gradle index 717320b95ac85..b846bafcd1941 100644 --- a/libs/core/build.gradle +++ b/libs/core/build.gradle @@ -82,6 +82,10 @@ dependencies { // lucene api "org.apache.lucene:lucene-core:${versions.lucene}" + // hppc + // @todo remove and replace w/ java util? + api 'com.carrotsearch:hppc:0.8.1' + testImplementation "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}" testImplementation "junit:junit:${versions.junit}" testImplementation "org.hamcrest:hamcrest:${versions.hamcrest}" @@ -91,6 +95,13 @@ dependencies { } } +// carried over from :server, remove compiler warnings for ImmutableOpenMap +tasks.withType(JavaCompile).configureEach { + options.compilerArgs -= '-Xlint:cast' + options.compilerArgs -= '-Xlint:rawtypes' + options.compilerArgs -= '-Xlint:unchecked' +} + tasks.named('forbiddenApisMain').configure { // :libs:opensearch-core does not depend on server // TODO: Need to decide how we want to handle for forbidden signatures with the changes to server diff --git a/libs/core/licenses/hppc-0.8.1.jar.sha1 b/libs/core/licenses/hppc-0.8.1.jar.sha1 new file mode 100644 index 0000000000000..47684ed023210 --- /dev/null +++ b/libs/core/licenses/hppc-0.8.1.jar.sha1 @@ -0,0 +1 @@ +ffc7ba8f289428b9508ab484b8001dea944ae603 \ No newline at end of file diff --git a/libs/core/licenses/hppc-LICENSE.txt b/libs/core/licenses/hppc-LICENSE.txt new file mode 100644 index 0000000000000..31467575cdbfe --- /dev/null +++ b/libs/core/licenses/hppc-LICENSE.txt @@ -0,0 +1,203 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2010-2013, Carrot Search s.c., Boznicza 11/56, Poznan, Poland + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/libs/core/licenses/hppc-NOTICE.txt b/libs/core/licenses/hppc-NOTICE.txt new file mode 100644 index 0000000000000..1d8842c0bc69d --- /dev/null +++ b/libs/core/licenses/hppc-NOTICE.txt @@ -0,0 +1,11 @@ +ACKNOWLEDGEMENT +=============== + +HPPC borrowed code, ideas or both from: + + * Apache Lucene, http://lucene.apache.org/ + (Apache license) + * Fastutil, http://fastutil.di.unimi.it/ + (Apache license) + * Koloboke, https://github.com/OpenHFT/Koloboke + (Apache license) diff --git a/server/src/main/java/org/opensearch/common/collect/ImmutableOpenIntMap.java b/libs/core/src/main/java/org/opensearch/core/common/collect/ImmutableOpenIntMap.java similarity index 80% rename from server/src/main/java/org/opensearch/common/collect/ImmutableOpenIntMap.java rename to libs/core/src/main/java/org/opensearch/core/common/collect/ImmutableOpenIntMap.java index 0bff76e7ec90e..3416493430600 100644 --- a/server/src/main/java/org/opensearch/common/collect/ImmutableOpenIntMap.java +++ b/libs/core/src/main/java/org/opensearch/core/common/collect/ImmutableOpenIntMap.java @@ -30,7 +30,7 @@ * GitHub history for details. */ -package org.opensearch.common.collect; +package org.opensearch.core.common.collect; import com.carrotsearch.hppc.IntCollection; import com.carrotsearch.hppc.IntContainer; @@ -46,13 +46,16 @@ import com.carrotsearch.hppc.predicates.IntPredicate; import com.carrotsearch.hppc.procedures.IntObjectProcedure; +import java.util.AbstractSet; import java.util.Iterator; import java.util.Map; +import java.util.Objects; +import java.util.Set; /** * An immutable map implementation based on open hash map. *

- * Can be constructed using a {@link #builder()}, or using {@link #builder(org.opensearch.common.collect.ImmutableOpenIntMap)} + * Can be constructed using a {@link #builder()}, or using {@link #builder(ImmutableOpenIntMap)} * (which is an optimized option to copy over existing content and modify it). * * @opensearch.internal @@ -60,6 +63,8 @@ public final class ImmutableOpenIntMap implements Iterable> { private final IntObjectHashMap map; + /** used to encapsulate hppc */ + private Set> entrySet; private ImmutableOpenIntMap(IntObjectHashMap map) { this.map = map; @@ -122,6 +127,17 @@ public Iterator> iterator() { return map.iterator(); } + /** + * Returns a new immutable set of the entries (IntegerKey-value pairs) in this map using the {@link Map#entrySet()} API. + * The purpose of this is to encapsulate hppc to remove the dependency for the opensearch libraries + */ + public Set> entrySet() { + if (Objects.isNull(this.entrySet) == true) { + this.entrySet = new ImmutableEntrySet(); + } + return entrySet; + } + /** * Returns a specialized view of the keys of this associated container. * The view additionally implements {@link com.carrotsearch.hppc.ObjectLookupContainer}. @@ -407,4 +423,77 @@ public String visualizeKeyDistribution(int characters) { return map.visualizeKeyDistribution(characters); } } + + /** immutable entry for {@link ImmutableEntrySet} */ + private class ImmutableEntry implements Map.Entry { + private int key; + private VType value; + + ImmutableEntry(Integer key, VType value) { + this.key = key.intValue(); + this.value = value; + } + + @Override + public Integer getKey() { + return this.key; + } + + @Override + public VType getValue() { + return this.value; + } + + @Override + public VType setValue(VType value) { + throw new UnsupportedOperationException("entry is immutable"); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ImmutableEntry that = (ImmutableEntry) o; + return Objects.equals(key, that.key) && Objects.equals(value, that.value); + } + + @Override + public int hashCode() { + return Objects.hash(key, value); + } + } + + /** Immutable Entry Set */ + private class ImmutableEntrySet extends AbstractSet> { + @Override + public Iterator> iterator() { + Iterator> mapIter = map.iterator(); + return new Iterator() { + @Override + public boolean hasNext() { + return mapIter.hasNext(); + } + + @Override + public ImmutableEntry next() { + IntObjectCursor next = mapIter.next(); + return next != null ? new ImmutableEntry(next.key, next.value) : null; + } + }; + } + + @Override + public int size() { + return map.size(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException("attempting to clear immutable entry set"); + } + } } diff --git a/server/src/main/java/org/opensearch/common/collect/ImmutableOpenMap.java b/libs/core/src/main/java/org/opensearch/core/common/collect/ImmutableOpenMap.java similarity index 81% rename from server/src/main/java/org/opensearch/common/collect/ImmutableOpenMap.java rename to libs/core/src/main/java/org/opensearch/core/common/collect/ImmutableOpenMap.java index 77716c951c524..2cb26c66b1ee9 100644 --- a/server/src/main/java/org/opensearch/common/collect/ImmutableOpenMap.java +++ b/libs/core/src/main/java/org/opensearch/core/common/collect/ImmutableOpenMap.java @@ -30,7 +30,7 @@ * GitHub history for details. */ -package org.opensearch.common.collect; +package org.opensearch.core.common.collect; import com.carrotsearch.hppc.ObjectCollection; import com.carrotsearch.hppc.ObjectContainer; @@ -44,8 +44,11 @@ import com.carrotsearch.hppc.predicates.ObjectPredicate; import com.carrotsearch.hppc.procedures.ObjectObjectProcedure; +import java.util.AbstractSet; import java.util.Iterator; import java.util.Map; +import java.util.Objects; +import java.util.Set; /** * An immutable map implementation based on open hash map. @@ -58,6 +61,8 @@ public final class ImmutableOpenMap implements Iterable> { private final ObjectObjectHashMap map; + /** used to encapsulate hppc */ + private Set> entrySet; private ImmutableOpenMap(ObjectObjectHashMap map) { this.map = map; @@ -128,6 +133,17 @@ public Iterator> iterator() { return map.iterator(); } + /** + * Returns a new immutable set of the entries (key-value pairs) in this map using the {@link Map#entrySet()} API. + * The purpose of this is to encapsulate hppc to remove the dependency for the opensearch libraries + */ + public Set> entrySet() { + if (Objects.isNull(this.entrySet) == true) { + this.entrySet = new ImmutableEntrySet(); + } + return entrySet; + } + /** * Returns a specialized view of the keys of this associated container. * The view additionally implements {@link ObjectLookupContainer}. @@ -426,4 +442,77 @@ public String visualizeKeyDistribution(int characters) { return map.visualizeKeyDistribution(characters); } } + + /** immutable entry for {@link ImmutableEntrySet} */ + private class ImmutableEntry implements Map.Entry { + private KType key; + private VType value; + + ImmutableEntry(KType key, VType value) { + this.key = key; + this.value = value; + } + + @Override + public KType getKey() { + return this.key; + } + + @Override + public VType getValue() { + return this.value; + } + + @Override + public VType setValue(VType value) { + throw new UnsupportedOperationException("entry is immutable"); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ImmutableEntry that = (ImmutableEntry) o; + return Objects.equals(key, that.key) && Objects.equals(value, that.value); + } + + @Override + public int hashCode() { + return Objects.hash(key, value); + } + } + + /** Immutable Entry Set */ + private class ImmutableEntrySet extends AbstractSet> { + @Override + public Iterator> iterator() { + Iterator> mapIter = map.iterator(); + return new Iterator() { + @Override + public boolean hasNext() { + return mapIter.hasNext(); + } + + @Override + public ImmutableEntry next() { + ObjectObjectCursor next = mapIter.next(); + return next != null ? new ImmutableEntry(next.key, next.value) : null; + } + }; + } + + @Override + public int size() { + return map.size(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException("attempting to clear immutable entry set"); + } + } } diff --git a/libs/core/src/main/java/org/opensearch/core/common/collect/package-info.java b/libs/core/src/main/java/org/opensearch/core/common/collect/package-info.java new file mode 100644 index 0000000000000..fef0830993457 --- /dev/null +++ b/libs/core/src/main/java/org/opensearch/core/common/collect/package-info.java @@ -0,0 +1,10 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** Common collections for core (need third party dependencies) */ +package org.opensearch.core.common.collect; diff --git a/libs/core/src/main/java/org/opensearch/core/common/package-info.java b/libs/core/src/main/java/org/opensearch/core/common/package-info.java new file mode 100644 index 0000000000000..e858939efa6ba --- /dev/null +++ b/libs/core/src/main/java/org/opensearch/core/common/package-info.java @@ -0,0 +1,15 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/** + * common package for core library (supports third-party dependencies + * + * If a common class doesn't require any third party dependencies, including core + * components, please refactor to o.opensearch.common library + */ +package org.opensearch.core.common; diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/ShrinkIndexIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/ShrinkIndexIT.java index ef74e7a28fec3..68cb6902124e8 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/ShrinkIndexIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/ShrinkIndexIT.java @@ -64,7 +64,7 @@ import org.opensearch.cluster.routing.UnassignedInfo; import org.opensearch.cluster.routing.allocation.decider.EnableAllocationDecider; import org.opensearch.common.Priority; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.ByteSizeValue; import org.opensearch.common.unit.TimeValue; 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 0d4cf6bd19188..8519eafba822a 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 @@ -32,13 +32,12 @@ package org.opensearch.action.admin.indices.get; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.opensearch.action.admin.indices.alias.Alias; import org.opensearch.action.admin.indices.get.GetIndexRequest.Feature; import org.opensearch.action.support.IndicesOptions; import org.opensearch.cluster.metadata.AliasMetadata; import org.opensearch.cluster.metadata.MappingMetadata; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.settings.Settings; import org.opensearch.index.IndexNotFoundException; import org.opensearch.test.OpenSearchIntegTestCase; @@ -311,8 +310,8 @@ private void assertEmptyMappings(GetIndexResponse response) { private void assertEmptyAliases(GetIndexResponse response) { assertThat(response.aliases(), notNullValue()); - for (final ObjectObjectCursor> entry : response.getAliases()) { - assertTrue(entry.value.isEmpty()); + for (final Map.Entry> entry : response.getAliases().entrySet()) { + assertTrue(entry.getValue().isEmpty()); } } } diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/shards/IndicesShardStoreRequestIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/shards/IndicesShardStoreRequestIT.java index ea9f7e0a7232d..bc0f0df209aab 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/shards/IndicesShardStoreRequestIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/shards/IndicesShardStoreRequestIT.java @@ -32,7 +32,6 @@ package org.opensearch.action.admin.indices.shards; -import com.carrotsearch.hppc.cursors.IntObjectCursor; import com.carrotsearch.hppc.cursors.ObjectCursor; import org.apache.lucene.index.CorruptIndexException; import org.opensearch.action.index.IndexRequestBuilder; @@ -42,8 +41,8 @@ import org.opensearch.cluster.routing.IndexRoutingTable; import org.opensearch.cluster.routing.ShardRouting; import org.opensearch.cluster.routing.ShardRoutingState; -import org.opensearch.common.collect.ImmutableOpenIntMap; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenIntMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.settings.Settings; import org.opensearch.index.Index; import org.opensearch.index.IndexService; @@ -126,11 +125,11 @@ public void testBasic() throws Exception { assertThat(response.getStoreStatuses().containsKey(index), equalTo(true)); ImmutableOpenIntMap> shardStoresStatuses = response.getStoreStatuses().get(index); assertThat(shardStoresStatuses.size(), equalTo(unassignedShards.size())); - for (IntObjectCursor> storesStatus : shardStoresStatuses) { - assertThat("must report for one store", storesStatus.value.size(), equalTo(1)); + for (Map.Entry> storesStatus : shardStoresStatuses.entrySet()) { + assertThat("must report for one store", storesStatus.getValue().size(), equalTo(1)); assertThat( "reported store should be primary", - storesStatus.value.get(0).getAllocationStatus(), + storesStatus.getValue().get(0).getAllocationStatus(), equalTo(IndicesShardStoresResponse.StoreStatus.AllocationStatus.PRIMARY) ); } @@ -210,18 +209,18 @@ public void testCorruptedShards() throws Exception { ImmutableOpenIntMap> shardStatuses = rsp.getStoreStatuses().get(index); assertNotNull(shardStatuses); assertThat(shardStatuses.size(), greaterThan(0)); - for (IntObjectCursor> shardStatus : shardStatuses) { - for (IndicesShardStoresResponse.StoreStatus status : shardStatus.value) { - if (corruptedShardIDMap.containsKey(shardStatus.key) - && corruptedShardIDMap.get(shardStatus.key).contains(status.getNode().getName())) { + for (Map.Entry> shardStatus : shardStatuses.entrySet()) { + for (IndicesShardStoresResponse.StoreStatus status : shardStatus.getValue()) { + if (corruptedShardIDMap.containsKey(shardStatus.getKey()) + && corruptedShardIDMap.get(shardStatus.getKey()).contains(status.getNode().getName())) { assertThat( - "shard [" + shardStatus.key + "] is failed on node [" + status.getNode().getName() + "]", + "shard [" + shardStatus.getKey() + "] is failed on node [" + status.getNode().getName() + "]", status.getStoreException(), notNullValue() ); } else { assertNull( - "shard [" + shardStatus.key + "] is not failed on node [" + status.getNode().getName() + "]", + "shard [" + shardStatus.getKey() + "] is not failed on node [" + status.getNode().getName() + "]", status.getStoreException() ); } diff --git a/server/src/internalClusterTest/java/org/opensearch/aliases/IndexAliasesIT.java b/server/src/internalClusterTest/java/org/opensearch/aliases/IndexAliasesIT.java index 574046509de75..096a21d3759ae 100644 --- a/server/src/internalClusterTest/java/org/opensearch/aliases/IndexAliasesIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/aliases/IndexAliasesIT.java @@ -32,7 +32,6 @@ package org.opensearch.aliases; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.opensearch.action.admin.indices.alias.Alias; import org.opensearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions; import org.opensearch.action.admin.indices.alias.get.GetAliasesResponse; @@ -1044,8 +1043,8 @@ public void testIndicesGetAliases() throws Exception { assertAcked(admin().indices().prepareAliases().removeAlias("foobar", "foo")); getResponse = admin().indices().prepareGetAliases("foo").addIndices("foobar").get(); - for (final ObjectObjectCursor> entry : getResponse.getAliases()) { - assertTrue(entry.value.isEmpty()); + for (final Map.Entry> entry : getResponse.getAliases().entrySet()) { + assertTrue(entry.getValue().isEmpty()); } assertTrue(admin().indices().prepareGetAliases("foo").addIndices("foobar").get().getAliases().isEmpty()); } diff --git a/server/src/internalClusterTest/java/org/opensearch/cluster/ClusterStateDiffIT.java b/server/src/internalClusterTest/java/org/opensearch/cluster/ClusterStateDiffIT.java index f0c83680c131b..335f9c9f99f9b 100644 --- a/server/src/internalClusterTest/java/org/opensearch/cluster/ClusterStateDiffIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/cluster/ClusterStateDiffIT.java @@ -56,7 +56,7 @@ import org.opensearch.cluster.routing.UnassignedInfo; import org.opensearch.common.UUIDs; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.NamedWriteableAwareStreamInput; import org.opensearch.common.io.stream.NamedWriteableRegistry; diff --git a/server/src/internalClusterTest/java/org/opensearch/cluster/routing/PrimaryAllocationIT.java b/server/src/internalClusterTest/java/org/opensearch/cluster/routing/PrimaryAllocationIT.java index d2cce1318772a..cddbc2c110eb9 100644 --- a/server/src/internalClusterTest/java/org/opensearch/cluster/routing/PrimaryAllocationIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/cluster/routing/PrimaryAllocationIT.java @@ -32,7 +32,6 @@ package org.opensearch.cluster.routing; -import com.carrotsearch.hppc.cursors.IntObjectCursor; import org.opensearch.action.DocWriteResponse; import org.opensearch.action.admin.cluster.reroute.ClusterRerouteRequestBuilder; import org.opensearch.action.admin.indices.shards.IndicesShardStoresResponse; @@ -48,7 +47,7 @@ import org.opensearch.cluster.routing.allocation.command.AllocateStalePrimaryAllocationCommand; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.Strings; -import org.opensearch.common.collect.ImmutableOpenIntMap; +import org.opensearch.core.common.collect.ImmutableOpenIntMap; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.set.Sets; import org.opensearch.common.xcontent.XContentType; @@ -74,6 +73,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; @@ -323,9 +323,9 @@ public void testForceStaleReplicaToBePromotedToPrimary() throws Exception { .getStoreStatuses() .get(idxName); ClusterRerouteRequestBuilder rerouteBuilder = client().admin().cluster().prepareReroute(); - for (IntObjectCursor> shardStoreStatuses : storeStatuses) { - int shardId = shardStoreStatuses.key; - IndicesShardStoresResponse.StoreStatus storeStatus = randomFrom(shardStoreStatuses.value); + for (Map.Entry> shardStoreStatuses : storeStatuses.entrySet()) { + int shardId = shardStoreStatuses.getKey(); + IndicesShardStoresResponse.StoreStatus storeStatus = randomFrom(shardStoreStatuses.getValue()); logger.info("--> adding allocation command for shard {}", shardId); // force allocation based on node id if (useStaleReplica) { diff --git a/server/src/internalClusterTest/java/org/opensearch/index/shard/RemoveCorruptedShardDataCommandIT.java b/server/src/internalClusterTest/java/org/opensearch/index/shard/RemoveCorruptedShardDataCommandIT.java index 7f7914b1ead87..ae37d79f6d396 100644 --- a/server/src/internalClusterTest/java/org/opensearch/index/shard/RemoveCorruptedShardDataCommandIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/index/shard/RemoveCorruptedShardDataCommandIT.java @@ -31,7 +31,6 @@ package org.opensearch.index.shard; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import com.carrotsearch.randomizedtesting.generators.RandomPicks; import joptsimple.OptionParser; import joptsimple.OptionSet; @@ -235,10 +234,10 @@ public Settings onNodeStopped(String nodeName) throws Exception { String nodeId = null; final ClusterState state = client().admin().cluster().prepareState().get().getState(); final DiscoveryNodes nodes = state.nodes(); - for (ObjectObjectCursor cursor : nodes.getNodes()) { - final String name = cursor.value.getName(); + for (Map.Entry cursor : nodes.getNodes().entrySet()) { + final String name = cursor.getValue().getName(); if (name.equals(node)) { - nodeId = cursor.key; + nodeId = cursor.getKey(); break; } } @@ -423,10 +422,10 @@ public Settings onNodeStopped(String nodeName) throws Exception { String primaryNodeId = null; final ClusterState state = client().admin().cluster().prepareState().get().getState(); final DiscoveryNodes nodes = state.nodes(); - for (ObjectObjectCursor cursor : nodes.getNodes()) { - final String name = cursor.value.getName(); + for (Map.Entry cursor : nodes.getNodes().entrySet()) { + final String name = cursor.getValue().getName(); if (name.equals(node1)) { - primaryNodeId = cursor.key; + primaryNodeId = cursor.getKey(); break; } } @@ -630,8 +629,8 @@ public void testResolvePath() throws Exception { final Map nodeNameToNodeId = new HashMap<>(); final ClusterState state = client().admin().cluster().prepareState().get().getState(); final DiscoveryNodes nodes = state.nodes(); - for (ObjectObjectCursor cursor : nodes.getNodes()) { - nodeNameToNodeId.put(cursor.value.getName(), cursor.key); + for (Map.Entry cursor : nodes.getNodes().entrySet()) { + nodeNameToNodeId.put(cursor.getValue().getName(), cursor.getKey()); } final GroupShardsIterator shardIterators = state.getRoutingTable().activePrimaryShardsGrouped(new String[] { indexName }, false); diff --git a/server/src/internalClusterTest/java/org/opensearch/index/store/CorruptedFileIT.java b/server/src/internalClusterTest/java/org/opensearch/index/store/CorruptedFileIT.java index 960e17b76acb5..6c83d7ed6246b 100644 --- a/server/src/internalClusterTest/java/org/opensearch/index/store/CorruptedFileIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/index/store/CorruptedFileIT.java @@ -31,7 +31,6 @@ package org.opensearch.index.store; -import com.carrotsearch.hppc.cursors.IntObjectCursor; import com.carrotsearch.randomizedtesting.generators.RandomPicks; import org.apache.lucene.index.CheckIndex; import org.apache.lucene.index.SegmentCommitInfo; @@ -103,6 +102,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.TreeSet; import java.util.concurrent.CopyOnWriteArrayList; @@ -674,9 +674,11 @@ public void testReplicaCorruption() throws Exception { final IndicesShardStoresResponse stores = client().admin().indices().prepareShardStores(index.getName()).get(); - for (IntObjectCursor> shards : stores.getStoreStatuses().get(index.getName())) { - for (IndicesShardStoresResponse.StoreStatus store : shards.value) { - final ShardId shardId = new ShardId(index, shards.key); + for (Map.Entry> shards : stores.getStoreStatuses() + .get(index.getName()) + .entrySet()) { + for (IndicesShardStoresResponse.StoreStatus store : shards.getValue()) { + final ShardId shardId = new ShardId(index, shards.getKey()); if (store.getAllocationStatus().equals(IndicesShardStoresResponse.StoreStatus.AllocationStatus.UNUSED)) { for (Path path : findFilesToCorruptOnNode(store.getNode().getName(), shardId)) { try (OutputStream os = Files.newOutputStream(path)) { 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 f2c760638b54b..d2c6742dddcaf 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationAllocationIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationAllocationIT.java @@ -8,7 +8,6 @@ package org.opensearch.indices.replication; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.opensearch.cluster.ClusterState; import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.cluster.routing.IndexRoutingTable; @@ -25,6 +24,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -231,11 +231,11 @@ private void verifyPerIndexPrimaryBalance() throws Exception { assertBusy(() -> { final ClusterState currentState = client().admin().cluster().prepareState().execute().actionGet().getState(); RoutingNodes nodes = currentState.getRoutingNodes(); - for (ObjectObjectCursor index : currentState.getRoutingTable().indicesRouting()) { - final int totalPrimaryShards = index.value.primaryShardsActive(); + for (Map.Entry index : currentState.getRoutingTable().indicesRouting().entrySet()) { + final int totalPrimaryShards = index.getValue().primaryShardsActive(); final int avgPrimaryShardsPerNode = (int) Math.ceil(totalPrimaryShards * 1f / currentState.getRoutingNodes().size()); for (RoutingNode node : nodes) { - final int primaryCount = node.shardsWithState(index.key, STARTED) + final int primaryCount = node.shardsWithState(index.getKey(), STARTED) .stream() .filter(ShardRouting::primary) .collect(Collectors.toList()) @@ -243,7 +243,7 @@ private void verifyPerIndexPrimaryBalance() throws Exception { if (primaryCount > avgPrimaryShardsPerNode) { logger.info( "--> Primary shard balance assertion failure for index {} on node {} {} <= {}", - index.key, + index.getKey(), node.node().getName(), primaryCount, avgPrimaryShardsPerNode @@ -260,8 +260,8 @@ private void verifyPrimaryBalance() throws Exception { final ClusterState currentState = client().admin().cluster().prepareState().execute().actionGet().getState(); RoutingNodes nodes = currentState.getRoutingNodes(); int totalPrimaryShards = 0; - for (ObjectObjectCursor index : currentState.getRoutingTable().indicesRouting()) { - totalPrimaryShards += index.value.primaryShardsActive(); + for (Map.Entry index : currentState.getRoutingTable().indicesRouting().entrySet()) { + totalPrimaryShards += index.getValue().primaryShardsActive(); } final int avgPrimaryShardsPerNode = (int) Math.ceil(totalPrimaryShards * 1f / currentState.getRoutingNodes().size()); for (RoutingNode node : nodes) { diff --git a/server/src/internalClusterTest/java/org/opensearch/search/SearchWeightedRoutingIT.java b/server/src/internalClusterTest/java/org/opensearch/search/SearchWeightedRoutingIT.java index 422527506ed6c..99442d1fd9e69 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/SearchWeightedRoutingIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/SearchWeightedRoutingIT.java @@ -26,7 +26,7 @@ import org.opensearch.cluster.routing.WeightedRouting; import org.opensearch.cluster.routing.WeightedRoutingStats; import org.opensearch.cluster.routing.allocation.decider.AwarenessAllocationDecider; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.settings.Settings; import org.opensearch.index.query.QueryBuilders; import org.opensearch.index.search.stats.SearchStats; diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/reroute/TransportClusterRerouteAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/reroute/TransportClusterRerouteAction.java index e9ae23f6b9e34..e7e63dc6e2294 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/reroute/TransportClusterRerouteAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/reroute/TransportClusterRerouteAction.java @@ -59,8 +59,8 @@ import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.Priority; import org.opensearch.common.Strings; -import org.opensearch.common.collect.ImmutableOpenIntMap; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenIntMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.inject.Inject; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.threadpool.ThreadPool; diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/restore/RestoreClusterStateListener.java b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/restore/RestoreClusterStateListener.java index d0f78e85e26a5..0fc7775437831 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/restore/RestoreClusterStateListener.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/restore/RestoreClusterStateListener.java @@ -40,7 +40,7 @@ import org.opensearch.cluster.ClusterStateListener; import org.opensearch.cluster.RestoreInProgress; import org.opensearch.cluster.service.ClusterService; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.index.shard.ShardId; import org.opensearch.snapshots.RestoreInfo; import org.opensearch.snapshots.RestoreService; diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java index bd7391a7939a1..46cdaf5c4427b 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java @@ -33,7 +33,6 @@ package org.opensearch.action.admin.cluster.snapshots.status; import com.carrotsearch.hppc.cursors.ObjectCursor; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.action.ActionListener; @@ -210,26 +209,26 @@ private void buildResponse( currentSnapshotNames.add(entry.snapshot().getSnapshotId().getName()); List shardStatusBuilder = new ArrayList<>(); Map indexIdLookup = null; - for (ObjectObjectCursor shardEntry : entry.shards()) { - SnapshotsInProgress.ShardSnapshotStatus status = shardEntry.value; + for (Map.Entry shardEntry : entry.shards().entrySet()) { + SnapshotsInProgress.ShardSnapshotStatus status = shardEntry.getValue(); if (status.nodeId() != null) { // We should have information about this shard from the shard: TransportNodesSnapshotsStatus.NodeSnapshotStatus nodeStatus = nodeSnapshotStatusMap.get(status.nodeId()); if (nodeStatus != null) { Map shardStatues = nodeStatus.status().get(entry.snapshot()); if (shardStatues != null) { - SnapshotIndexShardStatus shardStatus = shardStatues.get(shardEntry.key); + SnapshotIndexShardStatus shardStatus = shardStatues.get(shardEntry.getKey()); if (shardStatus != null) { // We have full information about this shard if (shardStatus.getStage() == SnapshotIndexShardStage.DONE - && shardEntry.value.state() != SnapshotsInProgress.ShardState.SUCCESS) { + && shardEntry.getValue().state() != SnapshotsInProgress.ShardState.SUCCESS) { // Unlikely edge case: // Data node has finished snapshotting the shard but the cluster state has not yet been updated // to reflect this. We adjust the status to show up as snapshot metadata being written because // technically if the data node failed before successfully reporting DONE state to cluster-manager, // then this shards state would jump to a failed state. shardStatus = new SnapshotIndexShardStatus( - shardEntry.key, + shardEntry.getKey(), SnapshotIndexShardStage.FINALIZE, shardStatus.getStats(), shardStatus.getNodeId(), @@ -247,7 +246,7 @@ private void buildResponse( // We rebuild the information they would have provided from their in memory state from the cluster // state and the repository contents in the below logic final SnapshotIndexShardStage stage; - switch (shardEntry.value.state()) { + switch (shardEntry.getValue().state()) { case FAILED: case ABORTED: case MISSING: @@ -262,7 +261,7 @@ private void buildResponse( stage = SnapshotIndexShardStage.DONE; break; default: - throw new IllegalArgumentException("Unknown snapshot state " + shardEntry.value.state()); + throw new IllegalArgumentException("Unknown snapshot state " + shardEntry.getValue().state()); } final SnapshotIndexShardStatus shardStatus; if (stage == SnapshotIndexShardStage.DONE) { @@ -271,7 +270,7 @@ private void buildResponse( if (indexIdLookup == null) { indexIdLookup = entry.indices().stream().collect(Collectors.toMap(IndexId::getName, Function.identity())); } - final ShardId shardId = shardEntry.key; + final ShardId shardId = shardEntry.getKey(); shardStatus = new SnapshotIndexShardStatus( shardId, repositoriesService.repository(entry.repository()) @@ -283,7 +282,7 @@ private void buildResponse( .asCopy() ); } else { - shardStatus = new SnapshotIndexShardStatus(shardEntry.key, stage); + shardStatus = new SnapshotIndexShardStatus(shardEntry.getKey(), stage); } shardStatusBuilder.add(shardStatus); } 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 88f94cacf3a81..15c2cea31f530 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 @@ -32,7 +32,6 @@ package org.opensearch.action.admin.cluster.state; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.action.ActionListener; @@ -222,9 +221,9 @@ private ClusterStateResponse buildResponse(final ClusterStateRequest request, fi builder.metadata(mdBuilder); if (request.customs()) { - for (ObjectObjectCursor custom : currentState.customs()) { - if (custom.value.isPrivate() == false) { - builder.putCustom(custom.key, custom.value); + for (final Map.Entry custom : currentState.customs().entrySet()) { + if (custom.getValue().isPrivate() == false) { + builder.putCustom(custom.getKey(), custom.getValue()); } } } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/stats/ClusterStatsIndices.java b/server/src/main/java/org/opensearch/action/admin/cluster/stats/ClusterStatsIndices.java index 02a516fffbfd3..79ce6046d97cb 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/stats/ClusterStatsIndices.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/stats/ClusterStatsIndices.java @@ -32,9 +32,8 @@ package org.opensearch.action.admin.cluster.stats; -import com.carrotsearch.hppc.ObjectObjectHashMap; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.opensearch.action.admin.indices.stats.CommonStats; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.core.xcontent.ToXContentFragment; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.index.cache.query.QueryCacheStats; @@ -46,6 +45,7 @@ import java.io.IOException; import java.util.List; +import java.util.Map; /** * Cluster Stats per index @@ -66,7 +66,7 @@ public class ClusterStatsIndices implements ToXContentFragment { private MappingStats mappings; public ClusterStatsIndices(List nodeResponses, MappingStats mappingStats, AnalysisStats analysisStats) { - ObjectObjectHashMap countsPerIndex = new ObjectObjectHashMap<>(); + ImmutableOpenMap.Builder countsPerIndex = new ImmutableOpenMap.Builder<>(); this.docs = new DocsStats(); this.store = new StoreStats(); @@ -101,8 +101,9 @@ public ClusterStatsIndices(List nodeResponses, Mapping shards = new ShardStats(); indexCount = countsPerIndex.size(); - for (ObjectObjectCursor indexCountsCursor : countsPerIndex) { - shards.addIndexShardCount(indexCountsCursor.value); + // build the immutable map (syntactic sugar around the ImmutableOpenMap) and iterate over the entrySet + for (Map.Entry indexCountsCursor : countsPerIndex.build().entrySet()) { + shards.addIndexShardCount(indexCountsCursor.getValue()); } this.mappings = mappingStats; diff --git a/server/src/main/java/org/opensearch/action/admin/indices/alias/TransportIndicesAliasesAction.java b/server/src/main/java/org/opensearch/action/admin/indices/alias/TransportIndicesAliasesAction.java index 0ab9faa94090a..419f60a881526 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/alias/TransportIndicesAliasesAction.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/alias/TransportIndicesAliasesAction.java @@ -51,7 +51,7 @@ import org.opensearch.cluster.metadata.Metadata; import org.opensearch.cluster.metadata.MetadataIndexAliasesService; import org.opensearch.cluster.service.ClusterService; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.inject.Inject; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.index.Index; diff --git a/server/src/main/java/org/opensearch/action/admin/indices/alias/get/GetAliasesResponse.java b/server/src/main/java/org/opensearch/action/admin/indices/alias/get/GetAliasesResponse.java index 60c0a403566d5..21c2eacceccc3 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/alias/get/GetAliasesResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/alias/get/GetAliasesResponse.java @@ -34,7 +34,7 @@ import org.opensearch.action.ActionResponse; import org.opensearch.cluster.metadata.AliasMetadata; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; diff --git a/server/src/main/java/org/opensearch/action/admin/indices/alias/get/TransportGetAliasesAction.java b/server/src/main/java/org/opensearch/action/admin/indices/alias/get/TransportGetAliasesAction.java index fe9c2dbccdf7b..2f581b67ec7d9 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/alias/get/TransportGetAliasesAction.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/alias/get/TransportGetAliasesAction.java @@ -41,7 +41,7 @@ import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; import org.opensearch.cluster.service.ClusterService; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.inject.Inject; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.logging.DeprecationLogger; 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 d15573ad3276c..62ddc2a22275e 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 @@ -32,13 +32,12 @@ package org.opensearch.action.admin.indices.get; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.opensearch.Version; import org.opensearch.action.ActionResponse; import org.opensearch.cluster.metadata.AliasMetadata; import org.opensearch.cluster.metadata.MappingMetadata; import org.opensearch.common.Strings; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.settings.Settings; @@ -255,27 +254,27 @@ public void writeTo(StreamOutput out) throws IOException { } } out.writeVInt(aliases.size()); - for (ObjectObjectCursor> indexEntry : aliases) { - out.writeString(indexEntry.key); - out.writeVInt(indexEntry.value.size()); - for (AliasMetadata aliasEntry : indexEntry.value) { + for (Map.Entry> indexEntry : aliases.entrySet()) { + out.writeString(indexEntry.getKey()); + out.writeVInt(indexEntry.getValue().size()); + for (AliasMetadata aliasEntry : indexEntry.getValue()) { aliasEntry.writeTo(out); } } out.writeVInt(settings.size()); - for (ObjectObjectCursor indexEntry : settings) { - out.writeString(indexEntry.key); - Settings.writeSettingsToStream(indexEntry.value, out); + for (Map.Entry indexEntry : settings.entrySet()) { + out.writeString(indexEntry.getKey()); + Settings.writeSettingsToStream(indexEntry.getValue(), out); } out.writeVInt(defaultSettings.size()); - for (ObjectObjectCursor indexEntry : defaultSettings) { - out.writeString(indexEntry.key); - Settings.writeSettingsToStream(indexEntry.value, out); + for (Map.Entry indexEntry : defaultSettings.entrySet()) { + out.writeString(indexEntry.getKey()); + Settings.writeSettingsToStream(indexEntry.getValue(), out); } out.writeVInt(dataStreams.size()); - for (ObjectObjectCursor indexEntry : dataStreams) { - out.writeString(indexEntry.key); - out.writeOptionalString(indexEntry.value); + for (Map.Entry indexEntry : dataStreams.entrySet()) { + out.writeString(indexEntry.getKey()); + out.writeOptionalString(indexEntry.getValue()); } } 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 dbd9afd58a1fa..9b27f3226dece 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 @@ -41,7 +41,7 @@ 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.core.common.collect.ImmutableOpenMap; import org.opensearch.common.inject.Inject; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.settings.IndexScopedSettings; diff --git a/server/src/main/java/org/opensearch/action/admin/indices/settings/get/GetSettingsResponse.java b/server/src/main/java/org/opensearch/action/admin/indices/settings/get/GetSettingsResponse.java index 5ddd9e9c910c3..b41833cf96ade 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/settings/get/GetSettingsResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/settings/get/GetSettingsResponse.java @@ -32,10 +32,9 @@ package org.opensearch.action.admin.indices.settings.get; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.opensearch.action.ActionResponse; import org.opensearch.common.Strings; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.settings.Settings; @@ -212,18 +211,18 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws private XContentBuilder toXContent(XContentBuilder builder, Params params, boolean omitEmptySettings) throws IOException { builder.startObject(); - for (ObjectObjectCursor cursor : getIndexToSettings()) { + for (Map.Entry cursor : getIndexToSettings().entrySet()) { // no settings, jump over it to shorten the response data - if (omitEmptySettings && cursor.value.isEmpty()) { + if (omitEmptySettings && cursor.getValue().isEmpty()) { continue; } - builder.startObject(cursor.key); + builder.startObject(cursor.getKey()); builder.startObject("settings"); - cursor.value.toXContent(builder, params); + cursor.getValue().toXContent(builder, params); builder.endObject(); if (indexToDefaultSettings.isEmpty() == false) { builder.startObject("defaults"); - indexToDefaultSettings.get(cursor.key).toXContent(builder, params); + indexToDefaultSettings.get(cursor.getKey()).toXContent(builder, params); builder.endObject(); } builder.endObject(); diff --git a/server/src/main/java/org/opensearch/action/admin/indices/settings/get/TransportGetSettingsAction.java b/server/src/main/java/org/opensearch/action/admin/indices/settings/get/TransportGetSettingsAction.java index cfa75167afa09..f7e5c12ade3e5 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/settings/get/TransportGetSettingsAction.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/settings/get/TransportGetSettingsAction.java @@ -41,7 +41,7 @@ import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; import org.opensearch.cluster.service.ClusterService; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.inject.Inject; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.regex.Regex; diff --git a/server/src/main/java/org/opensearch/action/admin/indices/shards/IndicesShardStoresResponse.java b/server/src/main/java/org/opensearch/action/admin/indices/shards/IndicesShardStoresResponse.java index ff0a3ae638525..f0704ba35fcbc 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/shards/IndicesShardStoresResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/shards/IndicesShardStoresResponse.java @@ -32,14 +32,12 @@ package org.opensearch.action.admin.indices.shards; -import com.carrotsearch.hppc.cursors.IntObjectCursor; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.opensearch.OpenSearchException; import org.opensearch.action.ActionResponse; import org.opensearch.action.support.DefaultShardOperationFailedException; import org.opensearch.cluster.node.DiscoveryNode; -import org.opensearch.common.collect.ImmutableOpenIntMap; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenIntMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.io.stream.Writeable; @@ -49,6 +47,7 @@ import java.io.IOException; import java.util.Collections; import java.util.List; +import java.util.Map; /** * Response for {@link IndicesShardStoresAction} @@ -319,9 +318,9 @@ public List getFailures() { public void writeTo(StreamOutput out) throws IOException { out.writeMap(storeStatuses, StreamOutput::writeString, (o, v) -> { o.writeVInt(v.size()); - for (IntObjectCursor> shardStatusesEntry : v) { - o.writeInt(shardStatusesEntry.key); - o.writeCollection(shardStatusesEntry.value); + for (Map.Entry> shardStatusesEntry : v.entrySet()) { + o.writeInt(shardStatusesEntry.getKey()); + o.writeCollection(shardStatusesEntry.getValue()); } }); out.writeList(failures); @@ -338,14 +337,14 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws } builder.startObject(Fields.INDICES); - for (ObjectObjectCursor>> indexShards : storeStatuses) { - builder.startObject(indexShards.key); + for (Map.Entry>> indexShards : storeStatuses.entrySet()) { + builder.startObject(indexShards.getKey()); builder.startObject(Fields.SHARDS); - for (IntObjectCursor> shardStatusesEntry : indexShards.value) { - builder.startObject(String.valueOf(shardStatusesEntry.key)); + for (Map.Entry> shardStatusesEntry : indexShards.getValue().entrySet()) { + builder.startObject(String.valueOf(shardStatusesEntry.getKey())); builder.startArray(Fields.STORES); - for (StoreStatus storeStatus : shardStatusesEntry.value) { + for (StoreStatus storeStatus : shardStatusesEntry.getValue()) { builder.startObject(); storeStatus.toXContent(builder, params); builder.endObject(); diff --git a/server/src/main/java/org/opensearch/action/admin/indices/shards/TransportIndicesShardStoresAction.java b/server/src/main/java/org/opensearch/action/admin/indices/shards/TransportIndicesShardStoresAction.java index cfe682e47f688..8d1d21c344334 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/shards/TransportIndicesShardStoresAction.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/shards/TransportIndicesShardStoresAction.java @@ -53,8 +53,8 @@ import org.opensearch.cluster.routing.RoutingTable; import org.opensearch.cluster.routing.ShardRouting; import org.opensearch.cluster.service.ClusterService; -import org.opensearch.common.collect.ImmutableOpenIntMap; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenIntMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.collect.Tuple; import org.opensearch.common.inject.Inject; import org.opensearch.common.io.stream.StreamInput; diff --git a/server/src/main/java/org/opensearch/action/support/ActiveShardCount.java b/server/src/main/java/org/opensearch/action/support/ActiveShardCount.java index 10699690d0aff..061866ab0ef4e 100644 --- a/server/src/main/java/org/opensearch/action/support/ActiveShardCount.java +++ b/server/src/main/java/org/opensearch/action/support/ActiveShardCount.java @@ -32,8 +32,6 @@ package org.opensearch.action.support; -import com.carrotsearch.hppc.cursors.IntObjectCursor; - import org.opensearch.cluster.ClusterState; import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.cluster.routing.IndexRoutingTable; @@ -43,6 +41,7 @@ import org.opensearch.common.io.stream.Writeable; import java.io.IOException; +import java.util.Map; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WAIT_FOR_ACTIVE_SHARDS; @@ -186,8 +185,8 @@ public boolean enoughShardsActive(final ClusterState clusterState, final String. if (waitForActiveShards == ActiveShardCount.DEFAULT) { waitForActiveShards = SETTING_WAIT_FOR_ACTIVE_SHARDS.get(indexMetadata.getSettings()); } - for (final IntObjectCursor shardRouting : indexRoutingTable.getShards()) { - if (waitForActiveShards.enoughShardsActive(shardRouting.value) == false) { + for (final Map.Entry shardRouting : indexRoutingTable.getShards().entrySet()) { + if (waitForActiveShards.enoughShardsActive(shardRouting.getValue()) == false) { // not enough active shard copies yet return false; } diff --git a/server/src/main/java/org/opensearch/action/support/replication/TransportBroadcastReplicationAction.java b/server/src/main/java/org/opensearch/action/support/replication/TransportBroadcastReplicationAction.java index b4bacefad8ad2..4cd18f333ab0d 100644 --- a/server/src/main/java/org/opensearch/action/support/replication/TransportBroadcastReplicationAction.java +++ b/server/src/main/java/org/opensearch/action/support/replication/TransportBroadcastReplicationAction.java @@ -32,7 +32,6 @@ package org.opensearch.action.support.replication; -import com.carrotsearch.hppc.cursors.IntObjectCursor; import org.opensearch.ExceptionsHelper; import org.opensearch.action.ActionListener; import org.opensearch.action.support.ActionFilters; @@ -56,6 +55,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; /** @@ -154,11 +154,12 @@ protected List shards(Request request, ClusterState clusterState) { for (String index : concreteIndices) { IndexMetadata indexMetadata = clusterState.metadata().getIndices().get(index); if (indexMetadata != null) { - for (IntObjectCursor shardRouting : clusterState.getRoutingTable() + for (Map.Entry shardRouting : clusterState.getRoutingTable() .indicesRouting() .get(index) - .getShards()) { - shardIds.add(shardRouting.value.shardId()); + .getShards() + .entrySet()) { + shardIds.add(shardRouting.getValue().shardId()); } } } diff --git a/server/src/main/java/org/opensearch/action/support/tasks/TransportTasksAction.java b/server/src/main/java/org/opensearch/action/support/tasks/TransportTasksAction.java index 460a0f7875558..36b1cb003d425 100644 --- a/server/src/main/java/org/opensearch/action/support/tasks/TransportTasksAction.java +++ b/server/src/main/java/org/opensearch/action/support/tasks/TransportTasksAction.java @@ -44,7 +44,7 @@ import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.cluster.node.DiscoveryNodes; import org.opensearch.cluster.service.ClusterService; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.collect.Tuple; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; diff --git a/server/src/main/java/org/opensearch/cluster/ClusterState.java b/server/src/main/java/org/opensearch/cluster/ClusterState.java index 5d32d2edb8494..1c305eacbb9db 100644 --- a/server/src/main/java/org/opensearch/cluster/ClusterState.java +++ b/server/src/main/java/org/opensearch/cluster/ClusterState.java @@ -33,7 +33,6 @@ package org.opensearch.cluster; import com.carrotsearch.hppc.cursors.ObjectCursor; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.opensearch.cluster.block.ClusterBlock; import org.opensearch.cluster.block.ClusterBlocks; import org.opensearch.cluster.coordination.CoordinationMetadata; @@ -53,7 +52,7 @@ import org.opensearch.common.Strings; import org.opensearch.common.UUIDs; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.NamedWriteableAwareStreamInput; import org.opensearch.common.io.stream.NamedWriteableRegistry; @@ -388,9 +387,9 @@ public String toString() { sb.append(getRoutingNodes()); if (customs.isEmpty() == false) { sb.append("customs:\n"); - for (ObjectObjectCursor cursor : customs) { - final String type = cursor.key; - final Custom custom = cursor.value; + for (Map.Entry cursor : customs.entrySet()) { + final String type = cursor.getKey(); + final Custom custom = cursor.getValue(); sb.append(TAB).append(type).append(": ").append(custom); } } @@ -506,9 +505,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws if (!blocks().indices().isEmpty()) { builder.startObject("indices"); - for (ObjectObjectCursor> entry : blocks().indices()) { - builder.startObject(entry.key); - for (ClusterBlock block : entry.value) { + for (Map.Entry> entry : blocks().indices().entrySet()) { + builder.startObject(entry.getKey()); + for (ClusterBlock block : entry.getValue()) { block.toXContent(builder, params); } builder.endObject(); @@ -576,9 +575,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.endObject(); } if (metrics.contains(Metric.CUSTOMS)) { - for (ObjectObjectCursor cursor : customs) { - builder.startObject(cursor.key); - cursor.value.toXContent(builder, params); + for (Map.Entry cursor : customs.entrySet()) { + builder.startObject(cursor.getKey()); + cursor.getValue().toXContent(builder, params); builder.endObject(); } } diff --git a/server/src/main/java/org/opensearch/cluster/DiffableUtils.java b/server/src/main/java/org/opensearch/cluster/DiffableUtils.java index f2a20b356d25d..586504604b3a1 100644 --- a/server/src/main/java/org/opensearch/cluster/DiffableUtils.java +++ b/server/src/main/java/org/opensearch/cluster/DiffableUtils.java @@ -33,12 +33,10 @@ package org.opensearch.cluster; import com.carrotsearch.hppc.cursors.IntCursor; -import com.carrotsearch.hppc.cursors.IntObjectCursor; import com.carrotsearch.hppc.cursors.ObjectCursor; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.opensearch.Version; -import org.opensearch.common.collect.ImmutableOpenIntMap; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenIntMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.io.stream.Writeable.Reader; @@ -320,15 +318,15 @@ public ImmutableOpenMapDiff( } } - for (ObjectObjectCursor partIter : after) { - T beforePart = before.get(partIter.key); + for (Map.Entry partIter : after.entrySet()) { + T beforePart = before.get(partIter.getKey()); if (beforePart == null) { - upserts.put(partIter.key, partIter.value); - } else if (partIter.value.equals(beforePart) == false) { + upserts.put(partIter.getKey(), partIter.getValue()); + } else if (partIter.getValue().equals(beforePart) == false) { if (valueSerializer.supportsDiffableValues()) { - diffs.put(partIter.key, valueSerializer.diff(partIter.value, beforePart)); + diffs.put(partIter.getKey(), valueSerializer.diff(partIter.getValue(), beforePart)); } else { - upserts.put(partIter.key, partIter.value); + upserts.put(partIter.getKey(), partIter.getValue()); } } } @@ -398,15 +396,15 @@ protected ImmutableOpenIntMapDiff(StreamInput in, KeySerializer keySeri } } - for (IntObjectCursor partIter : after) { - T beforePart = before.get(partIter.key); + for (Map.Entry partIter : after.entrySet()) { + T beforePart = before.get(partIter.getKey()); if (beforePart == null) { - upserts.put(partIter.key, partIter.value); - } else if (partIter.value.equals(beforePart) == false) { + upserts.put(partIter.getKey(), partIter.getValue()); + } else if (partIter.getValue().equals(beforePart) == false) { if (valueSerializer.supportsDiffableValues()) { - diffs.put(partIter.key, valueSerializer.diff(partIter.value, beforePart)); + diffs.put(partIter.getKey(), valueSerializer.diff(partIter.getValue(), beforePart)); } else { - upserts.put(partIter.key, partIter.value); + upserts.put(partIter.getKey(), partIter.getValue()); } } } diff --git a/server/src/main/java/org/opensearch/cluster/RestoreInProgress.java b/server/src/main/java/org/opensearch/cluster/RestoreInProgress.java index 75153e265481e..7e44a715048ea 100644 --- a/server/src/main/java/org/opensearch/cluster/RestoreInProgress.java +++ b/server/src/main/java/org/opensearch/cluster/RestoreInProgress.java @@ -33,10 +33,9 @@ package org.opensearch.cluster; import com.carrotsearch.hppc.cursors.ObjectCursor; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.opensearch.Version; import org.opensearch.cluster.ClusterState.Custom; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.io.stream.Writeable; @@ -49,6 +48,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.UUID; @@ -524,9 +524,9 @@ public void toXContent(Entry entry, XContentBuilder builder) throws IOException builder.endArray(); builder.startArray("shards"); { - for (ObjectObjectCursor shardEntry : entry.shards) { - ShardId shardId = shardEntry.key; - ShardRestoreStatus status = shardEntry.value; + for (Map.Entry shardEntry : entry.shards.entrySet()) { + ShardId shardId = shardEntry.getKey(); + ShardRestoreStatus status = shardEntry.getValue(); builder.startObject(); { builder.field("index", shardId.getIndex()); diff --git a/server/src/main/java/org/opensearch/cluster/SnapshotsInProgress.java b/server/src/main/java/org/opensearch/cluster/SnapshotsInProgress.java index d0d0da301ffaa..3af2de62a8227 100644 --- a/server/src/main/java/org/opensearch/cluster/SnapshotsInProgress.java +++ b/server/src/main/java/org/opensearch/cluster/SnapshotsInProgress.java @@ -34,12 +34,11 @@ import com.carrotsearch.hppc.ObjectContainer; import com.carrotsearch.hppc.cursors.ObjectCursor; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.opensearch.Version; import org.opensearch.cluster.ClusterState.Custom; import org.opensearch.common.Nullable; import org.opensearch.common.Strings; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.io.stream.Writeable; @@ -453,8 +452,8 @@ public Entry abort() { final ImmutableOpenMap.Builder shardsBuilder = ImmutableOpenMap.builder(); boolean completed = true; boolean allQueued = true; - for (ObjectObjectCursor shardEntry : shards) { - ShardSnapshotStatus status = shardEntry.value; + for (Map.Entry shardEntry : shards.entrySet()) { + ShardSnapshotStatus status = shardEntry.getValue(); allQueued &= status.state() == ShardState.QUEUED; if (status.state().completed() == false) { final String nodeId = status.nodeId(); @@ -466,7 +465,7 @@ public Entry abort() { ); } completed &= status.state().completed(); - shardsBuilder.put(shardEntry.key, status); + shardsBuilder.put(shardEntry.getKey(), status); } if (allQueued) { return null; @@ -678,9 +677,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.field(REPOSITORY_STATE_ID, repositoryStateId); builder.startArray(SHARDS); { - for (ObjectObjectCursor shardEntry : shards) { - ShardId shardId = shardEntry.key; - ShardSnapshotStatus status = shardEntry.value; + for (Map.Entry shardEntry : shards.entrySet()) { + ShardId shardId = shardEntry.getKey(); + ShardSnapshotStatus status = shardEntry.getValue(); builder.startObject(); { builder.field(INDEX, shardId.getIndex()); @@ -930,9 +929,9 @@ public static State fromValue(byte value) { private static boolean assertConsistentEntries(List entries) { final Map> assignedShardsByRepo = new HashMap<>(); for (Entry entry : entries) { - for (ObjectObjectCursor shard : entry.shards()) { - if (shard.value.isActive()) { - assert assignedShardsByRepo.computeIfAbsent(entry.repository(), k -> new HashSet<>()).add(shard.key) + for (Map.Entry shard : entry.shards().entrySet()) { + if (shard.getValue().isActive()) { + assert assignedShardsByRepo.computeIfAbsent(entry.repository(), k -> new HashSet<>()).add(shard.getKey()) : "Found duplicate shard assignments in " + entries; } } diff --git a/server/src/main/java/org/opensearch/cluster/awarenesshealth/ClusterAwarenessAttributesHealth.java b/server/src/main/java/org/opensearch/cluster/awarenesshealth/ClusterAwarenessAttributesHealth.java index cef4d1df4633a..e67135c9bf4c5 100644 --- a/server/src/main/java/org/opensearch/cluster/awarenesshealth/ClusterAwarenessAttributesHealth.java +++ b/server/src/main/java/org/opensearch/cluster/awarenesshealth/ClusterAwarenessAttributesHealth.java @@ -12,7 +12,7 @@ import org.opensearch.cluster.ClusterState; import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.common.Strings; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.io.stream.Writeable; diff --git a/server/src/main/java/org/opensearch/cluster/block/ClusterBlocks.java b/server/src/main/java/org/opensearch/cluster/block/ClusterBlocks.java index 167a1cc0fab98..82228c6ecae17 100644 --- a/server/src/main/java/org/opensearch/cluster/block/ClusterBlocks.java +++ b/server/src/main/java/org/opensearch/cluster/block/ClusterBlocks.java @@ -32,13 +32,12 @@ package org.opensearch.cluster.block; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.opensearch.cluster.AbstractDiffable; import org.opensearch.cluster.Diff; import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.cluster.metadata.MetadataIndexStateService; import org.opensearch.common.Nullable; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.util.set.Sets; @@ -109,8 +108,8 @@ private static EnumMap generateLevelHol Set newGlobal = unmodifiableSet(global.stream().filter(containsLevel).collect(toSet())); ImmutableOpenMap.Builder> indicesBuilder = ImmutableOpenMap.builder(); - for (ObjectObjectCursor> entry : indicesBlocks) { - indicesBuilder.put(entry.key, unmodifiableSet(entry.value.stream().filter(containsLevel).collect(toSet()))); + for (Map.Entry> entry : indicesBlocks.entrySet()) { + indicesBuilder.put(entry.getKey(), unmodifiableSet(entry.getValue().stream().filter(containsLevel).collect(toSet()))); } levelHolders.put(level, new ImmutableLevelHolder(newGlobal, indicesBuilder.build())); } @@ -288,9 +287,9 @@ public String toString() { sb.append(" ").append(block); } } - for (ObjectObjectCursor> entry : indices()) { - sb.append(" ").append(entry.key).append(":\n"); - for (ClusterBlock block : entry.value) { + for (Map.Entry> entry : indices().entrySet()) { + sb.append(" ").append(entry.getKey()).append(":\n"); + for (ClusterBlock block : entry.getValue()) { sb.append(" ").append(block); } } @@ -372,11 +371,11 @@ public Builder() {} public Builder blocks(ClusterBlocks blocks) { global.addAll(blocks.global()); - for (ObjectObjectCursor> entry : blocks.indices()) { - if (!indices.containsKey(entry.key)) { - indices.put(entry.key, new HashSet<>()); + for (Map.Entry> entry : blocks.indices().entrySet()) { + if (!indices.containsKey(entry.getKey())) { + indices.put(entry.getKey(), new HashSet<>()); } - indices.get(entry.key).addAll(entry.value); + indices.get(entry.getKey()).addAll(entry.getValue()); } return this; } diff --git a/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java b/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java index aa648a818cd15..a0b56a552eaa8 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java @@ -33,9 +33,7 @@ package org.opensearch.cluster.metadata; import com.carrotsearch.hppc.LongArrayList; -import com.carrotsearch.hppc.cursors.IntObjectCursor; import com.carrotsearch.hppc.cursors.ObjectCursor; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.opensearch.core.Assertions; import org.opensearch.LegacyESVersion; import org.opensearch.Version; @@ -49,8 +47,8 @@ import org.opensearch.cluster.node.DiscoveryNodeFilters; import org.opensearch.cluster.routing.allocation.IndexMetadataUpdater; import org.opensearch.common.Nullable; -import org.opensearch.common.collect.ImmutableOpenIntMap; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenIntMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.collect.MapBuilder; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.io.stream.StreamInput; @@ -900,8 +898,8 @@ public ImmutableOpenMap getAliases() { */ @Nullable public MappingMetadata mapping() { - for (ObjectObjectCursor cursor : mappings) { - return cursor.value; + for (Map.Entry cursor : mappings.entrySet()) { + return cursor.getValue(); } return null; } @@ -1230,14 +1228,14 @@ public void writeTo(StreamOutput out) throws IOException { cursor.value.writeTo(out); } out.writeVInt(customData.size()); - for (final ObjectObjectCursor cursor : customData) { - out.writeString(cursor.key); - cursor.value.writeTo(out); + for (final Map.Entry cursor : customData.entrySet()) { + out.writeString(cursor.getKey()); + cursor.getValue().writeTo(out); } out.writeVInt(inSyncAllocationIds.size()); - for (IntObjectCursor> cursor : inSyncAllocationIds) { - out.writeVInt(cursor.key); - DiffableUtils.StringSetValueSerializer.getInstance().write(cursor.value, out); + for (Map.Entry> cursor : inSyncAllocationIds.entrySet()) { + out.writeVInt(cursor.getKey()); + DiffableUtils.StringSetValueSerializer.getInstance().write(cursor.getValue(), out); } out.writeVInt(rolloverInfos.size()); for (ObjectCursor cursor : rolloverInfos.values()) { @@ -1703,9 +1701,9 @@ public static void toXContent(IndexMetadata indexMetadata, XContentBuilder build builder.endObject(); } - for (ObjectObjectCursor cursor : indexMetadata.customData) { - builder.field(cursor.key); - builder.map(cursor.value); + for (Map.Entry cursor : indexMetadata.customData.entrySet()) { + builder.field(cursor.getKey()); + builder.map(cursor.getValue()); } if (context != Metadata.XContentContext.API) { @@ -1735,9 +1733,9 @@ public static void toXContent(IndexMetadata indexMetadata, XContentBuilder build } builder.startObject(KEY_IN_SYNC_ALLOCATIONS); - for (IntObjectCursor> cursor : indexMetadata.inSyncAllocationIds) { - builder.startArray(String.valueOf(cursor.key)); - for (String allocationId : cursor.value) { + for (Map.Entry> cursor : indexMetadata.inSyncAllocationIds.entrySet()) { + builder.startArray(String.valueOf(cursor.getKey())); + for (String allocationId : cursor.getValue()) { builder.value(allocationId); } builder.endArray(); diff --git a/server/src/main/java/org/opensearch/cluster/metadata/IndexNameExpressionResolver.java b/server/src/main/java/org/opensearch/cluster/metadata/IndexNameExpressionResolver.java index cb81afa884b12..bda5b6c3b0fe9 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/IndexNameExpressionResolver.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/IndexNameExpressionResolver.java @@ -39,7 +39,7 @@ import org.opensearch.common.Booleans; import org.opensearch.common.Nullable; import org.opensearch.common.Strings; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.collect.Tuple; import org.opensearch.common.logging.DeprecationLogger; import org.opensearch.common.regex.Regex; diff --git a/server/src/main/java/org/opensearch/cluster/metadata/IndexTemplateMetadata.java b/server/src/main/java/org/opensearch/cluster/metadata/IndexTemplateMetadata.java index affa3b2587049..04a4337270d74 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/IndexTemplateMetadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/IndexTemplateMetadata.java @@ -32,13 +32,12 @@ package org.opensearch.cluster.metadata; import com.carrotsearch.hppc.cursors.ObjectCursor; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.opensearch.OpenSearchParseException; import org.opensearch.cluster.AbstractDiffable; import org.opensearch.cluster.Diff; import org.opensearch.common.Nullable; import org.opensearch.common.Strings; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.collect.MapBuilder; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.io.stream.StreamInput; @@ -246,9 +245,9 @@ public void writeTo(StreamOutput out) throws IOException { out.writeStringCollection(patterns); Settings.writeSettingsToStream(settings, out); out.writeVInt(mappings.size()); - for (ObjectObjectCursor cursor : mappings) { - out.writeString(cursor.key); - cursor.value.writeTo(out); + for (Map.Entry cursor : mappings.entrySet()) { + out.writeString(cursor.getKey()); + cursor.getValue().writeTo(out); } out.writeVInt(aliases.size()); for (ObjectCursor cursor : aliases.values()) { 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 67df17d1ca108..abc6fba9356d9 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/Metadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/Metadata.java @@ -33,8 +33,8 @@ package org.opensearch.cluster.metadata; import com.carrotsearch.hppc.cursors.ObjectCursor; - import com.carrotsearch.hppc.cursors.ObjectObjectCursor; + import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; import org.apache.lucene.util.CollectionUtil; @@ -53,7 +53,7 @@ import org.opensearch.common.Nullable; import org.opensearch.common.Strings; import org.opensearch.common.UUIDs; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.regex.Regex; diff --git a/server/src/main/java/org/opensearch/cluster/metadata/MetadataDeleteIndexService.java b/server/src/main/java/org/opensearch/cluster/metadata/MetadataDeleteIndexService.java index 655b5ceb376f5..8d616bd4627b7 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/MetadataDeleteIndexService.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/MetadataDeleteIndexService.java @@ -47,7 +47,7 @@ import org.opensearch.cluster.service.ClusterManagerTaskThrottler; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.Priority; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.inject.Inject; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.set.Sets; diff --git a/server/src/main/java/org/opensearch/cluster/metadata/MetadataIndexStateService.java b/server/src/main/java/org/opensearch/cluster/metadata/MetadataIndexStateService.java index 6de69c5a6f8f4..3b1c63c7e693d 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/MetadataIndexStateService.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/MetadataIndexStateService.java @@ -32,7 +32,6 @@ package org.opensearch.cluster.metadata; -import com.carrotsearch.hppc.cursors.IntObjectCursor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; @@ -71,7 +70,7 @@ import org.opensearch.common.Priority; import org.opensearch.common.Strings; import org.opensearch.common.UUIDs; -import org.opensearch.common.collect.ImmutableOpenIntMap; +import org.opensearch.core.common.collect.ImmutableOpenIntMap; import org.opensearch.common.collect.Tuple; import org.opensearch.common.inject.Inject; import org.opensearch.common.settings.Setting; @@ -642,8 +641,8 @@ private void waitForShardsReadyForClosing( final AtomicArray results = new AtomicArray<>(shards.size()); final CountDown countDown = new CountDown(shards.size()); - for (IntObjectCursor shard : shards) { - final IndexShardRoutingTable shardRoutingTable = shard.value; + for (Map.Entry shard : shards.entrySet()) { + final IndexShardRoutingTable shardRoutingTable = shard.getValue(); final int shardId = shardRoutingTable.shardId().id(); sendVerifyShardBeforeCloseRequest(shardRoutingTable, closingBlock, new NotifyOnceListener() { @Override @@ -775,8 +774,8 @@ private void waitForShardsReady( final AtomicArray results = new AtomicArray<>(shards.size()); final CountDown countDown = new CountDown(shards.size()); - for (IntObjectCursor shard : shards) { - final IndexShardRoutingTable shardRoutingTable = shard.value; + for (Map.Entry shard : shards.entrySet()) { + final IndexShardRoutingTable shardRoutingTable = shard.getValue(); final int shardId = shardRoutingTable.shardId().id(); sendVerifyShardBlockRequest(shardRoutingTable, clusterBlock, new NotifyOnceListener() { @Override 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 22d7235fd1f98..16d5667324a5b 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/SystemIndexMetadataUpgradeService.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/SystemIndexMetadataUpgradeService.java @@ -104,7 +104,7 @@ public class SystemIndexMetadataUpdateTask extends ClusterStateUpdateTask { public ClusterState execute(ClusterState currentState) throws Exception { final Map indexMetadataMap = currentState.metadata().indices(); final List updatedMetadata = new ArrayList<>(); - for (Map.Entry cursor : indexMetadataMap.entrySet()) { + for (final 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/node/DiscoveryNodes.java b/server/src/main/java/org/opensearch/cluster/node/DiscoveryNodes.java index 22669c74c2223..f7491d507f622 100644 --- a/server/src/main/java/org/opensearch/cluster/node/DiscoveryNodes.java +++ b/server/src/main/java/org/opensearch/cluster/node/DiscoveryNodes.java @@ -34,14 +34,13 @@ import com.carrotsearch.hppc.ObjectHashSet; import com.carrotsearch.hppc.cursors.ObjectCursor; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.opensearch.Version; import org.opensearch.cluster.AbstractDiffable; import org.opensearch.cluster.Diff; import org.opensearch.common.Booleans; import org.opensearch.common.Nullable; import org.opensearch.common.Strings; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.regex.Regex; @@ -844,15 +843,15 @@ public DiscoveryNodes build() { Version maxNodeVersion = null; Version minNonClientNodeVersion = null; Version maxNonClientNodeVersion = null; - for (ObjectObjectCursor nodeEntry : nodes) { - if (nodeEntry.value.isDataNode()) { - dataNodesBuilder.put(nodeEntry.key, nodeEntry.value); + for (Map.Entry nodeEntry : nodes.build().entrySet()) { + if (nodeEntry.getValue().isDataNode()) { + dataNodesBuilder.put(nodeEntry.getKey(), nodeEntry.getValue()); } - if (nodeEntry.value.isClusterManagerNode()) { - clusterManagerNodesBuilder.put(nodeEntry.key, nodeEntry.value); + if (nodeEntry.getValue().isClusterManagerNode()) { + clusterManagerNodesBuilder.put(nodeEntry.getKey(), nodeEntry.getValue()); } - final Version version = nodeEntry.value.getVersion(); - if (nodeEntry.value.isDataNode() || nodeEntry.value.isClusterManagerNode()) { + final Version version = nodeEntry.getValue().getVersion(); + if (nodeEntry.getValue().isDataNode() || nodeEntry.getValue().isClusterManagerNode()) { if (minNonClientNodeVersion == null) { minNonClientNodeVersion = version; maxNonClientNodeVersion = version; @@ -861,8 +860,8 @@ public DiscoveryNodes build() { maxNonClientNodeVersion = Version.max(maxNonClientNodeVersion, version); } } - if (nodeEntry.value.isIngestNode()) { - ingestNodesBuilder.put(nodeEntry.key, nodeEntry.value); + if (nodeEntry.getValue().isIngestNode()) { + ingestNodesBuilder.put(nodeEntry.getKey(), nodeEntry.getValue()); } minNodeVersion = minNodeVersion == null ? version : Version.min(minNodeVersion, version); maxNodeVersion = maxNodeVersion == null ? version : Version.max(maxNodeVersion, version); diff --git a/server/src/main/java/org/opensearch/cluster/routing/IndexRoutingTable.java b/server/src/main/java/org/opensearch/cluster/routing/IndexRoutingTable.java index 9463f9ff0a422..2d14138b40e59 100644 --- a/server/src/main/java/org/opensearch/cluster/routing/IndexRoutingTable.java +++ b/server/src/main/java/org/opensearch/cluster/routing/IndexRoutingTable.java @@ -34,7 +34,6 @@ import com.carrotsearch.hppc.IntSet; import com.carrotsearch.hppc.cursors.IntCursor; -import com.carrotsearch.hppc.cursors.IntObjectCursor; import org.apache.lucene.util.CollectionUtil; import org.opensearch.cluster.AbstractDiffable; import org.opensearch.cluster.Diff; @@ -47,7 +46,7 @@ import org.opensearch.cluster.routing.RecoverySource.SnapshotRecoverySource; import org.opensearch.cluster.routing.RecoverySource.RemoteStoreRecoverySource; import org.opensearch.common.Randomness; -import org.opensearch.common.collect.ImmutableOpenIntMap; +import org.opensearch.core.common.collect.ImmutableOpenIntMap; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.index.Index; @@ -59,6 +58,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.function.Predicate; @@ -95,8 +95,8 @@ public class IndexRoutingTable extends AbstractDiffable imple this.shuffler = new RotationShardShuffler(Randomness.get().nextInt()); this.shards = shards; List allActiveShards = new ArrayList<>(); - for (IntObjectCursor cursor : shards) { - for (ShardRouting shardRouting : cursor.value) { + for (Map.Entry cursor : shards.entrySet()) { + for (ShardRouting shardRouting : cursor.getValue()) { if (shardRouting.active()) { allActiveShards.add(shardRouting); } diff --git a/server/src/main/java/org/opensearch/cluster/routing/RoutingTable.java b/server/src/main/java/org/opensearch/cluster/routing/RoutingTable.java index 15bb997bfb05a..11c09529f311e 100644 --- a/server/src/main/java/org/opensearch/cluster/routing/RoutingTable.java +++ b/server/src/main/java/org/opensearch/cluster/routing/RoutingTable.java @@ -34,7 +34,6 @@ import com.carrotsearch.hppc.IntSet; import com.carrotsearch.hppc.cursors.ObjectCursor; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.opensearch.cluster.Diff; import org.opensearch.cluster.Diffable; import org.opensearch.cluster.DiffableUtils; @@ -43,7 +42,7 @@ import org.opensearch.cluster.routing.RecoverySource.SnapshotRecoverySource; import org.opensearch.cluster.routing.RecoverySource.RemoteStoreRecoverySource; import org.opensearch.common.Nullable; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.util.iterable.Iterables; @@ -635,8 +634,8 @@ public RoutingTable build() { @Override public String toString() { StringBuilder sb = new StringBuilder("routing_table (version ").append(version).append("):\n"); - for (ObjectObjectCursor entry : indicesRouting) { - sb.append(entry.value.prettyPrint()).append('\n'); + for (Map.Entry entry : indicesRouting.entrySet()) { + sb.append(entry.getValue().prettyPrint()).append('\n'); } return sb.toString(); } diff --git a/server/src/main/java/org/opensearch/cluster/routing/allocation/AllocationService.java b/server/src/main/java/org/opensearch/cluster/routing/allocation/AllocationService.java index 5169e63aeb9a5..3f4c31d484c26 100644 --- a/server/src/main/java/org/opensearch/cluster/routing/allocation/AllocationService.java +++ b/server/src/main/java/org/opensearch/cluster/routing/allocation/AllocationService.java @@ -54,7 +54,7 @@ import org.opensearch.cluster.routing.allocation.command.AllocationCommands; import org.opensearch.cluster.routing.allocation.decider.AllocationDeciders; import org.opensearch.cluster.routing.allocation.decider.Decision; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.gateway.GatewayAllocator; import org.opensearch.gateway.PriorityComparator; import org.opensearch.snapshots.SnapshotsInfoService; diff --git a/server/src/main/java/org/opensearch/cluster/routing/allocation/RoutingAllocation.java b/server/src/main/java/org/opensearch/cluster/routing/allocation/RoutingAllocation.java index 3ac22f5eee362..0b9d80ca9684f 100644 --- a/server/src/main/java/org/opensearch/cluster/routing/allocation/RoutingAllocation.java +++ b/server/src/main/java/org/opensearch/cluster/routing/allocation/RoutingAllocation.java @@ -43,7 +43,7 @@ import org.opensearch.cluster.routing.ShardRouting; import org.opensearch.cluster.routing.allocation.decider.AllocationDeciders; import org.opensearch.cluster.routing.allocation.decider.Decision; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.index.shard.ShardId; import org.opensearch.snapshots.RestoreService.RestoreInProgressUpdater; import org.opensearch.snapshots.SnapshotShardSizeInfo; diff --git a/server/src/main/java/org/opensearch/common/io/stream/StreamInput.java b/server/src/main/java/org/opensearch/common/io/stream/StreamInput.java index 419308880f04e..9fb3a30e28641 100644 --- a/server/src/main/java/org/opensearch/common/io/stream/StreamInput.java +++ b/server/src/main/java/org/opensearch/common/io/stream/StreamInput.java @@ -49,7 +49,7 @@ import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.geo.GeoPoint; import org.opensearch.common.settings.SecureString; import org.opensearch.common.text.Text; diff --git a/server/src/main/java/org/opensearch/common/io/stream/StreamOutput.java b/server/src/main/java/org/opensearch/common/io/stream/StreamOutput.java index f3c184ea288bd..54b9ad2de0d84 100644 --- a/server/src/main/java/org/opensearch/common/io/stream/StreamOutput.java +++ b/server/src/main/java/org/opensearch/common/io/stream/StreamOutput.java @@ -32,7 +32,6 @@ package org.opensearch.common.io.stream; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.apache.lucene.index.CorruptIndexException; import org.apache.lucene.index.IndexFormatTooNewException; import org.apache.lucene.index.IndexFormatTooOldException; @@ -51,7 +50,7 @@ import org.opensearch.common.Nullable; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.geo.GeoPoint; import org.opensearch.common.io.stream.Writeable.Writer; import org.opensearch.common.settings.SecureString; @@ -649,9 +648,9 @@ public final void writeMap(final Map map, final Writer keyWriter public final void writeMap(final ImmutableOpenMap map, final Writer keyWriter, final Writer valueWriter) throws IOException { writeVInt(map.size()); - for (final ObjectObjectCursor entry : map) { - keyWriter.write(this, entry.key); - valueWriter.write(this, entry.value); + for (final Map.Entry entry : map.entrySet()) { + keyWriter.write(this, entry.getKey()); + valueWriter.write(this, entry.getValue()); } } diff --git a/server/src/main/java/org/opensearch/gateway/AsyncShardFetch.java b/server/src/main/java/org/opensearch/gateway/AsyncShardFetch.java index b5c4d00228caa..30224e587c214 100644 --- a/server/src/main/java/org/opensearch/gateway/AsyncShardFetch.java +++ b/server/src/main/java/org/opensearch/gateway/AsyncShardFetch.java @@ -31,7 +31,6 @@ package org.opensearch.gateway; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; import org.opensearch.OpenSearchTimeoutException; @@ -295,8 +294,8 @@ synchronized void clearCacheForNode(String nodeId) { */ private void fillShardCacheWithDataNodes(Map> shardCache, DiscoveryNodes nodes) { // verify that all current data nodes are there - for (ObjectObjectCursor cursor : nodes.getDataNodes()) { - DiscoveryNode node = cursor.value; + for (Map.Entry cursor : nodes.getDataNodes().entrySet()) { + DiscoveryNode node = cursor.getValue(); if (shardCache.containsKey(node.getId()) == false) { shardCache.put(node.getId(), new NodeEntry(node.getId())); } diff --git a/server/src/main/java/org/opensearch/gateway/GatewayAllocator.java b/server/src/main/java/org/opensearch/gateway/GatewayAllocator.java index cdcf813d9ede0..dc19e85b71e0b 100644 --- a/server/src/main/java/org/opensearch/gateway/GatewayAllocator.java +++ b/server/src/main/java/org/opensearch/gateway/GatewayAllocator.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.logging.log4j.message.ParameterizedMessage; @@ -58,6 +57,7 @@ import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentMap; import java.util.stream.Collectors; @@ -233,8 +233,8 @@ private static void clearCacheForPrimary( } private boolean hasNewNodes(DiscoveryNodes nodes) { - for (ObjectObjectCursor node : nodes.getDataNodes()) { - if (lastSeenEphemeralIds.contains(node.value.getEphemeralId()) == false) { + for (Map.Entry node : nodes.getDataNodes().entrySet()) { + if (lastSeenEphemeralIds.contains(node.getValue().getEphemeralId()) == false) { return true; } } diff --git a/server/src/main/java/org/opensearch/index/mapper/FieldMapper.java b/server/src/main/java/org/opensearch/index/mapper/FieldMapper.java index a2b0702edb9a3..f187ab5f1cdbc 100644 --- a/server/src/main/java/org/opensearch/index/mapper/FieldMapper.java +++ b/server/src/main/java/org/opensearch/index/mapper/FieldMapper.java @@ -33,12 +33,11 @@ package org.opensearch.index.mapper; import com.carrotsearch.hppc.cursors.ObjectCursor; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; import org.apache.lucene.index.IndexOptions; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Setting.Property; import org.opensearch.common.settings.Settings; @@ -625,9 +624,9 @@ public MultiFields build(Mapper.Builder mainFieldBuilder, BuilderContext context } else { context.path().add(mainFieldBuilder.name()); ImmutableOpenMap.Builder mapperBuilders = this.mapperBuilders; - for (ObjectObjectCursor cursor : this.mapperBuilders) { - String key = cursor.key; - Mapper.Builder value = cursor.value; + for (Map.Entry cursor : this.mapperBuilders.build().entrySet()) { + String key = cursor.getKey(); + Mapper.Builder value = cursor.getValue(); Mapper mapper = value.build(context); assert mapper instanceof FieldMapper; mapperBuilders.put(key, mapper); @@ -644,8 +643,8 @@ public MultiFields build(Mapper.Builder mainFieldBuilder, BuilderContext context private MultiFields(ImmutableOpenMap mappers) { ImmutableOpenMap.Builder builder = new ImmutableOpenMap.Builder<>(); // we disable the all in multi-field mappers - for (ObjectObjectCursor cursor : mappers) { - builder.put(cursor.key, cursor.value); + for (Map.Entry cursor : mappers.entrySet()) { + builder.put(cursor.getKey(), cursor.getValue()); } this.mappers = builder.build(); } diff --git a/server/src/main/java/org/opensearch/rest/action/admin/indices/RestGetAliasesAction.java b/server/src/main/java/org/opensearch/rest/action/admin/indices/RestGetAliasesAction.java index 6afc0f425992b..149e3d1302b5e 100644 --- a/server/src/main/java/org/opensearch/rest/action/admin/indices/RestGetAliasesAction.java +++ b/server/src/main/java/org/opensearch/rest/action/admin/indices/RestGetAliasesAction.java @@ -32,7 +32,6 @@ package org.opensearch.rest.action.admin.indices; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.opensearch.action.admin.indices.alias.get.GetAliasesRequest; import org.opensearch.action.admin.indices.alias.get.GetAliasesResponse; import org.opensearch.action.support.IndicesOptions; @@ -40,7 +39,7 @@ import org.opensearch.cluster.metadata.AliasMetadata; import org.opensearch.cluster.metadata.Metadata; import org.opensearch.common.Strings; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.regex.Regex; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; @@ -55,6 +54,7 @@ import java.util.HashSet; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -100,11 +100,11 @@ static RestResponse buildRestResponse( ) throws Exception { final Set indicesToDisplay = new HashSet<>(); final Set returnedAliasNames = new HashSet<>(); - for (final ObjectObjectCursor> cursor : responseAliasMap) { - for (final AliasMetadata aliasMetadata : cursor.value) { + for (final Map.Entry> cursor : responseAliasMap.entrySet()) { + for (final AliasMetadata aliasMetadata : cursor.getValue()) { if (aliasesExplicitlyRequested) { // only display indices that have aliases - indicesToDisplay.add(cursor.key); + indicesToDisplay.add(cursor.getKey()); } returnedAliasNames.add(aliasMetadata.alias()); } @@ -165,13 +165,13 @@ static RestResponse buildRestResponse( builder.field("status", status.getStatus()); } - for (final ObjectObjectCursor> entry : responseAliasMap) { - if (aliasesExplicitlyRequested == false || (aliasesExplicitlyRequested && indicesToDisplay.contains(entry.key))) { - builder.startObject(entry.key); + for (final Map.Entry> entry : responseAliasMap.entrySet()) { + if (aliasesExplicitlyRequested == false || (aliasesExplicitlyRequested && indicesToDisplay.contains(entry.getKey()))) { + builder.startObject(entry.getKey()); { builder.startObject("aliases"); { - for (final AliasMetadata alias : entry.value) { + for (final AliasMetadata alias : entry.getValue()) { AliasMetadata.Builder.toXContent(alias, builder, ToXContent.EMPTY_PARAMS); } } diff --git a/server/src/main/java/org/opensearch/rest/action/cat/RestAliasAction.java b/server/src/main/java/org/opensearch/rest/action/cat/RestAliasAction.java index 7aa91c175dbf0..2c0fb4b16c38d 100644 --- a/server/src/main/java/org/opensearch/rest/action/cat/RestAliasAction.java +++ b/server/src/main/java/org/opensearch/rest/action/cat/RestAliasAction.java @@ -31,7 +31,6 @@ package org.opensearch.rest.action.cat; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.opensearch.action.admin.indices.alias.get.GetAliasesRequest; import org.opensearch.action.admin.indices.alias.get.GetAliasesResponse; import org.opensearch.action.support.IndicesOptions; @@ -44,6 +43,7 @@ import org.opensearch.rest.action.RestResponseListener; import java.util.List; +import java.util.Map; import static java.util.Arrays.asList; import static java.util.Collections.unmodifiableList; @@ -111,9 +111,9 @@ protected Table getTableWithHeader(RestRequest request) { private Table buildTable(RestRequest request, GetAliasesResponse response) { Table table = getTableWithHeader(request); - for (ObjectObjectCursor> cursor : response.getAliases()) { - String indexName = cursor.key; - for (AliasMetadata aliasMetadata : cursor.value) { + for (Map.Entry> cursor : response.getAliases().entrySet()) { + String indexName = cursor.getKey(); + for (AliasMetadata aliasMetadata : cursor.getValue()) { table.startRow(); table.addCell(aliasMetadata.alias()); table.addCell(indexName); diff --git a/server/src/main/java/org/opensearch/search/internal/ShardSearchRequest.java b/server/src/main/java/org/opensearch/search/internal/ShardSearchRequest.java index 2fae76712705a..0ca90bdb1a524 100644 --- a/server/src/main/java/org/opensearch/search/internal/ShardSearchRequest.java +++ b/server/src/main/java/org/opensearch/search/internal/ShardSearchRequest.java @@ -45,7 +45,7 @@ import org.opensearch.common.Nullable; import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; diff --git a/server/src/main/java/org/opensearch/snapshots/EmptySnapshotsInfoService.java b/server/src/main/java/org/opensearch/snapshots/EmptySnapshotsInfoService.java index 8629790bc9cbb..fdc9a96b098a3 100644 --- a/server/src/main/java/org/opensearch/snapshots/EmptySnapshotsInfoService.java +++ b/server/src/main/java/org/opensearch/snapshots/EmptySnapshotsInfoService.java @@ -32,7 +32,7 @@ package org.opensearch.snapshots; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; /** * Service for getting information about empty snapshots diff --git a/server/src/main/java/org/opensearch/snapshots/InFlightShardSnapshotStates.java b/server/src/main/java/org/opensearch/snapshots/InFlightShardSnapshotStates.java index 17d77fcc0695b..82cfdfbac50e8 100644 --- a/server/src/main/java/org/opensearch/snapshots/InFlightShardSnapshotStates.java +++ b/server/src/main/java/org/opensearch/snapshots/InFlightShardSnapshotStates.java @@ -32,7 +32,6 @@ package org.opensearch.snapshots; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.opensearch.cluster.SnapshotsInProgress; import org.opensearch.common.Nullable; import org.opensearch.index.shard.ShardId; @@ -73,14 +72,14 @@ public static InFlightShardSnapshotStates forRepo(String repoName, List clone : runningSnapshot.clones()) { - final RepositoryShardId repoShardId = clone.key; - addStateInformation(generations, busyIds, clone.value, repoShardId.shardId(), repoShardId.indexName()); + for (Map.Entry clone : runningSnapshot.clones().entrySet()) { + final RepositoryShardId repoShardId = clone.getKey(); + addStateInformation(generations, busyIds, clone.getValue(), repoShardId.shardId(), repoShardId.indexName()); } } else { - for (ObjectObjectCursor shard : runningSnapshot.shards()) { - final ShardId sid = shard.key; - addStateInformation(generations, busyIds, shard.value, sid.id(), sid.getIndexName()); + for (Map.Entry shard : runningSnapshot.shards().entrySet()) { + final ShardId sid = shard.getKey(); + addStateInformation(generations, busyIds, shard.getValue(), sid.id(), sid.getIndexName()); } } } diff --git a/server/src/main/java/org/opensearch/snapshots/InternalSnapshotsInfoService.java b/server/src/main/java/org/opensearch/snapshots/InternalSnapshotsInfoService.java index 518e4a558b2df..eac77d95546bc 100644 --- a/server/src/main/java/org/opensearch/snapshots/InternalSnapshotsInfoService.java +++ b/server/src/main/java/org/opensearch/snapshots/InternalSnapshotsInfoService.java @@ -47,7 +47,7 @@ import org.opensearch.cluster.routing.ShardRoutingState; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.Priority; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; diff --git a/server/src/main/java/org/opensearch/snapshots/RestoreService.java b/server/src/main/java/org/opensearch/snapshots/RestoreService.java index 40898db05ebe4..4ba9c955a8609 100644 --- a/server/src/main/java/org/opensearch/snapshots/RestoreService.java +++ b/server/src/main/java/org/opensearch/snapshots/RestoreService.java @@ -34,7 +34,6 @@ import com.carrotsearch.hppc.IntHashSet; import com.carrotsearch.hppc.IntSet; import com.carrotsearch.hppc.cursors.ObjectCursor; -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; @@ -79,13 +78,13 @@ import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.Priority; import org.opensearch.common.UUIDs; -import org.opensearch.common.collect.ImmutableOpenMap; import org.opensearch.common.lucene.Lucene; import org.opensearch.common.regex.Regex; import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; import org.opensearch.common.util.FeatureFlags; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.index.Index; import org.opensearch.index.IndexModule; import org.opensearch.index.IndexSettings; @@ -854,8 +853,8 @@ public static RestoreInProgress updateRestoreStateWithDeletedIndices(RestoreInPr RestoreInProgress.Builder builder = new RestoreInProgress.Builder(); for (RestoreInProgress.Entry entry : oldRestore) { ImmutableOpenMap.Builder shardsBuilder = null; - for (ObjectObjectCursor cursor : entry.shards()) { - ShardId shardId = cursor.key; + for (Map.Entry cursor : entry.shards().entrySet()) { + ShardId shardId = cursor.getKey(); if (deletedIndices.contains(shardId.getIndex())) { changesMade = true; if (shardsBuilder == null) { @@ -1214,10 +1213,10 @@ public static boolean failed(SnapshotInfo snapshot, String index) { public static Set restoringIndices(final ClusterState currentState, final Set indicesToCheck) { final Set indices = new HashSet<>(); for (RestoreInProgress.Entry entry : currentState.custom(RestoreInProgress.TYPE, RestoreInProgress.EMPTY)) { - for (ObjectObjectCursor shard : entry.shards()) { - Index index = shard.key.getIndex(); + for (Map.Entry shard : entry.shards().entrySet()) { + Index index = shard.getKey().getIndex(); if (indicesToCheck.contains(index) - && shard.value.state().completed() == false + && shard.getValue().state().completed() == false && currentState.getMetadata().index(index) != null) { indices.add(index); } diff --git a/server/src/main/java/org/opensearch/snapshots/SnapshotShardSizeInfo.java b/server/src/main/java/org/opensearch/snapshots/SnapshotShardSizeInfo.java index 6c951078e59e6..a3a78c80b4979 100644 --- a/server/src/main/java/org/opensearch/snapshots/SnapshotShardSizeInfo.java +++ b/server/src/main/java/org/opensearch/snapshots/SnapshotShardSizeInfo.java @@ -34,7 +34,7 @@ import org.opensearch.cluster.routing.RecoverySource; import org.opensearch.cluster.routing.ShardRouting; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; /** * Information about a snapshot shard size diff --git a/server/src/main/java/org/opensearch/snapshots/SnapshotShardsService.java b/server/src/main/java/org/opensearch/snapshots/SnapshotShardsService.java index 4c37af46bd101..022afcf2e49a7 100644 --- a/server/src/main/java/org/opensearch/snapshots/SnapshotShardsService.java +++ b/server/src/main/java/org/opensearch/snapshots/SnapshotShardsService.java @@ -32,7 +32,6 @@ package org.opensearch.snapshots; -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,7 @@ import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.Nullable; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.component.AbstractLifecycleComponent; import org.opensearch.common.concurrent.GatedCloseable; import org.opensearch.common.io.stream.StreamInput; @@ -227,10 +226,10 @@ private void startNewSnapshots(SnapshotsInProgress snapshotsInProgress) { Map startedShards = null; final Snapshot snapshot = entry.snapshot(); Map snapshotShards = shardSnapshots.getOrDefault(snapshot, emptyMap()); - for (ObjectObjectCursor shard : entry.shards()) { + for (Map.Entry shard : entry.shards().entrySet()) { // Add all new shards to start processing on - final ShardId shardId = shard.key; - final ShardSnapshotStatus shardSnapshotStatus = shard.value; + final ShardId shardId = shard.getKey(); + final ShardSnapshotStatus shardSnapshotStatus = shard.getValue(); if (shardSnapshotStatus.state() == ShardState.INIT && localNodeId.equals(shardSnapshotStatus.nodeId()) && snapshotShards.containsKey(shardId) == false) { @@ -249,13 +248,13 @@ private void startNewSnapshots(SnapshotsInProgress snapshotsInProgress) { // Abort all running shards for this snapshot final Snapshot snapshot = entry.snapshot(); Map snapshotShards = shardSnapshots.getOrDefault(snapshot, emptyMap()); - for (ObjectObjectCursor shard : entry.shards()) { - final IndexShardSnapshotStatus snapshotStatus = snapshotShards.get(shard.key); + for (Map.Entry shard : entry.shards().entrySet()) { + final IndexShardSnapshotStatus snapshotStatus = snapshotShards.get(shard.getKey()); if (snapshotStatus == null) { // due to CS batching we might have missed the INIT state and straight went into ABORTED // notify cluster-manager that abort has completed by moving to FAILED - if (shard.value.state() == ShardState.ABORTED && localNodeId.equals(shard.value.nodeId())) { - notifyFailedSnapshotShard(snapshot, shard.key, shard.value.reason()); + if (shard.getValue().state() == ShardState.ABORTED && localNodeId.equals(shard.getValue().nodeId())) { + notifyFailedSnapshotShard(snapshot, shard.getKey(), shard.getValue().reason()); } } else { snapshotStatus.abortIfNotCompleted("snapshot has been aborted"); diff --git a/server/src/main/java/org/opensearch/snapshots/SnapshotsService.java b/server/src/main/java/org/opensearch/snapshots/SnapshotsService.java index 645775c3ec09c..5581ed80f47e0 100644 --- a/server/src/main/java/org/opensearch/snapshots/SnapshotsService.java +++ b/server/src/main/java/org/opensearch/snapshots/SnapshotsService.java @@ -33,7 +33,6 @@ package org.opensearch.snapshots; import com.carrotsearch.hppc.cursors.ObjectCursor; -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; @@ -83,7 +82,7 @@ import org.opensearch.common.Priority; import org.opensearch.common.Strings; import org.opensearch.common.UUIDs; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.collect.Tuple; import org.opensearch.common.component.AbstractLifecycleComponent; import org.opensearch.common.io.stream.StreamInput; @@ -325,9 +324,9 @@ public ClusterState execute(ClusterState currentState) { ); if (request.partial() == false) { Set missing = new HashSet<>(); - for (ObjectObjectCursor entry : shards) { - if (entry.value.state() == ShardState.MISSING) { - missing.add(entry.key.getIndex().getName()); + for (Map.Entry entry : shards.entrySet()) { + if (entry.getValue().state() == ShardState.MISSING) { + missing.add(entry.getKey().getIndex().getName()); } } if (missing.isEmpty() == false) { @@ -641,12 +640,12 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS if (updatedEntry != null) { final Snapshot target = updatedEntry.snapshot(); final SnapshotId sourceSnapshot = updatedEntry.source(); - for (ObjectObjectCursor indexClone : updatedEntry.clones()) { - final ShardSnapshotStatus shardStatusBefore = indexClone.value; + for (Map.Entry indexClone : updatedEntry.clones().entrySet()) { + final ShardSnapshotStatus shardStatusBefore = indexClone.getValue(); if (shardStatusBefore.state() != ShardState.INIT) { continue; } - final RepositoryShardId repoShardId = indexClone.key; + final RepositoryShardId repoShardId = indexClone.getKey(); runReadyClone(target, sourceSnapshot, shardStatusBefore, repoShardId, repository); } } else { @@ -1176,9 +1175,9 @@ private static ImmutableOpenMap processWaitingShar ) { boolean snapshotChanged = false; ImmutableOpenMap.Builder shards = ImmutableOpenMap.builder(); - for (ObjectObjectCursor shardEntry : snapshotShards) { - ShardSnapshotStatus shardStatus = shardEntry.value; - ShardId shardId = shardEntry.key; + for (Map.Entry shardEntry : snapshotShards.entrySet()) { + ShardSnapshotStatus shardStatus = shardEntry.getValue(); + ShardId shardId = shardEntry.getKey(); if (shardStatus.equals(ShardSnapshotStatus.UNASSIGNED_QUEUED)) { // this shard snapshot is waiting for a previous snapshot to finish execution for this shard final ShardSnapshotStatus knownFailure = knownFailures.get(shardId); @@ -1253,11 +1252,11 @@ private static ImmutableOpenMap processWaitingShar private static boolean waitingShardsStartedOrUnassigned(SnapshotsInProgress snapshotsInProgress, ClusterChangedEvent event) { for (SnapshotsInProgress.Entry entry : snapshotsInProgress.entries()) { if (entry.state() == State.STARTED) { - for (ObjectObjectCursor shardStatus : entry.shards()) { - if (shardStatus.value.state() != ShardState.WAITING) { + for (Map.Entry shardStatus : entry.shards().entrySet()) { + if (shardStatus.getValue().state() != ShardState.WAITING) { continue; } - final ShardId shardId = shardStatus.key; + final ShardId shardId = shardStatus.getKey(); if (event.indexRoutingTableChanged(shardId.getIndexName())) { IndexRoutingTable indexShardRoutingTable = event.state().getRoutingTable().index(shardId.getIndex()); if (indexShardRoutingTable == null) { @@ -1378,9 +1377,9 @@ private void finalizeSnapshotEntry(SnapshotsInProgress.Entry entry, Metadata met final Snapshot snapshot = entry.snapshot(); logger.trace("[{}] finalizing snapshot in repository, state: [{}], failure[{}]", snapshot, entry.state(), failure); ArrayList shardFailures = new ArrayList<>(); - for (ObjectObjectCursor shardStatus : entry.shards()) { - ShardId shardId = shardStatus.key; - ShardSnapshotStatus status = shardStatus.value; + for (Map.Entry shardStatus : entry.shards().entrySet()) { + ShardId shardId = shardStatus.getKey(); + ShardSnapshotStatus status = shardStatus.getValue(); final ShardState state = status.state(); if (state.failed()) { shardFailures.add(new SnapshotShardFailure(status.nodeId(), shardId, status.reason())); @@ -2384,10 +2383,10 @@ private SnapshotsInProgress updatedSnapshotsInProgress(ClusterState currentState if (entry.state().completed() == false) { // Collect waiting shards that in entry that we can assign now that we are done with the deletion final List canBeUpdated = new ArrayList<>(); - for (ObjectObjectCursor value : entry.shards()) { - if (value.value.equals(ShardSnapshotStatus.UNASSIGNED_QUEUED) - && reassignedShardIds.contains(value.key) == false) { - canBeUpdated.add(value.key); + for (Map.Entry value : entry.shards().entrySet()) { + if (value.getValue().equals(ShardSnapshotStatus.UNASSIGNED_QUEUED) + && reassignedShardIds.contains(value.getKey()) == false) { + canBeUpdated.add(value.getKey()); } } if (canBeUpdated.isEmpty()) { @@ -3076,13 +3075,13 @@ private void startExecutableClones(SnapshotsInProgress snapshotsInProgress, @Nul for (SnapshotsInProgress.Entry entry : snapshotsInProgress.entries()) { if (entry.isClone() && entry.state() == State.STARTED && (repoName == null || entry.repository().equals(repoName))) { // this is a clone, see if new work is ready - for (ObjectObjectCursor clone : entry.clones()) { - if (clone.value.state() == ShardState.INIT) { + for (Map.Entry clone : entry.clones().entrySet()) { + if (clone.getValue().state() == ShardState.INIT) { runReadyClone( entry.snapshot(), entry.source(), - clone.value, - clone.key, + clone.getValue(), + clone.getKey(), repositoriesService.repository(entry.repository()) ); } diff --git a/server/src/test/java/org/opensearch/action/admin/indices/alias/get/GetAliasesResponseTests.java b/server/src/test/java/org/opensearch/action/admin/indices/alias/get/GetAliasesResponseTests.java index 98a6aba1932d5..3f7a26f937e24 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/alias/get/GetAliasesResponseTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/alias/get/GetAliasesResponseTests.java @@ -34,7 +34,7 @@ import org.opensearch.cluster.metadata.AliasMetadata; import org.opensearch.cluster.metadata.AliasMetadata.Builder; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.Writeable; import org.opensearch.test.AbstractWireSerializingTestCase; diff --git a/server/src/test/java/org/opensearch/action/admin/indices/alias/get/TransportGetAliasesActionTests.java b/server/src/test/java/org/opensearch/action/admin/indices/alias/get/TransportGetAliasesActionTests.java index 46da611d9c2a7..d20fb7f6eb5dd 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/alias/get/TransportGetAliasesActionTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/alias/get/TransportGetAliasesActionTests.java @@ -36,7 +36,7 @@ import org.opensearch.cluster.metadata.AliasMetadata; import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.cluster.metadata.Metadata; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.indices.SystemIndexDescriptor; import org.opensearch.indices.SystemIndices; import org.opensearch.test.OpenSearchTestCase; diff --git a/server/src/test/java/org/opensearch/action/admin/indices/datastream/DeleteDataStreamRequestTests.java b/server/src/test/java/org/opensearch/action/admin/indices/datastream/DeleteDataStreamRequestTests.java index e33b873a52f19..60171b91db758 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/datastream/DeleteDataStreamRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/datastream/DeleteDataStreamRequestTests.java @@ -42,7 +42,7 @@ import org.opensearch.cluster.metadata.Metadata; import org.opensearch.cluster.metadata.MetadataDeleteIndexService; import org.opensearch.common.Strings; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.collect.Tuple; import org.opensearch.common.io.stream.Writeable; import org.opensearch.common.settings.Settings; 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 225c435ee1106..b9791e781f560 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 @@ -37,7 +37,7 @@ import org.opensearch.action.admin.indices.mapping.get.GetMappingsResponseTests; import org.opensearch.cluster.metadata.AliasMetadata; import org.opensearch.cluster.metadata.MappingMetadata; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.Writeable; import org.opensearch.common.settings.IndexScopedSettings; import org.opensearch.common.settings.Settings; diff --git a/server/src/test/java/org/opensearch/action/admin/indices/settings/get/GetSettingsResponseTests.java b/server/src/test/java/org/opensearch/action/admin/indices/settings/get/GetSettingsResponseTests.java index 6de6fe6a4ddb0..bab3222d3d950 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/settings/get/GetSettingsResponseTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/settings/get/GetSettingsResponseTests.java @@ -32,7 +32,7 @@ package org.opensearch.action.admin.indices.settings.get; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.Writeable; import org.opensearch.common.settings.IndexScopedSettings; import org.opensearch.common.settings.Settings; diff --git a/server/src/test/java/org/opensearch/action/admin/indices/shards/IndicesShardStoreResponseTests.java b/server/src/test/java/org/opensearch/action/admin/indices/shards/IndicesShardStoreResponseTests.java index 4c215b89dd96f..176cb59e52983 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/shards/IndicesShardStoreResponseTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/shards/IndicesShardStoreResponseTests.java @@ -37,8 +37,8 @@ import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.common.UUIDs; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.collect.ImmutableOpenIntMap; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenIntMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; 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 5881c72587756..592c07f7b356a 100644 --- a/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionIngestTests.java +++ b/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionIngestTests.java @@ -57,7 +57,7 @@ import org.opensearch.cluster.node.DiscoveryNodes; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.Nullable; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.collect.MapBuilder; import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Settings; diff --git a/server/src/test/java/org/opensearch/cluster/ClusterStateTests.java b/server/src/test/java/org/opensearch/cluster/ClusterStateTests.java index e4c9c14e5f157..4dc527e8cfaba 100644 --- a/server/src/test/java/org/opensearch/cluster/ClusterStateTests.java +++ b/server/src/test/java/org/opensearch/cluster/ClusterStateTests.java @@ -50,7 +50,7 @@ import org.opensearch.cluster.routing.ShardRoutingState; import org.opensearch.cluster.routing.TestShardRouting; import org.opensearch.common.Strings; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.settings.Settings; import org.opensearch.common.transport.TransportAddress; import org.opensearch.core.xcontent.ToXContent; diff --git a/server/src/test/java/org/opensearch/cluster/block/ClusterBlockTests.java b/server/src/test/java/org/opensearch/cluster/block/ClusterBlockTests.java index af82e143faa37..0da8d67398801 100644 --- a/server/src/test/java/org/opensearch/cluster/block/ClusterBlockTests.java +++ b/server/src/test/java/org/opensearch/cluster/block/ClusterBlockTests.java @@ -34,7 +34,7 @@ import org.opensearch.Version; import org.opensearch.common.UUIDs; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.rest.RestStatus; diff --git a/server/src/test/java/org/opensearch/cluster/health/ClusterStateHealthTests.java b/server/src/test/java/org/opensearch/cluster/health/ClusterStateHealthTests.java index 19458c9f8a4f3..02df569a11857 100644 --- a/server/src/test/java/org/opensearch/cluster/health/ClusterStateHealthTests.java +++ b/server/src/test/java/org/opensearch/cluster/health/ClusterStateHealthTests.java @@ -31,7 +31,6 @@ package org.opensearch.cluster.health; -import com.carrotsearch.hppc.cursors.IntObjectCursor; import com.carrotsearch.hppc.cursors.ObjectCursor; import org.opensearch.Version; import org.opensearch.action.admin.cluster.health.ClusterHealthRequest; @@ -56,7 +55,7 @@ import org.opensearch.cluster.routing.allocation.AllocationService; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.UUIDs; -import org.opensearch.common.collect.ImmutableOpenIntMap; +import org.opensearch.core.common.collect.ImmutableOpenIntMap; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.settings.Settings; @@ -78,6 +77,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; @@ -448,8 +448,8 @@ private List generateClusterStates( } routingTable = RoutingTable.builder(routingTable).add(newIndexRoutingTable).build(); IndexMetadata.Builder idxMetaBuilder = IndexMetadata.builder(clusterState.metadata().index(indexName)); - for (final IntObjectCursor> entry : allocationIds.build()) { - idxMetaBuilder.putInSyncAllocationIds(entry.key, entry.value); + for (final Map.Entry> entry : allocationIds.build().entrySet()) { + idxMetaBuilder.putInSyncAllocationIds(entry.getKey(), entry.getValue()); } Metadata.Builder metadataBuilder = Metadata.builder(clusterState.metadata()).put(idxMetaBuilder); clusterState = ClusterState.builder(clusterState).routingTable(routingTable).metadata(metadataBuilder).build(); @@ -496,8 +496,8 @@ private List generateClusterStates( } routingTable = RoutingTable.builder(routingTable).add(newIndexRoutingTable).build(); idxMetaBuilder = IndexMetadata.builder(clusterState.metadata().index(indexName)); - for (final IntObjectCursor> entry : allocationIds.build()) { - idxMetaBuilder.putInSyncAllocationIds(entry.key, entry.value); + for (final Map.Entry> entry : allocationIds.build().entrySet()) { + idxMetaBuilder.putInSyncAllocationIds(entry.getKey(), entry.getValue()); } metadataBuilder = Metadata.builder(clusterState.metadata()).put(idxMetaBuilder); clusterState = ClusterState.builder(clusterState).routingTable(routingTable).metadata(metadataBuilder).build(); @@ -568,10 +568,13 @@ private List generateClusterStates( // returns true if the inactive primaries in the index are only due to cluster recovery // (not because of allocation of existing shard or previously having allocation ids assigned) private boolean primaryInactiveDueToRecovery(final String indexName, final ClusterState clusterState) { - for (final IntObjectCursor shardRouting : clusterState.routingTable().index(indexName).shards()) { - final ShardRouting primaryShard = shardRouting.value.primaryShard(); + for (final Map.Entry shardRouting : clusterState.routingTable() + .index(indexName) + .shards() + .entrySet()) { + final ShardRouting primaryShard = shardRouting.getValue().primaryShard(); if (primaryShard.active() == false) { - if (clusterState.metadata().index(indexName).inSyncAllocationIds(shardRouting.key).isEmpty() == false) { + if (clusterState.metadata().index(indexName).inSyncAllocationIds(shardRouting.getKey()).isEmpty() == false) { return false; } if (primaryShard.recoverySource() != null diff --git a/server/src/test/java/org/opensearch/cluster/metadata/IndexMetadataTests.java b/server/src/test/java/org/opensearch/cluster/metadata/IndexMetadataTests.java index e1482069d55dd..11d9c3aaf03f5 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/IndexMetadataTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/IndexMetadataTests.java @@ -38,7 +38,7 @@ import org.opensearch.action.admin.indices.rollover.RolloverInfo; import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.NamedWriteableAwareStreamInput; import org.opensearch.common.io.stream.NamedWriteableRegistry; diff --git a/server/src/test/java/org/opensearch/cluster/metadata/IndexTemplateMetadataTests.java b/server/src/test/java/org/opensearch/cluster/metadata/IndexTemplateMetadataTests.java index 5a358f581fa9a..412d3bae9280b 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/IndexTemplateMetadataTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/IndexTemplateMetadataTests.java @@ -33,7 +33,7 @@ import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.settings.Settings; import org.opensearch.core.xcontent.DeprecationHandler; import org.opensearch.core.xcontent.NamedXContentRegistry; diff --git a/server/src/test/java/org/opensearch/cluster/metadata/MetadataDeleteIndexServiceTests.java b/server/src/test/java/org/opensearch/cluster/metadata/MetadataDeleteIndexServiceTests.java index dbff833cfee60..f583bd84fa0a2 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/MetadataDeleteIndexServiceTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/MetadataDeleteIndexServiceTests.java @@ -40,7 +40,7 @@ import org.opensearch.cluster.routing.RoutingTable; import org.opensearch.cluster.routing.allocation.AllocationService; import org.opensearch.cluster.service.ClusterService; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.collect.Tuple; import org.opensearch.common.settings.Settings; import org.opensearch.index.Index; diff --git a/server/src/test/java/org/opensearch/cluster/metadata/MetadataIndexStateServiceTests.java b/server/src/test/java/org/opensearch/cluster/metadata/MetadataIndexStateServiceTests.java index 70ad47634d2da..c3fc2538c7ff0 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/MetadataIndexStateServiceTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/MetadataIndexStateServiceTests.java @@ -52,7 +52,7 @@ import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.Nullable; import org.opensearch.common.Strings; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.collect.Tuple; import org.opensearch.common.settings.Settings; import org.opensearch.index.Index; 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 8c2422c7dcf3b..689214cba83f1 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/MetadataTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/MetadataTests.java @@ -41,7 +41,7 @@ import org.opensearch.common.Strings; import org.opensearch.common.UUIDs; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.NamedWriteableAwareStreamInput; import org.opensearch.common.io.stream.NamedWriteableRegistry; 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 99c0d01a3dcca..0266be91fdf90 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 @@ -33,7 +33,6 @@ package org.opensearch.cluster.routing.allocation; import com.carrotsearch.hppc.cursors.ObjectCursor; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.lucene.util.ArrayUtil; @@ -69,6 +68,7 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -523,12 +523,12 @@ public void testPrimaryBalance_NotSolved_2() { private void verifyPerIndexPrimaryBalance(ClusterState currentState) { RoutingNodes nodes = currentState.getRoutingNodes(); - for (ObjectObjectCursor index : currentState.getRoutingTable().indicesRouting()) { - final int totalPrimaryShards = index.value.primaryShardsActive(); + for (Map.Entry index : currentState.getRoutingTable().indicesRouting().entrySet()) { + final int totalPrimaryShards = index.getValue().primaryShardsActive(); final int avgPrimaryShardsPerNode = (int) Math.ceil(totalPrimaryShards * 1f / currentState.getRoutingNodes().size()); for (RoutingNode node : nodes) { - final int primaryCount = node.shardsWithState(index.key, STARTED) + final int primaryCount = node.shardsWithState(index.getKey(), STARTED) .stream() .filter(ShardRouting::primary) .collect(Collectors.toList()) @@ -542,8 +542,8 @@ private void verifyPrimaryBalance(ClusterState clusterState) throws Exception { assertBusy(() -> { RoutingNodes nodes = clusterState.getRoutingNodes(); int totalPrimaryShards = 0; - for (ObjectObjectCursor index : clusterState.getRoutingTable().indicesRouting()) { - totalPrimaryShards += index.value.primaryShardsActive(); + for (Map.Entry index : clusterState.getRoutingTable().indicesRouting().entrySet()) { + totalPrimaryShards += index.getValue().primaryShardsActive(); } final int avgPrimaryShardsPerNode = (int) Math.ceil(totalPrimaryShards * 1f / clusterState.getRoutingNodes().size()); for (RoutingNode node : nodes) { diff --git a/server/src/test/java/org/opensearch/cluster/routing/allocation/NodeVersionAllocationDeciderTests.java b/server/src/test/java/org/opensearch/cluster/routing/allocation/NodeVersionAllocationDeciderTests.java index 38e24af421475..e622ff92094aa 100644 --- a/server/src/test/java/org/opensearch/cluster/routing/allocation/NodeVersionAllocationDeciderTests.java +++ b/server/src/test/java/org/opensearch/cluster/routing/allocation/NodeVersionAllocationDeciderTests.java @@ -63,7 +63,7 @@ import org.opensearch.cluster.routing.allocation.decider.ReplicaAfterPrimaryActiveAllocationDecider; import org.opensearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider; import org.opensearch.common.UUIDs; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.set.Sets; import org.opensearch.index.Index; 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 ab6042513af94..1d7bdc7557799 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 @@ -55,7 +55,7 @@ import org.opensearch.cluster.routing.allocation.decider.Decision; import org.opensearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider; import org.opensearch.common.UUIDs; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.settings.Settings; import org.opensearch.index.Index; import org.opensearch.index.shard.ShardId; diff --git a/server/src/test/java/org/opensearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java b/server/src/test/java/org/opensearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java index da50dd53b7d54..fdbc5833d8030 100644 --- a/server/src/test/java/org/opensearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java +++ b/server/src/test/java/org/opensearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java @@ -66,7 +66,7 @@ import org.opensearch.cluster.routing.allocation.command.AllocationCommands; import org.opensearch.cluster.routing.allocation.command.MoveAllocationCommand; import org.opensearch.common.UUIDs; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Settings; import org.opensearch.index.Index; diff --git a/server/src/test/java/org/opensearch/cluster/routing/allocation/decider/RestoreInProgressAllocationDeciderTests.java b/server/src/test/java/org/opensearch/cluster/routing/allocation/decider/RestoreInProgressAllocationDeciderTests.java index 4c0bdb2c900c7..b2d7d43237e00 100644 --- a/server/src/test/java/org/opensearch/cluster/routing/allocation/decider/RestoreInProgressAllocationDeciderTests.java +++ b/server/src/test/java/org/opensearch/cluster/routing/allocation/decider/RestoreInProgressAllocationDeciderTests.java @@ -52,7 +52,7 @@ import org.opensearch.cluster.routing.UnassignedInfo; import org.opensearch.cluster.routing.allocation.RoutingAllocation; import org.opensearch.common.UUIDs; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.index.shard.ShardId; import org.opensearch.repositories.IndexId; import org.opensearch.snapshots.Snapshot; diff --git a/server/src/test/java/org/opensearch/cluster/serialization/ClusterSerializationTests.java b/server/src/test/java/org/opensearch/cluster/serialization/ClusterSerializationTests.java index a760bd8e57d1f..d205be59ed8cf 100644 --- a/server/src/test/java/org/opensearch/cluster/serialization/ClusterSerializationTests.java +++ b/server/src/test/java/org/opensearch/cluster/serialization/ClusterSerializationTests.java @@ -50,7 +50,7 @@ import org.opensearch.cluster.routing.RoutingTable; import org.opensearch.cluster.routing.allocation.AllocationService; import org.opensearch.common.UUIDs; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.NamedWriteableAwareStreamInput; import org.opensearch.common.io.stream.NamedWriteableRegistry; diff --git a/server/src/test/java/org/opensearch/cluster/serialization/DiffableTests.java b/server/src/test/java/org/opensearch/cluster/serialization/DiffableTests.java index 9c1e3255bb3d8..55c6c680121fb 100644 --- a/server/src/test/java/org/opensearch/cluster/serialization/DiffableTests.java +++ b/server/src/test/java/org/opensearch/cluster/serialization/DiffableTests.java @@ -36,8 +36,8 @@ import org.opensearch.cluster.Diff; import org.opensearch.cluster.DiffableUtils; import org.opensearch.cluster.DiffableUtils.MapDiff; -import org.opensearch.common.collect.ImmutableOpenIntMap; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenIntMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; diff --git a/server/src/test/java/org/opensearch/common/io/stream/BytesStreamsTests.java b/server/src/test/java/org/opensearch/common/io/stream/BytesStreamsTests.java index 0ff3511f26f30..84dbeefc5e3b9 100644 --- a/server/src/test/java/org/opensearch/common/io/stream/BytesStreamsTests.java +++ b/server/src/test/java/org/opensearch/common/io/stream/BytesStreamsTests.java @@ -37,7 +37,7 @@ import org.apache.lucene.util.Constants; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.geo.GeoPoint; import org.opensearch.common.lucene.BytesRefs; import org.opensearch.common.unit.TimeValue; diff --git a/server/src/test/java/org/opensearch/gateway/PrimaryShardAllocatorTests.java b/server/src/test/java/org/opensearch/gateway/PrimaryShardAllocatorTests.java index 9bbef8a506b83..da22ee16a61b6 100644 --- a/server/src/test/java/org/opensearch/gateway/PrimaryShardAllocatorTests.java +++ b/server/src/test/java/org/opensearch/gateway/PrimaryShardAllocatorTests.java @@ -58,7 +58,7 @@ import org.opensearch.cluster.routing.allocation.decider.Decision; import org.opensearch.common.Nullable; import org.opensearch.common.UUIDs; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.set.Sets; import org.opensearch.env.ShardLockObtainFailedException; diff --git a/server/src/test/java/org/opensearch/indices/ShardLimitValidatorTests.java b/server/src/test/java/org/opensearch/indices/ShardLimitValidatorTests.java index ef3e85b0da775..bddb869cb6c8a 100644 --- a/server/src/test/java/org/opensearch/indices/ShardLimitValidatorTests.java +++ b/server/src/test/java/org/opensearch/indices/ShardLimitValidatorTests.java @@ -42,7 +42,7 @@ import org.opensearch.cluster.service.ClusterService; import org.opensearch.cluster.shards.ShardCounts; import org.opensearch.common.ValidationException; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Settings; import org.opensearch.index.Index; diff --git a/server/src/test/java/org/opensearch/rest/action/admin/indices/RestGetAliasesActionTests.java b/server/src/test/java/org/opensearch/rest/action/admin/indices/RestGetAliasesActionTests.java index c7974754d7bd0..92633615e0856 100644 --- a/server/src/test/java/org/opensearch/rest/action/admin/indices/RestGetAliasesActionTests.java +++ b/server/src/test/java/org/opensearch/rest/action/admin/indices/RestGetAliasesActionTests.java @@ -33,7 +33,7 @@ package org.opensearch.rest.action.admin.indices; import org.opensearch.cluster.metadata.AliasMetadata; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; diff --git a/server/src/test/java/org/opensearch/snapshots/InternalSnapshotsInfoServiceTests.java b/server/src/test/java/org/opensearch/snapshots/InternalSnapshotsInfoServiceTests.java index 483b5c268d3f9..3bf25da600ac5 100644 --- a/server/src/test/java/org/opensearch/snapshots/InternalSnapshotsInfoServiceTests.java +++ b/server/src/test/java/org/opensearch/snapshots/InternalSnapshotsInfoServiceTests.java @@ -54,7 +54,7 @@ import org.opensearch.cluster.service.ClusterApplier; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.UUIDs; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.settings.Settings; import org.opensearch.index.Index; import org.opensearch.index.shard.ShardId; diff --git a/server/src/test/java/org/opensearch/snapshots/SnapshotsInProgressSerializationTests.java b/server/src/test/java/org/opensearch/snapshots/SnapshotsInProgressSerializationTests.java index dc5d869c2f6a2..16daadc7ae878 100644 --- a/server/src/test/java/org/opensearch/snapshots/SnapshotsInProgressSerializationTests.java +++ b/server/src/test/java/org/opensearch/snapshots/SnapshotsInProgressSerializationTests.java @@ -39,7 +39,7 @@ import org.opensearch.cluster.SnapshotsInProgress.Entry; import org.opensearch.cluster.SnapshotsInProgress.ShardState; import org.opensearch.cluster.SnapshotsInProgress.State; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.io.stream.Writeable; import org.opensearch.index.Index; diff --git a/server/src/test/java/org/opensearch/snapshots/SnapshotsServiceTests.java b/server/src/test/java/org/opensearch/snapshots/SnapshotsServiceTests.java index 7f96d4842e37d..05eb959bc0bc1 100644 --- a/server/src/test/java/org/opensearch/snapshots/SnapshotsServiceTests.java +++ b/server/src/test/java/org/opensearch/snapshots/SnapshotsServiceTests.java @@ -44,7 +44,7 @@ import org.opensearch.cluster.routing.ShardRoutingState; import org.opensearch.cluster.routing.TestShardRouting; import org.opensearch.common.UUIDs; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.settings.Settings; import org.opensearch.index.Index; import org.opensearch.index.shard.ShardId; diff --git a/test/framework/src/main/java/org/opensearch/cluster/OpenSearchAllocationTestCase.java b/test/framework/src/main/java/org/opensearch/cluster/OpenSearchAllocationTestCase.java index ff0ad0c69e4e5..a130ed8baab59 100644 --- a/test/framework/src/main/java/org/opensearch/cluster/OpenSearchAllocationTestCase.java +++ b/test/framework/src/main/java/org/opensearch/cluster/OpenSearchAllocationTestCase.java @@ -48,7 +48,7 @@ import org.opensearch.cluster.routing.allocation.decider.AllocationDeciders; import org.opensearch.cluster.routing.allocation.decider.Decision; import org.opensearch.cluster.routing.allocation.decider.SameShardAllocationDecider; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Settings; import org.opensearch.gateway.GatewayAllocator; diff --git a/test/framework/src/main/java/org/opensearch/test/InternalTestCluster.java b/test/framework/src/main/java/org/opensearch/test/InternalTestCluster.java index 121003f66fc94..0cbd9c914074a 100644 --- a/test/framework/src/main/java/org/opensearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/opensearch/test/InternalTestCluster.java @@ -32,8 +32,6 @@ package org.opensearch.test; import com.carrotsearch.hppc.ObjectLongMap; -import com.carrotsearch.hppc.cursors.IntObjectCursor; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import com.carrotsearch.randomizedtesting.RandomizedTest; import com.carrotsearch.randomizedtesting.SeedUtils; import com.carrotsearch.randomizedtesting.generators.RandomNumbers; @@ -1492,9 +1490,9 @@ private IndexShard getShardOrNull(ClusterState clusterState, ShardRouting shardR public void assertSeqNos() throws Exception { assertBusy(() -> { final ClusterState state = clusterService().state(); - for (ObjectObjectCursor indexRoutingTable : state.routingTable().indicesRouting()) { - for (IntObjectCursor indexShardRoutingTable : indexRoutingTable.value.shards()) { - ShardRouting primaryShardRouting = indexShardRoutingTable.value.primaryShard(); + for (Map.Entry indexRoutingTable : state.routingTable().indicesRouting().entrySet()) { + for (Map.Entry indexShardRoutingTable : indexRoutingTable.getValue().shards().entrySet()) { + ShardRouting primaryShardRouting = indexShardRoutingTable.getValue().primaryShard(); final IndexShard primaryShard = getShardOrNull(state, primaryShardRouting); if (primaryShard == null) { continue; // just ignore - shard movement @@ -1512,7 +1510,7 @@ public void assertSeqNos() throws Exception { primarySeqNoStats.getGlobalCheckpoint(), not(equalTo(SequenceNumbers.UNASSIGNED_SEQ_NO)) ); - for (ShardRouting replicaShardRouting : indexShardRoutingTable.value.replicaShards()) { + for (ShardRouting replicaShardRouting : indexShardRoutingTable.getValue().replicaShards()) { final IndexShard replicaShard = getShardOrNull(state, replicaShardRouting); if (replicaShard == null) { continue; // just ignore - shard movement @@ -1542,9 +1540,9 @@ public void assertSeqNos() throws Exception { public void assertSameDocIdsOnShards() throws Exception { assertBusy(() -> { ClusterState state = client().admin().cluster().prepareState().get().getState(); - for (ObjectObjectCursor indexRoutingTable : state.routingTable().indicesRouting()) { - for (IntObjectCursor indexShardRoutingTable : indexRoutingTable.value.shards()) { - ShardRouting primaryShardRouting = indexShardRoutingTable.value.primaryShard(); + for (Map.Entry indexRoutingTable : state.routingTable().indicesRouting().entrySet()) { + for (Map.Entry indexShardRoutingTable : indexRoutingTable.getValue().shards().entrySet()) { + ShardRouting primaryShardRouting = indexShardRoutingTable.getValue().primaryShard(); IndexShard primaryShard = getShardOrNull(state, primaryShardRouting); if (primaryShard == null) { continue; @@ -1555,7 +1553,7 @@ public void assertSameDocIdsOnShards() throws Exception { } catch (AlreadyClosedException ex) { continue; } - for (ShardRouting replicaShardRouting : indexShardRoutingTable.value.replicaShards()) { + for (ShardRouting replicaShardRouting : indexShardRoutingTable.getValue().replicaShards()) { IndexShard replicaShard = getShardOrNull(state, replicaShardRouting); if (replicaShard == null) { continue; diff --git a/test/framework/src/main/java/org/opensearch/test/hamcrest/CollectionAssertions.java b/test/framework/src/main/java/org/opensearch/test/hamcrest/CollectionAssertions.java index ca000ef5b460c..86469bc7cdacf 100644 --- a/test/framework/src/main/java/org/opensearch/test/hamcrest/CollectionAssertions.java +++ b/test/framework/src/main/java/org/opensearch/test/hamcrest/CollectionAssertions.java @@ -31,7 +31,7 @@ package org.opensearch.test.hamcrest; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.hamcrest.Matcher; /** diff --git a/test/framework/src/main/java/org/opensearch/test/hamcrest/CollectionMatchers.java b/test/framework/src/main/java/org/opensearch/test/hamcrest/CollectionMatchers.java index 733cd4a21acca..9072bd39cff71 100644 --- a/test/framework/src/main/java/org/opensearch/test/hamcrest/CollectionMatchers.java +++ b/test/framework/src/main/java/org/opensearch/test/hamcrest/CollectionMatchers.java @@ -31,7 +31,7 @@ package org.opensearch.test.hamcrest; -import org.opensearch.common.collect.ImmutableOpenMap; +import org.opensearch.core.common.collect.ImmutableOpenMap; import org.hamcrest.Description; import org.hamcrest.TypeSafeMatcher; From 6bb3a3ef2f02db351ea285db23dee595c0347f89 Mon Sep 17 00:00:00 2001 From: Nicholas Walter Knize Date: Thu, 6 Apr 2023 09:52:32 -0500 Subject: [PATCH 2/3] fix DiscoveryNodes ImmutableOpenMap failure Signed-off-by: Nicholas Walter Knize --- .../java/org/opensearch/cluster/node/DiscoveryNodes.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/opensearch/cluster/node/DiscoveryNodes.java b/server/src/main/java/org/opensearch/cluster/node/DiscoveryNodes.java index f7491d507f622..503131f82bef3 100644 --- a/server/src/main/java/org/opensearch/cluster/node/DiscoveryNodes.java +++ b/server/src/main/java/org/opensearch/cluster/node/DiscoveryNodes.java @@ -843,7 +843,8 @@ public DiscoveryNodes build() { Version maxNodeVersion = null; Version minNonClientNodeVersion = null; Version maxNonClientNodeVersion = null; - for (Map.Entry nodeEntry : nodes.build().entrySet()) { + ImmutableOpenMap nodeMap = this.nodes.build(); + for (Map.Entry nodeEntry : nodeMap.entrySet()) { if (nodeEntry.getValue().isDataNode()) { dataNodesBuilder.put(nodeEntry.getKey(), nodeEntry.getValue()); } @@ -868,7 +869,7 @@ public DiscoveryNodes build() { } return new DiscoveryNodes( - nodes.build(), + nodeMap, dataNodesBuilder.build(), clusterManagerNodesBuilder.build(), ingestNodesBuilder.build(), From 2b0f30c49a54dbac064650637c9cf8f79b2450ab Mon Sep 17 00:00:00 2001 From: Nicholas Walter Knize Date: Thu, 6 Apr 2023 12:58:06 -0500 Subject: [PATCH 3/3] fix fieldMapper - reverted to hppc cursor until class refactor Signed-off-by: Nicholas Walter Knize --- .../main/java/org/opensearch/index/mapper/FieldMapper.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/opensearch/index/mapper/FieldMapper.java b/server/src/main/java/org/opensearch/index/mapper/FieldMapper.java index f187ab5f1cdbc..e3055d371f90a 100644 --- a/server/src/main/java/org/opensearch/index/mapper/FieldMapper.java +++ b/server/src/main/java/org/opensearch/index/mapper/FieldMapper.java @@ -34,6 +34,7 @@ import com.carrotsearch.hppc.cursors.ObjectCursor; +import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; import org.apache.lucene.index.IndexOptions; @@ -624,9 +625,9 @@ public MultiFields build(Mapper.Builder mainFieldBuilder, BuilderContext context } else { context.path().add(mainFieldBuilder.name()); ImmutableOpenMap.Builder mapperBuilders = this.mapperBuilders; - for (Map.Entry cursor : this.mapperBuilders.build().entrySet()) { - String key = cursor.getKey(); - Mapper.Builder value = cursor.getValue(); + for (ObjectObjectCursor cursor : this.mapperBuilders) { + String key = cursor.key; + Mapper.Builder value = cursor.value; Mapper mapper = value.build(context); assert mapper instanceof FieldMapper; mapperBuilders.put(key, mapper);