Skip to content

Commit d1afd8d

Browse files
committed
HBASE-23304: RPCs needed for client meta information lookup (apache#904)
* HBASE-23304: RPCs needed for client meta information lookup This patch implements the RPCs needed for the meta information lookup during connection init. New tests added to cover the RPC code paths. HBASE-23305 builds on this to implement the client side logic. Fixed a bunch of checkstyle nits around the places the patch touches. Signed-off-by: Andrew Purtell <apurtell@apache.org> (cherry picked from commit 4f8fbba)
1 parent ca26328 commit d1afd8d

File tree

4 files changed

+275
-22
lines changed

4 files changed

+275
-22
lines changed

hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,9 @@ private static IOException makeIOExceptionOfException(Exception e) {
377377
* @see #toServerName(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.ServerName)
378378
*/
379379
public static HBaseProtos.ServerName toServerName(final ServerName serverName) {
380-
if (serverName == null) return null;
380+
if (serverName == null) {
381+
return null;
382+
}
381383
HBaseProtos.ServerName.Builder builder =
382384
HBaseProtos.ServerName.newBuilder();
383385
builder.setHostName(serverName.getHostname());

hbase-protocol-shaded/src/main/protobuf/Master.proto

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,3 +1196,47 @@ service HbckService {
11961196
rpc FixMeta(FixMetaRequest)
11971197
returns(FixMetaResponse);
11981198
}
1199+
1200+
/** Request and response to get the clusterID for this cluster */
1201+
message GetClusterIdRequest {
1202+
}
1203+
message GetClusterIdResponse {
1204+
/** Not set if cluster ID could not be determined. */
1205+
optional string cluster_id = 1;
1206+
}
1207+
1208+
/** Request and response to get the currently active master name for this cluster */
1209+
message GetActiveMasterRequest {
1210+
}
1211+
message GetActiveMasterResponse {
1212+
/** Not set if an active master could not be determined. */
1213+
optional ServerName server_name = 1;
1214+
}
1215+
1216+
/** Request and response to get the current list of meta region locations */
1217+
message GetMetaRegionLocationsRequest {
1218+
}
1219+
message GetMetaRegionLocationsResponse {
1220+
/** Not set if meta region locations could not be determined. */
1221+
repeated RegionLocation meta_locations = 1;
1222+
}
1223+
1224+
/**
1225+
* Implements all the RPCs needed by clients to look up cluster meta information needed for connection establishment.
1226+
*/
1227+
service ClientMetaService {
1228+
/**
1229+
* Get Cluster ID for this cluster.
1230+
*/
1231+
rpc GetClusterId(GetClusterIdRequest) returns(GetClusterIdResponse);
1232+
1233+
/**
1234+
* Get active master server name for this cluster.
1235+
*/
1236+
rpc GetActiveMaster(GetActiveMasterRequest) returns(GetActiveMasterResponse);
1237+
1238+
/**
1239+
* Get current meta replicas' region locations.
1240+
*/
1241+
rpc GetMetaRegionLocations(GetMetaRegionLocationsRequest) returns(GetMetaRegionLocationsResponse);
1242+
}

hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java

Lines changed: 64 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.apache.hadoop.hbase.master;
1919

2020
import static org.apache.hadoop.hbase.master.MasterWalManager.META_FILTER;
21-
2221
import java.io.FileNotFoundException;
2322
import java.io.IOException;
2423
import java.net.BindException;
@@ -30,13 +29,15 @@
3029
import java.util.List;
3130
import java.util.Map;
3231
import java.util.Map.Entry;
32+
import java.util.Optional;
3333
import java.util.Set;
3434
import java.util.stream.Collectors;
3535
import org.apache.hadoop.conf.Configuration;
3636
import org.apache.hadoop.fs.Path;
3737
import org.apache.hadoop.hbase.ClusterMetricsBuilder;
3838
import org.apache.hadoop.hbase.DoNotRetryIOException;
3939
import org.apache.hadoop.hbase.HConstants;
40+
import org.apache.hadoop.hbase.HRegionLocation;
4041
import org.apache.hadoop.hbase.MetaTableAccessor;
4142
import org.apache.hadoop.hbase.NamespaceDescriptor;
4243
import org.apache.hadoop.hbase.Server;
@@ -116,11 +117,9 @@
116117
import org.apache.zookeeper.KeeperException;
117118
import org.slf4j.Logger;
118119
import org.slf4j.LoggerFactory;
119-
120120
import org.apache.hbase.thirdparty.com.google.protobuf.RpcController;
121121
import org.apache.hbase.thirdparty.com.google.protobuf.ServiceException;
122122
import org.apache.hbase.thirdparty.com.google.protobuf.UnsafeByteOperations;
123-
124123
import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
125124
import org.apache.hadoop.hbase.shaded.protobuf.ResponseConverter;
126125
import org.apache.hadoop.hbase.shaded.protobuf.generated.AccessControlProtos;
@@ -161,6 +160,7 @@
161160
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.BalanceResponse;
162161
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ClearDeadServersRequest;
163162
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ClearDeadServersResponse;
163+
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ClientMetaService;
164164
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.CreateNamespaceRequest;
165165
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.CreateNamespaceResponse;
166166
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.CreateTableRequest;
@@ -185,12 +185,18 @@
185185
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ExecProcedureResponse;
186186
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.FixMetaRequest;
187187
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.FixMetaResponse;
188+
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetActiveMasterRequest;
189+
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetActiveMasterResponse;
190+
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetClusterIdRequest;
191+
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetClusterIdResponse;
188192
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetClusterStatusRequest;
189193
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetClusterStatusResponse;
190194
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetCompletedSnapshotsRequest;
191195
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetCompletedSnapshotsResponse;
192196
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetLocksRequest;
193197
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetLocksResponse;
198+
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetMetaRegionLocationsRequest;
199+
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetMetaRegionLocationsResponse;
194200
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetNamespaceDescriptorRequest;
195201
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetNamespaceDescriptorResponse;
196202
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetProcedureResultRequest;
@@ -349,9 +355,10 @@
349355
*/
350356
@InterfaceAudience.Private
351357
@SuppressWarnings("deprecation")
352-
public class MasterRpcServices extends RSRpcServices
353-
implements MasterService.BlockingInterface, RegionServerStatusService.BlockingInterface,
354-
LockService.BlockingInterface, HbckService.BlockingInterface {
358+
public class MasterRpcServices extends RSRpcServices implements
359+
MasterService.BlockingInterface, RegionServerStatusService.BlockingInterface,
360+
LockService.BlockingInterface, HbckService.BlockingInterface,
361+
ClientMetaService.BlockingInterface {
355362
private static final Logger LOG = LoggerFactory.getLogger(MasterRpcServices.class.getName());
356363
private static final Logger AUDITLOG =
357364
LoggerFactory.getLogger("SecurityLogger."+MasterRpcServices.class.getName());
@@ -360,7 +367,7 @@ public class MasterRpcServices extends RSRpcServices
360367

361368
/**
362369
* @return Subset of configuration to pass initializing regionservers: e.g.
363-
* the filesystem to use and root directory to use.
370+
* the filesystem to use and root directory to use.
364371
*/
365372
private RegionServerStartupResponse.Builder createConfigurationSubset() {
366373
RegionServerStartupResponse.Builder resp = addConfig(
@@ -486,15 +493,17 @@ boolean synchronousBalanceSwitch(final boolean b) throws IOException {
486493
protected List<BlockingServiceAndInterface> getServices() {
487494
List<BlockingServiceAndInterface> bssi = new ArrayList<>(5);
488495
bssi.add(new BlockingServiceAndInterface(
489-
MasterService.newReflectiveBlockingService(this),
490-
MasterService.BlockingInterface.class));
496+
MasterService.newReflectiveBlockingService(this),
497+
MasterService.BlockingInterface.class));
491498
bssi.add(new BlockingServiceAndInterface(
492-
RegionServerStatusService.newReflectiveBlockingService(this),
493-
RegionServerStatusService.BlockingInterface.class));
499+
RegionServerStatusService.newReflectiveBlockingService(this),
500+
RegionServerStatusService.BlockingInterface.class));
494501
bssi.add(new BlockingServiceAndInterface(LockService.newReflectiveBlockingService(this),
495502
LockService.BlockingInterface.class));
496503
bssi.add(new BlockingServiceAndInterface(HbckService.newReflectiveBlockingService(this),
497504
HbckService.BlockingInterface.class));
505+
bssi.add(new BlockingServiceAndInterface(ClientMetaService.newReflectiveBlockingService(this),
506+
ClientMetaService.BlockingInterface.class));
498507
bssi.addAll(super.getServices());
499508
return bssi;
500509
}
@@ -621,7 +630,9 @@ public AssignRegionResponse assignRegion(RpcController controller,
621630

622631
final byte[] regionName = req.getRegion().getValue().toByteArray();
623632
final RegionInfo regionInfo = master.getAssignmentManager().getRegionInfo(regionName);
624-
if (regionInfo == null) throw new UnknownRegionException(Bytes.toStringBinary(regionName));
633+
if (regionInfo == null) {
634+
throw new UnknownRegionException(Bytes.toStringBinary(regionName));
635+
}
625636

626637
final AssignRegionResponse arr = AssignRegionResponse.newBuilder().build();
627638
if (master.cpHost != null) {
@@ -666,7 +677,7 @@ public CreateNamespaceResponse createNamespace(RpcController controller,
666677

667678
@Override
668679
public CreateTableResponse createTable(RpcController controller, CreateTableRequest req)
669-
throws ServiceException {
680+
throws ServiceException {
670681
TableDescriptor tableDescriptor = ProtobufUtil.toTableDescriptor(req.getTableSchema());
671682
byte [][] splitKeys = ProtobufUtil.getSplitKeysArray(req);
672683
try {
@@ -1063,7 +1074,7 @@ public GetSchemaAlterStatusResponse getSchemaAlterStatus(
10631074
* Get list of TableDescriptors for requested tables.
10641075
* @param c Unused (set to null).
10651076
* @param req GetTableDescriptorsRequest that contains:
1066-
* - tableNames: requested tables, or if empty, all are requested
1077+
* - tableNames: requested tables, or if empty, all are requested.
10671078
* @return GetTableDescriptorsResponse
10681079
* @throws ServiceException
10691080
*/
@@ -1207,9 +1218,9 @@ public IsProcedureDoneResponse isProcedureDone(RpcController controller,
12071218
/**
12081219
* Checks if the specified snapshot is done.
12091220
* @return true if the snapshot is in file system ready to use,
1210-
* false if the snapshot is in the process of completing
1221+
* false if the snapshot is in the process of completing
12111222
* @throws ServiceException wrapping UnknownSnapshotException if invalid snapshot, or
1212-
* a wrapped HBaseSnapshotException with progress failure reason.
1223+
* a wrapped HBaseSnapshotException with progress failure reason.
12131224
*/
12141225
@Override
12151226
public IsSnapshotDoneResponse isSnapshotDone(RpcController controller,
@@ -1451,7 +1462,9 @@ public OfflineRegionResponse offlineRegion(RpcController controller,
14511462

14521463
final byte[] regionName = request.getRegion().getValue().toByteArray();
14531464
final RegionInfo hri = master.getAssignmentManager().getRegionInfo(regionName);
1454-
if (hri == null) throw new UnknownRegionException(Bytes.toStringBinary(regionName));
1465+
if (hri == null) {
1466+
throw new UnknownRegionException(Bytes.toStringBinary(regionName));
1467+
}
14551468

14561469
if (master.cpHost != null) {
14571470
master.cpHost.preRegionOffline(hri);
@@ -2298,8 +2311,8 @@ public RegionSpaceUseReportResponse reportRegionSpaceUse(RpcController controlle
22982311
report.getRegionSize(), now);
22992312
}
23002313
} else {
2301-
LOG.debug(
2302-
"Received region space usage report but HMaster is not ready to process it, skipping");
2314+
LOG.debug("Received region space usage report but HMaster is not ready to process it, "
2315+
+ "skipping");
23032316
}
23042317
return RegionSpaceUseReportResponse.newBuilder().build();
23052318
} catch (Exception e) {
@@ -2335,8 +2348,8 @@ public GetSpaceQuotaRegionSizesResponse getSpaceQuotaRegionSizes(
23352348
}
23362349
return builder.build();
23372350
} else {
2338-
LOG.debug(
2339-
"Received space quota region size report but HMaster is not ready to process it, skipping");
2351+
LOG.debug("Received space quota region size report but HMaster is not ready to process it,"
2352+
+ "skipping");
23402353
}
23412354
return builder.build();
23422355
} catch (Exception e) {
@@ -2880,4 +2893,34 @@ private boolean shouldSubmitSCP(ServerName serverName) {
28802893
return true;
28812894
}
28822895

2896+
@Override
2897+
public GetClusterIdResponse getClusterId(RpcController rpcController, GetClusterIdRequest request)
2898+
throws ServiceException {
2899+
GetClusterIdResponse.Builder resp = GetClusterIdResponse.newBuilder();
2900+
String clusterId = master.getClusterId();
2901+
if (clusterId != null) {
2902+
resp.setClusterId(clusterId);
2903+
}
2904+
return resp.build();
2905+
}
2906+
2907+
@Override
2908+
public GetActiveMasterResponse getActiveMaster(RpcController rpcController,
2909+
GetActiveMasterRequest request) throws ServiceException {
2910+
GetActiveMasterResponse.Builder resp = GetActiveMasterResponse.newBuilder();
2911+
Optional<ServerName> serverName = master.getActiveMaster();
2912+
serverName.ifPresent(name -> resp.setServerName(ProtobufUtil.toServerName(name)));
2913+
return resp.build();
2914+
}
2915+
2916+
@Override
2917+
public GetMetaRegionLocationsResponse getMetaRegionLocations(RpcController rpcController,
2918+
GetMetaRegionLocationsRequest request) throws ServiceException {
2919+
GetMetaRegionLocationsResponse.Builder response = GetMetaRegionLocationsResponse.newBuilder();
2920+
Optional<List<HRegionLocation>> metaLocations =
2921+
master.getMetaRegionLocationCache().getMetaRegionLocations();
2922+
metaLocations.ifPresent(hRegionLocations -> hRegionLocations.forEach(
2923+
location -> response.addMetaLocations(ProtobufUtil.toRegionLocation(location))));
2924+
return response.build();
2925+
}
28832926
}

0 commit comments

Comments
 (0)