HBASE-20215 - Rename CollectionUtils to ConcurrentMapUtils
This commit is contained in:
parent
91dffb043a
commit
54093b0d1f
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -18,62 +18,16 @@
|
|||
|
||||
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.
|
||||
* @deprecated Since 2.0.6/2.1.3/2.2.0
|
||||
*/
|
||||
@InterfaceAudience.Private
|
||||
public class CollectionUtils {
|
||||
//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 {
|
||||
|
||||
/**
|
||||
* 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 <K, V> V computeIfAbsent(ConcurrentMap<K, V> map, K key, Supplier<V> supplier) {
|
||||
return computeIfAbsent(map, key, supplier, () -> {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* A supplier that throws IOException when get.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface IOExceptionSupplier<V> {
|
||||
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 <K, V> V computeIfAbsentEx(ConcurrentMap<K, V> map, K key,
|
||||
IOExceptionSupplier<V> 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 <K, V> V computeIfAbsent(ConcurrentMap<K, V> map, K key, Supplier<V> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <K, V> V computeIfAbsent(ConcurrentMap<K, V> map, K key, Supplier<V> supplier) {
|
||||
return computeIfAbsent(map, key, supplier, () -> {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* A supplier that throws IOException when get.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface IOExceptionSupplier<V> {
|
||||
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 <K, V> V computeIfAbsentEx(ConcurrentMap<K, V> map, K key,
|
||||
IOExceptionSupplier<V> 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 <K, V> V computeIfAbsent(ConcurrentMap<K, V> map, K key, Supplier<V> 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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue