Skip to content

Commit

Permalink
Use consistent map type in IndicesService (#88369)
Browse files Browse the repository at this point in the history
Iteration and lookup from this map get quite hot at times for large data nodes.
We shouldn't have different map types here depending on whether or not the latest operation
was an index delete or create on the node.
Also, the wrapped HashMap is slower to iterate than the immutable collections map.
  • Loading branch information
original-brownbear authored Jul 8, 2022
1 parent 66e750c commit d7b6a32
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@
import java.util.stream.Collectors;

import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static java.util.Collections.unmodifiableMap;
import static org.elasticsearch.common.util.CollectionUtils.arrayAsArrayList;
import static org.elasticsearch.common.util.concurrent.EsExecutors.daemonThreadFactory;
import static org.elasticsearch.core.Strings.format;
Expand Down Expand Up @@ -218,7 +216,7 @@ public class IndicesService extends AbstractLifecycleComponent
private final ScriptService scriptService;
private final ClusterService clusterService;
private final Client client;
private volatile Map<String, IndexService> indices = emptyMap();
private volatile Map<String, IndexService> indices = Map.of();
private final Map<Index, List<PendingDelete>> pendingDeletes = new HashMap<>();
private final AtomicInteger numUncompletedDeletes = new AtomicInteger();
private final OldShardsStats oldShardsStats = new OldShardsStats();
Expand Down Expand Up @@ -860,10 +858,9 @@ public void removeIndex(final Index index, final IndexRemovalReason reason, fina
}

logger.debug("[{}] closing ... (reason [{}])", indexName, reason);
Map<String, IndexService> newIndices = new HashMap<>(indices);
indexService = newIndices.remove(index.getUUID());
indexService = indices.get(index.getUUID());
assert indexService != null : "IndexService is null for index: " + index;
indices = unmodifiableMap(newIndices);
indices = Maps.copyMapWithRemovedEntry(indices, index.getUUID());
listener = indexService.getIndexEventListener();
}

Expand Down

0 comments on commit d7b6a32

Please sign in to comment.