HBASE-23648: Re-use underlying connection registry in RawAsyncHBaseAdmin (#994)
* HBASE-23648: Re-use underlying connection registry in RawAsyncHBaseAdmin No need to create and close a new registry on demand. Audited other usages of getRegistry() and the code looks fine. * Fix checkstyle issues in RawAsyncHBaseAdmin
This commit is contained in:
parent
0a1c3b2055
commit
7162c02c0d
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* or more contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -21,7 +21,6 @@ import static org.apache.hadoop.hbase.HConstants.HIGH_QOS;
|
||||||
import static org.apache.hadoop.hbase.TableName.META_TABLE_NAME;
|
import static org.apache.hadoop.hbase.TableName.META_TABLE_NAME;
|
||||||
import static org.apache.hadoop.hbase.util.FutureUtils.addListener;
|
import static org.apache.hadoop.hbase.util.FutureUtils.addListener;
|
||||||
import static org.apache.hadoop.hbase.util.FutureUtils.unwrapCompletionException;
|
import static org.apache.hadoop.hbase.util.FutureUtils.unwrapCompletionException;
|
||||||
|
|
||||||
import com.google.protobuf.Message;
|
import com.google.protobuf.Message;
|
||||||
import com.google.protobuf.RpcChannel;
|
import com.google.protobuf.RpcChannel;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -46,7 +45,6 @@ import java.util.function.Supplier;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.hbase.AsyncMetaTableAccessor;
|
import org.apache.hadoop.hbase.AsyncMetaTableAccessor;
|
||||||
import org.apache.hadoop.hbase.CacheEvictionStats;
|
import org.apache.hadoop.hbase.CacheEvictionStats;
|
||||||
|
@ -99,14 +97,12 @@ import org.apache.hadoop.hbase.util.ForeignExceptionUtil;
|
||||||
import org.apache.yetus.audience.InterfaceAudience;
|
import org.apache.yetus.audience.InterfaceAudience;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting;
|
import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting;
|
||||||
import org.apache.hbase.thirdparty.com.google.common.base.Preconditions;
|
import org.apache.hbase.thirdparty.com.google.common.base.Preconditions;
|
||||||
import org.apache.hbase.thirdparty.com.google.protobuf.RpcCallback;
|
import org.apache.hbase.thirdparty.com.google.protobuf.RpcCallback;
|
||||||
import org.apache.hbase.thirdparty.io.netty.util.HashedWheelTimer;
|
import org.apache.hbase.thirdparty.io.netty.util.HashedWheelTimer;
|
||||||
import org.apache.hbase.thirdparty.io.netty.util.Timeout;
|
import org.apache.hbase.thirdparty.io.netty.util.Timeout;
|
||||||
import org.apache.hbase.thirdparty.io.netty.util.TimerTask;
|
import org.apache.hbase.thirdparty.io.netty.util.TimerTask;
|
||||||
|
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
|
import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.RequestConverter;
|
import org.apache.hadoop.hbase.shaded.protobuf.RequestConverter;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.AccessControlProtos;
|
import org.apache.hadoop.hbase.shaded.protobuf.generated.AccessControlProtos;
|
||||||
|
@ -755,7 +751,8 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> addColumnFamily(TableName tableName, ColumnFamilyDescriptor columnFamily) {
|
public CompletableFuture<Void> addColumnFamily(
|
||||||
|
TableName tableName, ColumnFamilyDescriptor columnFamily) {
|
||||||
return this.<AddColumnRequest, AddColumnResponse> procedureCall(tableName,
|
return this.<AddColumnRequest, AddColumnResponse> procedureCall(tableName,
|
||||||
RequestConverter.buildAddColumnRequest(tableName, columnFamily, ng.getNonceGroup(),
|
RequestConverter.buildAddColumnRequest(tableName, columnFamily, ng.getNonceGroup(),
|
||||||
ng.newNonce()), (s, c, req, done) -> s.addColumn(c, req, done), (resp) -> resp.getProcId(),
|
ng.newNonce()), (s, c, req, done) -> s.addColumn(c, req, done), (resp) -> resp.getProcId(),
|
||||||
|
@ -809,10 +806,10 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||||
.<NamespaceDescriptor> newMasterCaller()
|
.<NamespaceDescriptor> newMasterCaller()
|
||||||
.action(
|
.action(
|
||||||
(controller, stub) -> this
|
(controller, stub) -> this
|
||||||
.<GetNamespaceDescriptorRequest, GetNamespaceDescriptorResponse, NamespaceDescriptor> call(
|
.<GetNamespaceDescriptorRequest, GetNamespaceDescriptorResponse, NamespaceDescriptor>
|
||||||
controller, stub, RequestConverter.buildGetNamespaceDescriptorRequest(name), (s, c,
|
call(controller, stub, RequestConverter.buildGetNamespaceDescriptorRequest(name),
|
||||||
req, done) -> s.getNamespaceDescriptor(c, req, done), (resp) -> ProtobufUtil
|
(s, c, req, done) -> s.getNamespaceDescriptor(c, req, done), (resp)
|
||||||
.toNamespaceDescriptor(resp.getNamespaceDescriptor()))).call();
|
-> ProtobufUtil.toNamespaceDescriptor(resp.getNamespaceDescriptor()))).call();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -830,13 +827,12 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<List<NamespaceDescriptor>> listNamespaceDescriptors() {
|
public CompletableFuture<List<NamespaceDescriptor>> listNamespaceDescriptors() {
|
||||||
return this
|
return this
|
||||||
.<List<NamespaceDescriptor>> newMasterCaller()
|
.<List<NamespaceDescriptor>> newMasterCaller().action((controller, stub) -> this
|
||||||
.action(
|
.<ListNamespaceDescriptorsRequest, ListNamespaceDescriptorsResponse,
|
||||||
(controller, stub) -> this
|
List<NamespaceDescriptor>> call(controller, stub,
|
||||||
.<ListNamespaceDescriptorsRequest, ListNamespaceDescriptorsResponse, List<NamespaceDescriptor>> call(
|
ListNamespaceDescriptorsRequest.newBuilder().build(), (s, c, req, done) ->
|
||||||
controller, stub, ListNamespaceDescriptorsRequest.newBuilder().build(), (s, c, req,
|
s.listNamespaceDescriptors(c, req, done),
|
||||||
done) -> s.listNamespaceDescriptors(c, req, done), (resp) -> ProtobufUtil
|
(resp) -> ProtobufUtil.toNamespaceDescriptorList(resp))).call();
|
||||||
.toNamespaceDescriptorList(resp))).call();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1080,10 +1076,7 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||||
private CompletableFuture<List<HRegionLocation>> getTableHRegionLocations(TableName tableName) {
|
private CompletableFuture<List<HRegionLocation>> getTableHRegionLocations(TableName tableName) {
|
||||||
if (TableName.META_TABLE_NAME.equals(tableName)) {
|
if (TableName.META_TABLE_NAME.equals(tableName)) {
|
||||||
CompletableFuture<List<HRegionLocation>> future = new CompletableFuture<>();
|
CompletableFuture<List<HRegionLocation>> future = new CompletableFuture<>();
|
||||||
// For meta table, we use zk to fetch all locations.
|
addListener(connection.registry.getMetaRegionLocations(), (metaRegions, err) -> {
|
||||||
ConnectionRegistry registry = ConnectionRegistryFactory.getRegistry(
|
|
||||||
connection.getConfiguration());
|
|
||||||
addListener(registry.getMetaRegionLocations(), (metaRegions, err) -> {
|
|
||||||
if (err != null) {
|
if (err != null) {
|
||||||
future.completeExceptionally(err);
|
future.completeExceptionally(err);
|
||||||
} else if (metaRegions == null || metaRegions.isEmpty() ||
|
} else if (metaRegions == null || metaRegions.isEmpty() ||
|
||||||
|
@ -1092,8 +1085,6 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||||
} else {
|
} else {
|
||||||
future.complete(Collections.singletonList(metaRegions.getDefaultRegionLocation()));
|
future.complete(Collections.singletonList(metaRegions.getDefaultRegionLocation()));
|
||||||
}
|
}
|
||||||
// close the registry.
|
|
||||||
IOUtils.closeQuietly(registry);
|
|
||||||
});
|
});
|
||||||
return future;
|
return future;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1689,11 +1680,10 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<ReplicationPeerConfig> getReplicationPeerConfig(String peerId) {
|
public CompletableFuture<ReplicationPeerConfig> getReplicationPeerConfig(String peerId) {
|
||||||
return this.<ReplicationPeerConfig> newMasterCaller().action((controller, stub) -> this
|
return this.<ReplicationPeerConfig> newMasterCaller().action((controller, stub) -> this
|
||||||
.<GetReplicationPeerConfigRequest, GetReplicationPeerConfigResponse, ReplicationPeerConfig> call(
|
.<GetReplicationPeerConfigRequest, GetReplicationPeerConfigResponse, ReplicationPeerConfig>
|
||||||
controller, stub, RequestConverter.buildGetReplicationPeerConfigRequest(peerId),
|
call(controller, stub, RequestConverter.buildGetReplicationPeerConfigRequest(peerId),
|
||||||
(s, c, req, done) -> s.getReplicationPeerConfig(c, req, done),
|
(s, c, req, done) -> s.getReplicationPeerConfig(c, req, done),
|
||||||
(resp) -> ReplicationPeerConfigUtil.convert(resp.getPeerConfig())))
|
(resp) -> ReplicationPeerConfigUtil.convert(resp.getPeerConfig()))).call();
|
||||||
.call();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1710,8 +1700,8 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> transitReplicationPeerSyncReplicationState(String peerId,
|
public CompletableFuture<Void> transitReplicationPeerSyncReplicationState(String peerId,
|
||||||
SyncReplicationState clusterState) {
|
SyncReplicationState clusterState) {
|
||||||
return this
|
return this.<TransitReplicationPeerSyncReplicationStateRequest,
|
||||||
.<TransitReplicationPeerSyncReplicationStateRequest, TransitReplicationPeerSyncReplicationStateResponse> procedureCall(
|
TransitReplicationPeerSyncReplicationStateResponse> procedureCall(
|
||||||
RequestConverter.buildTransitReplicationPeerSyncReplicationStateRequest(peerId,
|
RequestConverter.buildTransitReplicationPeerSyncReplicationStateRequest(peerId,
|
||||||
clusterState),
|
clusterState),
|
||||||
(s, c, req, done) -> s.transitReplicationPeerSyncReplicationState(c, req, done),
|
(s, c, req, done) -> s.transitReplicationPeerSyncReplicationState(c, req, done),
|
||||||
|
@ -1786,11 +1776,8 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||||
return this
|
return this
|
||||||
.<List<ReplicationPeerDescription>> newMasterCaller()
|
.<List<ReplicationPeerDescription>> newMasterCaller()
|
||||||
.action(
|
.action(
|
||||||
(controller, stub) -> this
|
(controller, stub) -> this.<ListReplicationPeersRequest, ListReplicationPeersResponse,
|
||||||
.<ListReplicationPeersRequest, ListReplicationPeersResponse, List<ReplicationPeerDescription>> call(
|
List<ReplicationPeerDescription>> call(controller, stub, request,
|
||||||
controller,
|
|
||||||
stub,
|
|
||||||
request,
|
|
||||||
(s, c, req, done) -> s.listReplicationPeers(c, req, done),
|
(s, c, req, done) -> s.listReplicationPeers(c, req, done),
|
||||||
(resp) -> resp.getPeerDescList().stream()
|
(resp) -> resp.getPeerDescList().stream()
|
||||||
.map(ReplicationPeerConfigUtil::toReplicationPeerDescription)
|
.map(ReplicationPeerConfigUtil::toReplicationPeerDescription)
|
||||||
|
@ -2299,11 +2286,13 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Void> decommissionRegionServers(List<ServerName> servers, boolean offload) {
|
public CompletableFuture<Void> decommissionRegionServers(
|
||||||
|
List<ServerName> servers, boolean offload) {
|
||||||
return this.<Void> newMasterCaller()
|
return this.<Void> newMasterCaller()
|
||||||
.action((controller, stub) -> this
|
.action((controller, stub) -> this
|
||||||
.<DecommissionRegionServersRequest, DecommissionRegionServersResponse, Void> call(
|
.<DecommissionRegionServersRequest, DecommissionRegionServersResponse, Void> call(
|
||||||
controller, stub, RequestConverter.buildDecommissionRegionServersRequest(servers, offload),
|
controller, stub,
|
||||||
|
RequestConverter.buildDecommissionRegionServersRequest(servers, offload),
|
||||||
(s, c, req, done) -> s.decommissionRegionServers(c, req, done), resp -> null))
|
(s, c, req, done) -> s.decommissionRegionServers(c, req, done), resp -> null))
|
||||||
.call();
|
.call();
|
||||||
}
|
}
|
||||||
|
@ -2325,11 +2314,11 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||||
public CompletableFuture<Void> recommissionRegionServer(ServerName server,
|
public CompletableFuture<Void> recommissionRegionServer(ServerName server,
|
||||||
List<byte[]> encodedRegionNames) {
|
List<byte[]> encodedRegionNames) {
|
||||||
return this.<Void> newMasterCaller()
|
return this.<Void> newMasterCaller()
|
||||||
.action((controller, stub) -> this
|
.action((controller, stub) ->
|
||||||
.<RecommissionRegionServerRequest, RecommissionRegionServerResponse, Void> call(controller,
|
this.<RecommissionRegionServerRequest, RecommissionRegionServerResponse, Void> call(
|
||||||
stub, RequestConverter.buildRecommissionRegionServerRequest(server, encodedRegionNames),
|
controller, stub, RequestConverter.buildRecommissionRegionServerRequest(
|
||||||
(s, c, req, done) -> s.recommissionRegionServer(c, req, done), resp -> null))
|
server, encodedRegionNames), (s, c, req, done) -> s.recommissionRegionServer(
|
||||||
.call();
|
c, req, done), resp -> null)).call();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2395,7 +2384,6 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||||
* Get the region info for the passed region name. The region name may be a full region name or
|
* Get the region info for the passed region name. The region name may be a full region name or
|
||||||
* encoded region name. If the region does not found, then it'll throw an UnknownRegionException
|
* encoded region name. If the region does not found, then it'll throw an UnknownRegionException
|
||||||
* wrapped by a {@link CompletableFuture}
|
* wrapped by a {@link CompletableFuture}
|
||||||
* @param regionNameOrEncodedRegionName
|
|
||||||
* @return region info, wrapped by a {@link CompletableFuture}
|
* @return region info, wrapped by a {@link CompletableFuture}
|
||||||
*/
|
*/
|
||||||
private CompletableFuture<RegionInfo> getRegionInfo(byte[] regionNameOrEncodedRegionName) {
|
private CompletableFuture<RegionInfo> getRegionInfo(byte[] regionNameOrEncodedRegionName) {
|
||||||
|
@ -2886,10 +2874,11 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||||
.<List<SecurityCapability>> newMasterCaller()
|
.<List<SecurityCapability>> newMasterCaller()
|
||||||
.action(
|
.action(
|
||||||
(controller, stub) -> this
|
(controller, stub) -> this
|
||||||
.<SecurityCapabilitiesRequest, SecurityCapabilitiesResponse, List<SecurityCapability>> call(
|
.<SecurityCapabilitiesRequest, SecurityCapabilitiesResponse, List<SecurityCapability>>
|
||||||
controller, stub, SecurityCapabilitiesRequest.newBuilder().build(), (s, c, req,
|
call(controller, stub, SecurityCapabilitiesRequest.newBuilder().build(),
|
||||||
done) -> s.getSecurityCapabilities(c, req, done), (resp) -> ProtobufUtil
|
(s, c, req, done) -> s.getSecurityCapabilities(c, req, done),
|
||||||
.toSecurityCapabilityList(resp.getCapabilitiesList()))).call();
|
(resp) -> ProtobufUtil.toSecurityCapabilityList(resp.getCapabilitiesList())))
|
||||||
|
.call();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3066,14 +3055,10 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||||
MajorCompactionTimestampRequest request =
|
MajorCompactionTimestampRequest request =
|
||||||
MajorCompactionTimestampRequest.newBuilder()
|
MajorCompactionTimestampRequest.newBuilder()
|
||||||
.setTableName(ProtobufUtil.toProtoTableName(tableName)).build();
|
.setTableName(ProtobufUtil.toProtoTableName(tableName)).build();
|
||||||
return this
|
return this.<Optional<Long>> newMasterCaller().action((controller, stub) ->
|
||||||
.<Optional<Long>> newMasterCaller()
|
this.<MajorCompactionTimestampRequest, MajorCompactionTimestampResponse, Optional<Long>>
|
||||||
.action(
|
call(controller, stub, request, (s, c, req, done) -> s.getLastMajorCompactionTimestamp(
|
||||||
(controller, stub) -> this
|
c, req, done), ProtobufUtil::toOptionalTimestamp)).call();
|
||||||
.<MajorCompactionTimestampRequest, MajorCompactionTimestampResponse, Optional<Long>> call(
|
|
||||||
controller, stub, request,
|
|
||||||
(s, c, req, done) -> s.getLastMajorCompactionTimestamp(c, req, done),
|
|
||||||
ProtobufUtil::toOptionalTimestamp)).call();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3213,11 +3198,10 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
|
||||||
public CompletableFuture<Boolean> isBalancerEnabled() {
|
public CompletableFuture<Boolean> isBalancerEnabled() {
|
||||||
return this
|
return this
|
||||||
.<Boolean> newMasterCaller()
|
.<Boolean> newMasterCaller()
|
||||||
.action(
|
.action((controller, stub) ->
|
||||||
(controller, stub) -> this.<IsBalancerEnabledRequest, IsBalancerEnabledResponse, Boolean> call(
|
this.<IsBalancerEnabledRequest, IsBalancerEnabledResponse, Boolean> call(controller,
|
||||||
controller, stub, RequestConverter.buildIsBalancerEnabledRequest(),
|
stub, RequestConverter.buildIsBalancerEnabledRequest(), (s, c, req, done)
|
||||||
(s, c, req, done) -> s.isBalancerEnabled(c, req, done), (resp) -> resp.getEnabled()))
|
-> s.isBalancerEnabled(c, req, done), (resp) -> resp.getEnabled())).call();
|
||||||
.call();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue