From 5572c309721acf6befd57f9b2cc6f65e40113b88 Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Thu, 5 Aug 2021 14:35:34 +0200 Subject: [PATCH] Remove Redundant ConcurrentHashMapLong This class is nothing but a noop wrapper around a normal CHM. It does nothing, adds indirection and hides the fact that it's just a standard CHM and has all the same boxing/unboxing under the hood. --- .../concurrent/ConcurrentCollections.java | 11 -- .../concurrent/ConcurrentHashMapLong.java | 135 ------------------ .../elasticsearch/search/SearchService.java | 3 +- .../org/elasticsearch/tasks/TaskManager.java | 6 +- .../elasticsearch/transport/Transport.java | 5 +- .../xpack/ml/integration/DatafeedJobsIT.java | 3 +- .../xpack/ml/integration/MlJobIT.java | 4 +- 7 files changed, 8 insertions(+), 159 deletions(-) delete mode 100644 server/src/main/java/org/elasticsearch/common/util/concurrent/ConcurrentHashMapLong.java diff --git a/server/src/main/java/org/elasticsearch/common/util/concurrent/ConcurrentCollections.java b/server/src/main/java/org/elasticsearch/common/util/concurrent/ConcurrentCollections.java index c33fbc864f13b..ab6de57cc2b9e 100644 --- a/server/src/main/java/org/elasticsearch/common/util/concurrent/ConcurrentCollections.java +++ b/server/src/main/java/org/elasticsearch/common/util/concurrent/ConcurrentCollections.java @@ -46,17 +46,6 @@ public static ConcurrentMap newConcurrentMap() { return new ConcurrentHashMap<>(); } - /** - * Creates a new CHM with an aggressive concurrency level, aimed at highly updateable long living maps. - */ - public static ConcurrentMapLong newConcurrentMapLongWithAggressiveConcurrency() { - return new ConcurrentHashMapLong<>(ConcurrentCollections.newConcurrentMapWithAggressiveConcurrency()); - } - - public static ConcurrentMapLong newConcurrentMapLong() { - return new ConcurrentHashMapLong<>(ConcurrentCollections.newConcurrentMap()); - } - public static Set newConcurrentSet() { return Collections.newSetFromMap(ConcurrentCollections.newConcurrentMap()); } diff --git a/server/src/main/java/org/elasticsearch/common/util/concurrent/ConcurrentHashMapLong.java b/server/src/main/java/org/elasticsearch/common/util/concurrent/ConcurrentHashMapLong.java deleted file mode 100644 index 6112b214a4952..0000000000000 --- a/server/src/main/java/org/elasticsearch/common/util/concurrent/ConcurrentHashMapLong.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.common.util.concurrent; - -import java.util.Collection; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentMap; - -public class ConcurrentHashMapLong implements ConcurrentMapLong { - - private final ConcurrentMap map; - - public ConcurrentHashMapLong(ConcurrentMap map) { - this.map = map; - } - - @Override - public T get(long key) { - return map.get(key); - } - - @Override - public T remove(long key) { - return map.remove(key); - } - - @Override - public T put(long key, T value) { - return map.put(key, value); - } - - // MAP DELEGATION - - @Override - public boolean isEmpty() { - return map.isEmpty(); - } - - @Override - public int size() { - return map.size(); - } - - @Override - public T get(Object key) { - return map.get(key); - } - - @Override - public boolean containsKey(Object key) { - return map.containsKey(key); - } - - @Override - public boolean containsValue(Object value) { - return map.containsValue(value); - } - - @Override - public T put(Long key, T value) { - return map.put(key, value); - } - - @Override - public T putIfAbsent(Long key, T value) { - return map.putIfAbsent(key, value); - } - - @Override - public void putAll(Map m) { - map.putAll(m); - } - - @Override - public T remove(Object key) { - return map.remove(key); - } - - @Override - public boolean remove(Object key, Object value) { - return map.remove(key, value); - } - - @Override - public boolean replace(Long key, T oldValue, T newValue) { - return map.replace(key, oldValue, newValue); - } - - @Override - public T replace(Long key, T value) { - return map.replace(key, value); - } - - @Override - public void clear() { - map.clear(); - } - - @Override - public Set keySet() { - return map.keySet(); - } - - @Override - public Collection values() { - return map.values(); - } - - @Override - public Set> entrySet() { - return map.entrySet(); - } - - @Override - public boolean equals(Object o) { - return map.equals(o); - } - - @Override - public int hashCode() { - return map.hashCode(); - } - - @Override - public String toString() { - return map.toString(); - } -} diff --git a/server/src/main/java/org/elasticsearch/search/SearchService.java b/server/src/main/java/org/elasticsearch/search/SearchService.java index ad6a286b2ee69..6b3c456ef18bc 100644 --- a/server/src/main/java/org/elasticsearch/search/SearchService.java +++ b/server/src/main/java/org/elasticsearch/search/SearchService.java @@ -44,7 +44,6 @@ import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.CollectionUtils; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; -import org.elasticsearch.common.util.concurrent.ConcurrentMapLong; import org.elasticsearch.core.internal.io.IOUtils; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexNotFoundException; @@ -222,7 +221,7 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv private final AtomicLong idGenerator = new AtomicLong(); - private final ConcurrentMapLong activeReaders = ConcurrentCollections.newConcurrentMapLongWithAggressiveConcurrency(); + private final Map activeReaders = ConcurrentCollections.newConcurrentMapWithAggressiveConcurrency(); private final MultiBucketConsumerService multiBucketConsumerService; diff --git a/server/src/main/java/org/elasticsearch/tasks/TaskManager.java b/server/src/main/java/org/elasticsearch/tasks/TaskManager.java index 9ea607efb9651..03998073805b0 100644 --- a/server/src/main/java/org/elasticsearch/tasks/TaskManager.java +++ b/server/src/main/java/org/elasticsearch/tasks/TaskManager.java @@ -33,7 +33,6 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.common.util.concurrent.AbstractRunnable; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; -import org.elasticsearch.common.util.concurrent.ConcurrentMapLong; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TaskTransportChannel; @@ -78,10 +77,9 @@ public class TaskManager implements ClusterStateApplier { private final List taskHeaders; private final ThreadPool threadPool; - private final ConcurrentMapLong tasks = ConcurrentCollections.newConcurrentMapLongWithAggressiveConcurrency(); + private final Map tasks = ConcurrentCollections.newConcurrentMapWithAggressiveConcurrency(); - private final ConcurrentMapLong cancellableTasks = ConcurrentCollections - .newConcurrentMapLongWithAggressiveConcurrency(); + private final Map cancellableTasks = ConcurrentCollections.newConcurrentMapWithAggressiveConcurrency(); private final AtomicLong taskIdGenerator = new AtomicLong(); diff --git a/server/src/main/java/org/elasticsearch/transport/Transport.java b/server/src/main/java/org/elasticsearch/transport/Transport.java index 76912f6e322f6..082711a488299 100644 --- a/server/src/main/java/org/elasticsearch/transport/Transport.java +++ b/server/src/main/java/org/elasticsearch/transport/Transport.java @@ -17,7 +17,6 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.common.util.Maps; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; -import org.elasticsearch.common.util.concurrent.ConcurrentMapLong; import java.io.Closeable; import java.io.IOException; @@ -165,8 +164,8 @@ public String action() { * This class is a registry that allows */ final class ResponseHandlers { - private final ConcurrentMapLong> handlers = ConcurrentCollections - .newConcurrentMapLongWithAggressiveConcurrency(); + private final Map> handlers = ConcurrentCollections + .newConcurrentMapWithAggressiveConcurrency(); private final AtomicLong requestIdGenerator = new AtomicLong(); /** diff --git a/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/DatafeedJobsIT.java b/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/DatafeedJobsIT.java index ed41905088df0..ccdd409eeab03 100644 --- a/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/DatafeedJobsIT.java +++ b/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/DatafeedJobsIT.java @@ -18,7 +18,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.core.TimeValue; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; -import org.elasticsearch.common.util.concurrent.ConcurrentMapLong; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.aggregations.AggregationBuilders; @@ -574,7 +573,7 @@ public void testRealtime_multipleStopCalls() throws Exception { final String datafeedId = jobId + "-datafeed"; startRealtime(jobId); - ConcurrentMapLong exceptions = ConcurrentCollections.newConcurrentMapLong(); + Map exceptions = ConcurrentCollections.newConcurrentMap(); // It's practically impossible to assert that a stop request has waited // for a concurrently executing request to finish before returning. diff --git a/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/MlJobIT.java b/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/MlJobIT.java index b29df801a73ea..bca7879f0c6ae 100644 --- a/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/MlJobIT.java +++ b/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/MlJobIT.java @@ -724,8 +724,8 @@ public void testDelete_multipleRequest() throws Exception { String jobId = "delete-job-multiple-times"; createFarequoteJob(jobId); - ConcurrentMapLong responses = ConcurrentCollections.newConcurrentMapLong(); - ConcurrentMapLong responseExceptions = ConcurrentCollections.newConcurrentMapLong(); + Map responses = ConcurrentCollections.newConcurrentMap(); + Map responseExceptions = ConcurrentCollections.newConcurrentMap(); AtomicReference ioe = new AtomicReference<>(); AtomicInteger recreationGuard = new AtomicInteger(0); AtomicReference recreationResponse = new AtomicReference<>();