Skip to content

Commit 767fd68

Browse files
authored
Convert cluster state "customs" to Map (#87265)
The pluggable portions of in memory cluster state are held within an ImmutableOpenMap. This commit converts that to a Map. Note that the diff format is the same for immutableopenmap and jdk map, so no bwc logic is necessary. relates #86239
1 parent 64d716b commit 767fd68

File tree

5 files changed

+14
-16
lines changed

5 files changed

+14
-16
lines changed

server/src/internalClusterTest/java/org/elasticsearch/cluster/ClusterStateDiffIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ private interface RandomClusterPart<T> {
371371
/**
372372
* Returns list of parts from metadata
373373
*/
374-
ImmutableOpenMap<String, T> parts(ClusterState clusterState);
374+
Map<String, T> parts(ClusterState clusterState);
375375

376376
/**
377377
* Puts the part back into metadata
@@ -401,7 +401,7 @@ private interface RandomClusterPart<T> {
401401
*/
402402
private <T> ClusterState randomClusterStateParts(ClusterState clusterState, String prefix, RandomClusterPart<T> randomPart) {
403403
ClusterState.Builder builder = ClusterState.builder(clusterState);
404-
ImmutableOpenMap<String, T> parts = randomPart.parts(clusterState);
404+
Map<String, T> parts = randomPart.parts(clusterState);
405405
int partCount = parts.size();
406406
if (partCount > 0) {
407407
List<String> randomParts = randomSubsetOf(
@@ -688,7 +688,7 @@ private ClusterState.Builder randomClusterStateCustoms(final ClusterState cluste
688688
return ClusterState.builder(randomClusterStateParts(clusterState, "custom", new RandomClusterPart<ClusterState.Custom>() {
689689

690690
@Override
691-
public ImmutableOpenMap<String, ClusterState.Custom> parts(ClusterState clusterState) {
691+
public Map<String, ClusterState.Custom> parts(ClusterState clusterState) {
692692
return clusterState.customs();
693693
}
694694

server/src/main/java/org/elasticsearch/cluster/ClusterState.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ default boolean isPrivate() {
151151

152152
private final ClusterBlocks blocks;
153153

154-
private final ImmutableOpenMap<String, Custom> customs;
154+
private final Map<String, Custom> customs;
155155

156156
private final ClusterName clusterName;
157157

@@ -183,7 +183,7 @@ public ClusterState(
183183
RoutingTable routingTable,
184184
DiscoveryNodes nodes,
185185
ClusterBlocks blocks,
186-
ImmutableOpenMap<String, Custom> customs,
186+
Map<String, Custom> customs,
187187
boolean wasReadFromDiff,
188188
@Nullable RoutingNodes routingNodes
189189
) {
@@ -281,11 +281,11 @@ public ClusterBlocks getBlocks() {
281281
return blocks;
282282
}
283283

284-
public ImmutableOpenMap<String, Custom> customs() {
284+
public Map<String, Custom> customs() {
285285
return this.customs;
286286
}
287287

288-
public ImmutableOpenMap<String, Custom> getCustoms() {
288+
public Map<String, Custom> getCustoms() {
289289
return this.customs;
290290
}
291291

@@ -698,7 +698,7 @@ public Builder removeCustom(String type) {
698698
return this;
699699
}
700700

701-
public Builder customs(ImmutableOpenMap<String, Custom> customs) {
701+
public Builder customs(Map<String, Custom> customs) {
702702
customs.forEach((key, value) -> Objects.requireNonNull(value, key));
703703
this.customs.putAllFromMap(customs);
704704
return this;
@@ -814,7 +814,7 @@ private static class ClusterStateDiff implements Diff<ClusterState> {
814814

815815
private final Diff<ClusterBlocks> blocks;
816816

817-
private final Diff<ImmutableOpenMap<String, Custom>> customs;
817+
private final Diff<Map<String, Custom>> customs;
818818

819819
ClusterStateDiff(ClusterState before, ClusterState after) {
820820
fromUuid = before.stateUUID;
@@ -837,7 +837,7 @@ private static class ClusterStateDiff implements Diff<ClusterState> {
837837
nodes = DiscoveryNodes.readDiffFrom(in, localNode);
838838
metadata = Metadata.readDiffFrom(in);
839839
blocks = ClusterBlocks.readDiffFrom(in);
840-
customs = DiffableUtils.readImmutableOpenMapDiff(in, DiffableUtils.getStringKeySerializer(), CUSTOM_VALUE_SERIALIZER);
840+
customs = DiffableUtils.readJdkMapDiff(in, DiffableUtils.getStringKeySerializer(), CUSTOM_VALUE_SERIALIZER);
841841
if (in.getVersion().before(Version.V_8_0_0)) {
842842
in.readVInt(); // used to be minimumMasterNodesOnPublishingMaster, which was used in 7.x for BWC with 6.x
843843
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public ClusterState deleteIndices(ClusterState currentState, Set<Index> indices)
145145
ClusterBlocks blocks = clusterBlocksBuilder.build();
146146

147147
// update snapshot restore entries
148-
ImmutableOpenMap<String, ClusterState.Custom> customs = currentState.getCustoms();
148+
Map<String, ClusterState.Custom> customs = currentState.getCustoms();
149149
final RestoreInProgress restoreInProgress = currentState.custom(RestoreInProgress.TYPE, RestoreInProgress.EMPTY);
150150
RestoreInProgress updatedRestoreInProgress = RestoreService.updateRestoreStateWithDeletedIndices(restoreInProgress, indices);
151151
if (updatedRestoreInProgress != restoreInProgress) {

server/src/main/java/org/elasticsearch/cluster/routing/allocation/RoutingAllocation.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.elasticsearch.cluster.routing.ShardRouting;
2121
import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders;
2222
import org.elasticsearch.cluster.routing.allocation.decider.Decision;
23-
import org.elasticsearch.common.collect.ImmutableOpenMap;
2423
import org.elasticsearch.core.Nullable;
2524
import org.elasticsearch.index.shard.ShardId;
2625
import org.elasticsearch.snapshots.RestoreService.RestoreInProgressUpdater;
@@ -188,7 +187,7 @@ public <T extends ClusterState.Custom> T custom(String key) {
188187
return (T) clusterState.customs().get(key);
189188
}
190189

191-
public ImmutableOpenMap<String, ClusterState.Custom> getCustoms() {
190+
public Map<String, ClusterState.Custom> getCustoms() {
192191
return clusterState.getCustoms();
193192
}
194193

server/src/main/java/org/elasticsearch/common/io/stream/VersionedNamedWriteable.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
package org.elasticsearch.common.io.stream;
1010

1111
import org.elasticsearch.Version;
12-
import org.elasticsearch.common.collect.ImmutableOpenMap;
1312

1413
import java.io.IOException;
14+
import java.util.Map;
1515

1616
/**
1717
* A {@link NamedWriteable} that has a minimum version associated with it.
@@ -49,8 +49,7 @@ static <T extends VersionedNamedWriteable> boolean shouldSerialize(final StreamO
4949
* @param customs map of customs
5050
* @param <T> type of customs in map
5151
*/
52-
static <T extends VersionedNamedWriteable> void writeVersionedWritables(StreamOutput out, ImmutableOpenMap<String, T> customs)
53-
throws IOException {
52+
static <T extends VersionedNamedWriteable> void writeVersionedWritables(StreamOutput out, Map<String, T> customs) throws IOException {
5453
// filter out custom states not supported by the other node
5554
int numberOfCustoms = 0;
5655
for (final T value : customs.values()) {

0 commit comments

Comments
 (0)