Skip to content

Commit 929f561

Browse files
committed
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.
1 parent d0f6883 commit 929f561

4 files changed

Lines changed: 265 additions & 23 deletions

File tree

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
@@ -376,7 +376,9 @@ private static IOException makeIOExceptionOfException(Throwable e) {
376376
* @see #toServerName(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.ServerName)
377377
*/
378378
public static HBaseProtos.ServerName toServerName(final ServerName serverName) {
379-
if (serverName == null) return null;
379+
if (serverName == null) {
380+
return null;
381+
}
380382
HBaseProtos.ServerName.Builder builder =
381383
HBaseProtos.ServerName.newBuilder();
382384
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
@@ -1200,3 +1200,47 @@ service HbckService {
12001200
rpc FixMeta(FixMetaRequest)
12011201
returns(FixMetaResponse);
12021202
}
1203+
1204+
/** Request and response to get the clusterID for this cluster */
1205+
message GetClusterIdRequest {
1206+
}
1207+
message GetClusterIdResponse {
1208+
/** Not set if cluster ID could not be determined. */
1209+
optional string cluster_id = 1;
1210+
}
1211+
1212+
/** Request and response to get the currently active master name for this cluster */
1213+
message GetActiveMasterRequest {
1214+
}
1215+
message GetActiveMasterResponse {
1216+
/** Not set if an active master could not be determined. */
1217+
optional ServerName server_name = 1;
1218+
}
1219+
1220+
/** Request and response to get the current list of meta region locations */
1221+
message GetMetaRegionLocationsRequest {
1222+
}
1223+
message GetMetaRegionLocationsResponse {
1224+
/** Not set if meta region locations could not be determined. */
1225+
repeated RegionLocation meta_locations = 1;
1226+
}
1227+
1228+
/**
1229+
* Implements all the RPCs needed by clients to look up cluster meta information needed for connection establishment.
1230+
*/
1231+
service ClientMetaService {
1232+
/**
1233+
* Get Cluster ID for this cluster.
1234+
*/
1235+
rpc GetClusterId(GetClusterIdRequest) returns(GetClusterIdResponse);
1236+
1237+
/**
1238+
* Get active master server name for this cluster.
1239+
*/
1240+
rpc GetActiveMaster(GetActiveMasterRequest) returns(GetActiveMasterResponse);
1241+
1242+
/**
1243+
* Get current meta replicas' region locations.
1244+
*/
1245+
rpc GetMetaRegionLocations(GetMetaRegionLocationsRequest) returns(GetMetaRegionLocationsResponse);
1246+
}

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

Lines changed: 65 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
*
33
* Licensed to the Apache Software Foundation (ASF) under one
44
* or more contributor license agreements. See the NOTICE file
@@ -19,7 +19,6 @@
1919
package org.apache.hadoop.hbase.master;
2020

2121
import static org.apache.hadoop.hbase.master.MasterWalManager.META_FILTER;
22-
2322
import java.io.FileNotFoundException;
2423
import java.io.IOException;
2524
import java.net.BindException;
@@ -31,13 +30,15 @@
3130
import java.util.List;
3231
import java.util.Map;
3332
import java.util.Map.Entry;
33+
import java.util.Optional;
3434
import java.util.Set;
3535
import java.util.stream.Collectors;
3636
import org.apache.hadoop.conf.Configuration;
3737
import org.apache.hadoop.fs.Path;
3838
import org.apache.hadoop.hbase.ClusterMetricsBuilder;
3939
import org.apache.hadoop.hbase.DoNotRetryIOException;
4040
import org.apache.hadoop.hbase.HConstants;
41+
import org.apache.hadoop.hbase.HRegionLocation;
4142
import org.apache.hadoop.hbase.MetaTableAccessor;
4243
import org.apache.hadoop.hbase.NamespaceDescriptor;
4344
import org.apache.hadoop.hbase.Server;
@@ -117,11 +118,9 @@
117118
import org.apache.zookeeper.KeeperException;
118119
import org.slf4j.Logger;
119120
import org.slf4j.LoggerFactory;
120-
121121
import org.apache.hbase.thirdparty.com.google.protobuf.RpcController;
122122
import org.apache.hbase.thirdparty.com.google.protobuf.ServiceException;
123123
import org.apache.hbase.thirdparty.com.google.protobuf.UnsafeByteOperations;
124-
125124
import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
126125
import org.apache.hadoop.hbase.shaded.protobuf.ResponseConverter;
127126
import org.apache.hadoop.hbase.shaded.protobuf.generated.AccessControlProtos;
@@ -162,6 +161,7 @@
162161
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.BalanceResponse;
163162
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ClearDeadServersRequest;
164163
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ClearDeadServersResponse;
164+
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ClientMetaService;
165165
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.CreateNamespaceRequest;
166166
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.CreateNamespaceResponse;
167167
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.CreateTableRequest;
@@ -186,12 +186,18 @@
186186
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.ExecProcedureResponse;
187187
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.FixMetaRequest;
188188
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.FixMetaResponse;
189+
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetActiveMasterRequest;
190+
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetActiveMasterResponse;
191+
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetClusterIdRequest;
192+
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetClusterIdResponse;
189193
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetClusterStatusRequest;
190194
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetClusterStatusResponse;
191195
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetCompletedSnapshotsRequest;
192196
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetCompletedSnapshotsResponse;
193197
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetLocksRequest;
194198
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetLocksResponse;
199+
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetMetaRegionLocationsRequest;
200+
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetMetaRegionLocationsResponse;
195201
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetNamespaceDescriptorRequest;
196202
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetNamespaceDescriptorResponse;
197203
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetProcedureResultRequest;
@@ -352,9 +358,10 @@
352358
*/
353359
@InterfaceAudience.Private
354360
@SuppressWarnings("deprecation")
355-
public class MasterRpcServices extends RSRpcServices
356-
implements MasterService.BlockingInterface, RegionServerStatusService.BlockingInterface,
357-
LockService.BlockingInterface, HbckService.BlockingInterface {
361+
public class MasterRpcServices extends RSRpcServices implements
362+
MasterService.BlockingInterface, RegionServerStatusService.BlockingInterface,
363+
LockService.BlockingInterface, HbckService.BlockingInterface,
364+
ClientMetaService.BlockingInterface {
358365
private static final Logger LOG = LoggerFactory.getLogger(MasterRpcServices.class.getName());
359366
private static final Logger AUDITLOG =
360367
LoggerFactory.getLogger("SecurityLogger."+MasterRpcServices.class.getName());
@@ -363,7 +370,7 @@ public class MasterRpcServices extends RSRpcServices
363370

364371
/**
365372
* @return Subset of configuration to pass initializing regionservers: e.g.
366-
* the filesystem to use and root directory to use.
373+
* the filesystem to use and root directory to use.
367374
*/
368375
private RegionServerStartupResponse.Builder createConfigurationSubset() {
369376
RegionServerStartupResponse.Builder resp = addConfig(
@@ -489,15 +496,17 @@ boolean synchronousBalanceSwitch(final boolean b) throws IOException {
489496
protected List<BlockingServiceAndInterface> getServices() {
490497
List<BlockingServiceAndInterface> bssi = new ArrayList<>(5);
491498
bssi.add(new BlockingServiceAndInterface(
492-
MasterService.newReflectiveBlockingService(this),
493-
MasterService.BlockingInterface.class));
499+
MasterService.newReflectiveBlockingService(this),
500+
MasterService.BlockingInterface.class));
494501
bssi.add(new BlockingServiceAndInterface(
495-
RegionServerStatusService.newReflectiveBlockingService(this),
496-
RegionServerStatusService.BlockingInterface.class));
502+
RegionServerStatusService.newReflectiveBlockingService(this),
503+
RegionServerStatusService.BlockingInterface.class));
497504
bssi.add(new BlockingServiceAndInterface(LockService.newReflectiveBlockingService(this),
498505
LockService.BlockingInterface.class));
499506
bssi.add(new BlockingServiceAndInterface(HbckService.newReflectiveBlockingService(this),
500507
HbckService.BlockingInterface.class));
508+
bssi.add(new BlockingServiceAndInterface(ClientMetaService.newReflectiveBlockingService(this),
509+
ClientMetaService.BlockingInterface.class));
501510
bssi.addAll(super.getServices());
502511
return bssi;
503512
}
@@ -624,7 +633,9 @@ public AssignRegionResponse assignRegion(RpcController controller,
624633

625634
final byte[] regionName = req.getRegion().getValue().toByteArray();
626635
final RegionInfo regionInfo = master.getAssignmentManager().getRegionInfo(regionName);
627-
if (regionInfo == null) throw new UnknownRegionException(Bytes.toStringBinary(regionName));
636+
if (regionInfo == null) {
637+
throw new UnknownRegionException(Bytes.toStringBinary(regionName));
638+
}
628639

629640
final AssignRegionResponse arr = AssignRegionResponse.newBuilder().build();
630641
if (master.cpHost != null) {
@@ -669,7 +680,7 @@ public CreateNamespaceResponse createNamespace(RpcController controller,
669680

670681
@Override
671682
public CreateTableResponse createTable(RpcController controller, CreateTableRequest req)
672-
throws ServiceException {
683+
throws ServiceException {
673684
TableDescriptor tableDescriptor = ProtobufUtil.toTableDescriptor(req.getTableSchema());
674685
byte [][] splitKeys = ProtobufUtil.getSplitKeysArray(req);
675686
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);
@@ -2292,8 +2305,8 @@ public RegionSpaceUseReportResponse reportRegionSpaceUse(RpcController controlle
22922305
report.getRegionSize(), now);
22932306
}
22942307
} else {
2295-
LOG.debug(
2296-
"Received region space usage report but HMaster is not ready to process it, skipping");
2308+
LOG.debug("Received region space usage report but HMaster is not ready to process it, "
2309+
+ "skipping");
22972310
}
22982311
return RegionSpaceUseReportResponse.newBuilder().build();
22992312
} catch (Exception e) {
@@ -2329,8 +2342,8 @@ public GetSpaceQuotaRegionSizesResponse getSpaceQuotaRegionSizes(
23292342
}
23302343
return builder.build();
23312344
} else {
2332-
LOG.debug(
2333-
"Received space quota region size report but HMaster is not ready to process it, skipping");
2345+
LOG.debug("Received space quota region size report but HMaster is not ready to process it,"
2346+
+ "skipping");
23342347
}
23352348
return builder.build();
23362349
} catch (Exception e) {
@@ -2874,4 +2887,34 @@ private boolean shouldSubmitSCP(ServerName serverName) {
28742887
return true;
28752888
}
28762889

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

0 commit comments

Comments
 (0)