From 5f8d46d82610010c49c219fcce51950e8601a701 Mon Sep 17 00:00:00 2001 From: Wellington Chevreuil Date: Wed, 23 Jan 2019 14:19:36 -0600 Subject: [PATCH] HBASE-20215 - Rename CollectionUtils to ConcurrentMapUtils Change-Id: I6e16493b8e98e2a2e814f3291945326b9d392997 Change-Id: I260e00f06b08bc660b7d938a6caaf0cf718892c6 --- .../client/AsyncBatchRpcRetryingCaller.java | 2 +- .../hbase/client/AsyncConnectionImpl.java | 6 +- .../client/AsyncNonMetaRegionLocator.java | 2 +- .../client/ConnectionImplementation.java | 4 +- .../apache/hadoop/hbase/client/MetaCache.java | 2 +- .../hbase/client/MetricsConnection.java | 2 +- .../client/PreemptiveFastFailInterceptor.java | 2 +- .../hbase/client/ServerStatisticTracker.java | 2 +- .../hbase/client/SimpleRequestController.java | 2 +- .../hadoop/hbase/client/TestAsyncProcess.java | 2 +- .../hadoop/hbase/util/CollectionUtils.java | 55 +------------ .../hadoop/hbase/util/ConcurrentMapUtils.java | 79 +++++++++++++++++++ .../ZKSplitLogManagerCoordination.java | 2 +- .../hadoop/hbase/master/ServerManager.java | 2 +- .../hadoop/hbase/quotas/QuotaCache.java | 2 +- .../hadoop/hbase/regionserver/HRegion.java | 2 +- .../wal/SequenceIdAccounting.java | 2 +- .../hbase/wal/BoundedGroupingStrategy.java | 2 +- 18 files changed, 102 insertions(+), 70 deletions(-) create mode 100644 hbase-common/src/main/java/org/apache/hadoop/hbase/util/ConcurrentMapUtils.java diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncBatchRpcRetryingCaller.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncBatchRpcRetryingCaller.java index 55590bd420..33e636647a 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncBatchRpcRetryingCaller.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncBatchRpcRetryingCaller.java @@ -22,7 +22,7 @@ import static org.apache.hadoop.hbase.client.ConnectionUtils.SLEEP_DELTA_NS; import static org.apache.hadoop.hbase.client.ConnectionUtils.getPauseTime; import static org.apache.hadoop.hbase.client.ConnectionUtils.resetController; import static org.apache.hadoop.hbase.client.ConnectionUtils.translateException; -import static org.apache.hadoop.hbase.util.CollectionUtils.computeIfAbsent; +import static org.apache.hadoop.hbase.util.ConcurrentMapUtils.computeIfAbsent; import static org.apache.hadoop.hbase.util.FutureUtils.addListener; import java.io.IOException; diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncConnectionImpl.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncConnectionImpl.java index 3cbd950370..d86be50068 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncConnectionImpl.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncConnectionImpl.java @@ -41,7 +41,7 @@ import org.apache.hadoop.hbase.ipc.RpcClient; import org.apache.hadoop.hbase.ipc.RpcClientFactory; import org.apache.hadoop.hbase.ipc.RpcControllerFactory; import org.apache.hadoop.hbase.security.User; -import org.apache.hadoop.hbase.util.CollectionUtils; +import org.apache.hadoop.hbase.util.ConcurrentMapUtils; import org.apache.hadoop.hbase.util.Threads; import org.apache.hadoop.security.UserGroupInformation; import org.apache.yetus.audience.InterfaceAudience; @@ -168,7 +168,7 @@ class AsyncConnectionImpl implements AsyncConnection { } ClientService.Interface getRegionServerStub(ServerName serverName) throws IOException { - return CollectionUtils.computeIfAbsentEx(rsStubs, + return ConcurrentMapUtils.computeIfAbsentEx(rsStubs, getStubKey(ClientService.Interface.class.getSimpleName(), serverName, hostnameCanChange), () -> createRegionServerStub(serverName)); } @@ -182,7 +182,7 @@ class AsyncConnectionImpl implements AsyncConnection { } AdminService.Interface getAdminStub(ServerName serverName) throws IOException { - return CollectionUtils.computeIfAbsentEx(adminSubs, + return ConcurrentMapUtils.computeIfAbsentEx(adminSubs, getStubKey(AdminService.Interface.class.getSimpleName(), serverName, hostnameCanChange), () -> createAdminServerStub(serverName)); } diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java index 1fcfbb024d..1a1f32adb5 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java @@ -29,7 +29,7 @@ import static org.apache.hadoop.hbase.client.ConnectionUtils.createClosestRowAft import static org.apache.hadoop.hbase.client.ConnectionUtils.isEmptyStopRow; import static org.apache.hadoop.hbase.client.RegionInfo.createRegionName; import static org.apache.hadoop.hbase.util.Bytes.BYTES_COMPARATOR; -import static org.apache.hadoop.hbase.util.CollectionUtils.computeIfAbsent; +import static org.apache.hadoop.hbase.util.ConcurrentMapUtils.computeIfAbsent; import java.io.IOException; import java.util.Arrays; diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java index 4e3543f4d6..e86052213a 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java @@ -22,8 +22,8 @@ import static org.apache.hadoop.hbase.client.ConnectionUtils.NO_NONCE_GENERATOR; import static org.apache.hadoop.hbase.client.ConnectionUtils.getStubKey; import static org.apache.hadoop.hbase.client.ConnectionUtils.retries2Attempts; import static org.apache.hadoop.hbase.client.MetricsConnection.CLIENT_SIDE_METRICS_ENABLED_KEY; -import static org.apache.hadoop.hbase.util.CollectionUtils.computeIfAbsent; -import static org.apache.hadoop.hbase.util.CollectionUtils.computeIfAbsentEx; +import static org.apache.hadoop.hbase.util.ConcurrentMapUtils.computeIfAbsent; +import static org.apache.hadoop.hbase.util.ConcurrentMapUtils.computeIfAbsentEx; import edu.umd.cs.findbugs.annotations.Nullable; import java.io.Closeable; diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/MetaCache.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/MetaCache.java index a3677890d4..fde2838acc 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/MetaCache.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/MetaCache.java @@ -18,7 +18,7 @@ package org.apache.hadoop.hbase.client; -import static org.apache.hadoop.hbase.util.CollectionUtils.computeIfAbsent; +import static org.apache.hadoop.hbase.util.ConcurrentMapUtils.computeIfAbsent; import java.util.Map; import java.util.Map.Entry; diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/MetricsConnection.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/MetricsConnection.java index e61ba247ef..df2732d9bf 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/MetricsConnection.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/MetricsConnection.java @@ -18,7 +18,7 @@ package org.apache.hadoop.hbase.client; import static com.codahale.metrics.MetricRegistry.name; -import static org.apache.hadoop.hbase.util.CollectionUtils.computeIfAbsent; +import static org.apache.hadoop.hbase.util.ConcurrentMapUtils.computeIfAbsent; import com.codahale.metrics.Counter; import com.codahale.metrics.Histogram; diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/PreemptiveFastFailInterceptor.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/PreemptiveFastFailInterceptor.java index 7b6bba3d83..f6289d20bd 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/PreemptiveFastFailInterceptor.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/PreemptiveFastFailInterceptor.java @@ -17,7 +17,7 @@ */ package org.apache.hadoop.hbase.client; -import static org.apache.hadoop.hbase.util.CollectionUtils.computeIfAbsent; +import static org.apache.hadoop.hbase.util.ConcurrentMapUtils.computeIfAbsent; import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting; diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ServerStatisticTracker.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ServerStatisticTracker.java index 9fb655b92a..c5c7375cc3 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ServerStatisticTracker.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ServerStatisticTracker.java @@ -17,7 +17,7 @@ */ package org.apache.hadoop.hbase.client; -import static org.apache.hadoop.hbase.util.CollectionUtils.computeIfAbsent; +import static org.apache.hadoop.hbase.util.ConcurrentMapUtils.computeIfAbsent; import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting; diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/SimpleRequestController.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/SimpleRequestController.java index 2c9a367148..261d663e0f 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/SimpleRequestController.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/SimpleRequestController.java @@ -45,7 +45,7 @@ import org.apache.yetus.audience.InterfaceStability; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hadoop.hbase.util.Bytes; -import static org.apache.hadoop.hbase.util.CollectionUtils.computeIfAbsent; +import static org.apache.hadoop.hbase.util.ConcurrentMapUtils.computeIfAbsent; import org.apache.hadoop.hbase.util.EnvironmentEdge; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestAsyncProcess.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestAsyncProcess.java index 4a2ed8d747..025953f9e0 100644 --- a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestAsyncProcess.java +++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestAsyncProcess.java @@ -1762,7 +1762,7 @@ public class TestAsyncProcess { long expectedSleep = 0L; for (int i = 0; i < retries; i++) { expectedSleep += ConnectionUtils.getPauseTime(specialPause, i); - // Prevent jitter in CollectionUtils#getPauseTime to affect result + // Prevent jitter in ConcurrentMapUtils#getPauseTime to affect result actualSleep += (long) (specialPause * 0.01f); } LOG.debug("Expected to sleep " + expectedSleep + "ms, actually slept " + actualSleep + "ms"); diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/CollectionUtils.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/CollectionUtils.java index bfe41d8f38..6451f6d5db 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/CollectionUtils.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/CollectionUtils.java @@ -18,62 +18,15 @@ package org.apache.hadoop.hbase.util; -import java.io.IOException; -import java.util.concurrent.ConcurrentMap; -import java.util.function.Supplier; - import org.apache.yetus.audience.InterfaceAudience; /** * Utility methods for dealing with Collections, including treating null collections as empty. */ @InterfaceAudience.Private -public class CollectionUtils { - - /** - * In HBASE-16648 we found that ConcurrentHashMap.get is much faster than computeIfAbsent if the - * value already exists. Notice that the implementation does not guarantee that the supplier will - * only be executed once. - */ - public static V computeIfAbsent(ConcurrentMap map, K key, Supplier supplier) { - return computeIfAbsent(map, key, supplier, () -> { - }); - } - - /** - * A supplier that throws IOException when get. - */ - @FunctionalInterface - public interface IOExceptionSupplier { - V get() throws IOException; - } - - /** - * In HBASE-16648 we found that ConcurrentHashMap.get is much faster than computeIfAbsent if the - * value already exists. So here we copy the implementation of - * {@link ConcurrentMap#computeIfAbsent(Object, java.util.function.Function)}. It uses get and - * putIfAbsent to implement computeIfAbsent. And notice that the implementation does not guarantee - * that the supplier will only be executed once. - */ - public static V computeIfAbsentEx(ConcurrentMap map, K key, - IOExceptionSupplier supplier) throws IOException { - V v, newValue; - return ((v = map.get(key)) == null && (newValue = supplier.get()) != null - && (v = map.putIfAbsent(key, newValue)) == null) ? newValue : v; - } +//HBASE-20215: Marking as deprecated. Although audience is private, there might be references to +//this class on some client classpath. +@Deprecated +public class CollectionUtils extends ConcurrentMapUtils { - public static V computeIfAbsent(ConcurrentMap map, K key, Supplier supplier, - Runnable actionIfAbsent) { - V v = map.get(key); - if (v != null) { - return v; - } - V newValue = supplier.get(); - v = map.putIfAbsent(key, newValue); - if (v != null) { - return v; - } - actionIfAbsent.run(); - return newValue; - } } diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ConcurrentMapUtils.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ConcurrentMapUtils.java new file mode 100644 index 0000000000..eae599b0bd --- /dev/null +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ConcurrentMapUtils.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +package org.apache.hadoop.hbase.util; + +import java.io.IOException; +import java.util.concurrent.ConcurrentMap; +import java.util.function.Supplier; + +import org.apache.yetus.audience.InterfaceAudience; + +/** + * Utility methods for dealing with Collections, including treating null collections as empty. + */ +@InterfaceAudience.Private +public class ConcurrentMapUtils { + + /** + * In HBASE-16648 we found that ConcurrentHashMap.get is much faster than computeIfAbsent if the + * value already exists. Notice that the implementation does not guarantee that the supplier will + * only be executed once. + */ + public static V computeIfAbsent(ConcurrentMap map, K key, Supplier supplier) { + return computeIfAbsent(map, key, supplier, () -> { + }); + } + + /** + * A supplier that throws IOException when get. + */ + @FunctionalInterface + public interface IOExceptionSupplier { + V get() throws IOException; + } + + /** + * In HBASE-16648 we found that ConcurrentHashMap.get is much faster than computeIfAbsent if the + * value already exists. So here we copy the implementation of + * {@link ConcurrentMap#computeIfAbsent(Object, java.util.function.Function)}. It uses get and + * putIfAbsent to implement computeIfAbsent. And notice that the implementation does not guarantee + * that the supplier will only be executed once. + */ + public static V computeIfAbsentEx(ConcurrentMap map, K key, + IOExceptionSupplier supplier) throws IOException { + V v, newValue; + return ((v = map.get(key)) == null && (newValue = supplier.get()) != null + && (v = map.putIfAbsent(key, newValue)) == null) ? newValue : v; + } + + public static V computeIfAbsent(ConcurrentMap map, K key, Supplier supplier, + Runnable actionIfAbsent) { + V v = map.get(key); + if (v != null) { + return v; + } + V newValue = supplier.get(); + v = map.putIfAbsent(key, newValue); + if (v != null) { + return v; + } + actionIfAbsent.run(); + return newValue; + } +} diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/coordination/ZKSplitLogManagerCoordination.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/coordination/ZKSplitLogManagerCoordination.java index c1fbac986a..60c2b71888 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/coordination/ZKSplitLogManagerCoordination.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/coordination/ZKSplitLogManagerCoordination.java @@ -24,7 +24,7 @@ import static org.apache.hadoop.hbase.master.SplitLogManager.TerminationStatus.D import static org.apache.hadoop.hbase.master.SplitLogManager.TerminationStatus.FAILURE; import static org.apache.hadoop.hbase.master.SplitLogManager.TerminationStatus.IN_PROGRESS; import static org.apache.hadoop.hbase.master.SplitLogManager.TerminationStatus.SUCCESS; -import static org.apache.hadoop.hbase.util.CollectionUtils.computeIfAbsent; +import static org.apache.hadoop.hbase.util.ConcurrentMapUtils.computeIfAbsent; import java.io.IOException; import java.util.List; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java index 86d72d161b..0fb1551792 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java @@ -18,7 +18,7 @@ */ package org.apache.hadoop.hbase.master; -import static org.apache.hadoop.hbase.util.CollectionUtils.computeIfAbsent; +import static org.apache.hadoop.hbase.util.ConcurrentMapUtils.computeIfAbsent; import java.io.IOException; import java.net.InetAddress; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/QuotaCache.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/QuotaCache.java index 0664cc5119..fac998f092 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/QuotaCache.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/QuotaCache.java @@ -18,7 +18,7 @@ package org.apache.hadoop.hbase.quotas; -import static org.apache.hadoop.hbase.util.CollectionUtils.computeIfAbsent; +import static org.apache.hadoop.hbase.util.ConcurrentMapUtils.computeIfAbsent; import org.apache.hadoop.hbase.regionserver.HRegionServer; import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index b04f54815e..8b3bc89286 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -19,7 +19,7 @@ package org.apache.hadoop.hbase.regionserver; import static org.apache.hadoop.hbase.HConstants.REPLICATION_SCOPE_LOCAL; import static org.apache.hadoop.hbase.regionserver.HStoreFile.MAJOR_COMPACTION_KEY; -import static org.apache.hadoop.hbase.util.CollectionUtils.computeIfAbsent; +import static org.apache.hadoop.hbase.util.ConcurrentMapUtils.computeIfAbsent; import edu.umd.cs.findbugs.annotations.Nullable; import java.io.EOFException; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/SequenceIdAccounting.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/SequenceIdAccounting.java index 4e3ca176ce..9736d8bd1f 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/SequenceIdAccounting.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/SequenceIdAccounting.java @@ -17,7 +17,7 @@ */ package org.apache.hadoop.hbase.regionserver.wal; -import static org.apache.hadoop.hbase.util.CollectionUtils.computeIfAbsent; +import static org.apache.hadoop.hbase.util.ConcurrentMapUtils.computeIfAbsent; import java.util.ArrayList; import java.util.Collection; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/BoundedGroupingStrategy.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/BoundedGroupingStrategy.java index ea26ea7c12..bafcee339e 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/BoundedGroupingStrategy.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/BoundedGroupingStrategy.java @@ -18,7 +18,7 @@ */ package org.apache.hadoop.hbase.wal; -import static org.apache.hadoop.hbase.util.CollectionUtils.computeIfAbsent; +import static org.apache.hadoop.hbase.util.ConcurrentMapUtils.computeIfAbsent; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; -- 2.17.2 (Apple Git-113)