1818package org .apache .hadoop .hbase .master ;
1919
2020import static org .apache .hadoop .hbase .master .MasterWalManager .META_FILTER ;
21-
2221import java .io .FileNotFoundException ;
2322import java .io .IOException ;
2423import java .net .BindException ;
3029import java .util .List ;
3130import java .util .Map ;
3231import java .util .Map .Entry ;
32+ import java .util .Optional ;
3333import java .util .Set ;
3434import java .util .stream .Collectors ;
3535
3838import org .apache .hadoop .hbase .ClusterMetricsBuilder ;
3939import org .apache .hadoop .hbase .DoNotRetryIOException ;
4040import org .apache .hadoop .hbase .HConstants ;
41+ import org .apache .hadoop .hbase .HRegionLocation ;
4142import org .apache .hadoop .hbase .MetaTableAccessor ;
4243import org .apache .hadoop .hbase .NamespaceDescriptor ;
4344import org .apache .hadoop .hbase .Server ;
119120import org .apache .zookeeper .KeeperException ;
120121import org .slf4j .Logger ;
121122import org .slf4j .LoggerFactory ;
122-
123123import org .apache .hbase .thirdparty .com .google .protobuf .RpcController ;
124124import org .apache .hbase .thirdparty .com .google .protobuf .ServiceException ;
125125import org .apache .hbase .thirdparty .com .google .protobuf .UnsafeByteOperations ;
126-
127-
128126import org .apache .hadoop .hbase .shaded .protobuf .ProtobufUtil ;
129127import org .apache .hadoop .hbase .shaded .protobuf .ResponseConverter ;
130128import org .apache .hadoop .hbase .shaded .protobuf .generated .AccessControlProtos ;
165163import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .BalanceResponse ;
166164import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .ClearDeadServersRequest ;
167165import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .ClearDeadServersResponse ;
166+ import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .ClientMetaService ;
168167import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .CreateNamespaceRequest ;
169168import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .CreateNamespaceResponse ;
170169import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .CreateTableRequest ;
189188import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .ExecProcedureResponse ;
190189import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .FixMetaRequest ;
191190import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .FixMetaResponse ;
191+ import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetActiveMasterRequest ;
192+ import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetActiveMasterResponse ;
193+ import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetClusterIdRequest ;
194+ import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetClusterIdResponse ;
192195import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetClusterStatusRequest ;
193196import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetClusterStatusResponse ;
194197import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetCompletedSnapshotsRequest ;
195198import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetCompletedSnapshotsResponse ;
196199import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetLocksRequest ;
197200import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetLocksResponse ;
201+ import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetMetaRegionLocationsRequest ;
202+ import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetMetaRegionLocationsResponse ;
198203import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetNamespaceDescriptorRequest ;
199204import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetNamespaceDescriptorResponse ;
200205import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetProcedureResultRequest ;
357362 */
358363@ InterfaceAudience .Private
359364@ SuppressWarnings ("deprecation" )
360- public class MasterRpcServices extends RSRpcServices
361- implements MasterService .BlockingInterface , RegionServerStatusService .BlockingInterface ,
362- LockService .BlockingInterface , HbckService .BlockingInterface {
365+ public class MasterRpcServices extends RSRpcServices implements
366+ MasterService .BlockingInterface , RegionServerStatusService .BlockingInterface ,
367+ LockService .BlockingInterface , HbckService .BlockingInterface ,
368+ ClientMetaService .BlockingInterface {
363369 private static final Logger LOG = LoggerFactory .getLogger (MasterRpcServices .class .getName ());
364370 private static final Logger AUDITLOG =
365371 LoggerFactory .getLogger ("SecurityLogger." +MasterRpcServices .class .getName ());
@@ -368,7 +374,7 @@ public class MasterRpcServices extends RSRpcServices
368374
369375 /**
370376 * @return Subset of configuration to pass initializing regionservers: e.g.
371- * the filesystem to use and root directory to use.
377+ * the filesystem to use and root directory to use.
372378 */
373379 private RegionServerStartupResponse .Builder createConfigurationSubset () {
374380 RegionServerStartupResponse .Builder resp = addConfig (
@@ -494,15 +500,17 @@ boolean synchronousBalanceSwitch(final boolean b) throws IOException {
494500 protected List <BlockingServiceAndInterface > getServices () {
495501 List <BlockingServiceAndInterface > bssi = new ArrayList <>(5 );
496502 bssi .add (new BlockingServiceAndInterface (
497- MasterService .newReflectiveBlockingService (this ),
498- MasterService .BlockingInterface .class ));
503+ MasterService .newReflectiveBlockingService (this ),
504+ MasterService .BlockingInterface .class ));
499505 bssi .add (new BlockingServiceAndInterface (
500- RegionServerStatusService .newReflectiveBlockingService (this ),
501- RegionServerStatusService .BlockingInterface .class ));
506+ RegionServerStatusService .newReflectiveBlockingService (this ),
507+ RegionServerStatusService .BlockingInterface .class ));
502508 bssi .add (new BlockingServiceAndInterface (LockService .newReflectiveBlockingService (this ),
503509 LockService .BlockingInterface .class ));
504510 bssi .add (new BlockingServiceAndInterface (HbckService .newReflectiveBlockingService (this ),
505511 HbckService .BlockingInterface .class ));
512+ bssi .add (new BlockingServiceAndInterface (ClientMetaService .newReflectiveBlockingService (this ),
513+ ClientMetaService .BlockingInterface .class ));
506514 bssi .addAll (super .getServices ());
507515 return bssi ;
508516 }
@@ -629,7 +637,9 @@ public AssignRegionResponse assignRegion(RpcController controller,
629637
630638 final byte [] regionName = req .getRegion ().getValue ().toByteArray ();
631639 final RegionInfo regionInfo = master .getAssignmentManager ().getRegionInfo (regionName );
632- if (regionInfo == null ) throw new UnknownRegionException (Bytes .toStringBinary (regionName ));
640+ if (regionInfo == null ) {
641+ throw new UnknownRegionException (Bytes .toStringBinary (regionName ));
642+ }
633643
634644 final AssignRegionResponse arr = AssignRegionResponse .newBuilder ().build ();
635645 if (master .cpHost != null ) {
@@ -674,7 +684,7 @@ public CreateNamespaceResponse createNamespace(RpcController controller,
674684
675685 @ Override
676686 public CreateTableResponse createTable (RpcController controller , CreateTableRequest req )
677- throws ServiceException {
687+ throws ServiceException {
678688 TableDescriptor tableDescriptor = ProtobufUtil .toTableDescriptor (req .getTableSchema ());
679689 byte [][] splitKeys = ProtobufUtil .getSplitKeysArray (req );
680690 try {
@@ -1071,7 +1081,7 @@ public GetSchemaAlterStatusResponse getSchemaAlterStatus(
10711081 * Get list of TableDescriptors for requested tables.
10721082 * @param c Unused (set to null).
10731083 * @param req GetTableDescriptorsRequest that contains:
1074- * - tableNames: requested tables, or if empty, all are requested
1084+ * - tableNames: requested tables, or if empty, all are requested.
10751085 * @return GetTableDescriptorsResponse
10761086 * @throws ServiceException
10771087 */
@@ -1215,9 +1225,9 @@ public IsProcedureDoneResponse isProcedureDone(RpcController controller,
12151225 /**
12161226 * Checks if the specified snapshot is done.
12171227 * @return true if the snapshot is in file system ready to use,
1218- * false if the snapshot is in the process of completing
1228+ * false if the snapshot is in the process of completing
12191229 * @throws ServiceException wrapping UnknownSnapshotException if invalid snapshot, or
1220- * a wrapped HBaseSnapshotException with progress failure reason.
1230+ * a wrapped HBaseSnapshotException with progress failure reason.
12211231 */
12221232 @ Override
12231233 public IsSnapshotDoneResponse isSnapshotDone (RpcController controller ,
@@ -1459,7 +1469,9 @@ public OfflineRegionResponse offlineRegion(RpcController controller,
14591469
14601470 final byte [] regionName = request .getRegion ().getValue ().toByteArray ();
14611471 final RegionInfo hri = master .getAssignmentManager ().getRegionInfo (regionName );
1462- if (hri == null ) throw new UnknownRegionException (Bytes .toStringBinary (regionName ));
1472+ if (hri == null ) {
1473+ throw new UnknownRegionException (Bytes .toStringBinary (regionName ));
1474+ }
14631475
14641476 if (master .cpHost != null ) {
14651477 master .cpHost .preRegionOffline (hri );
@@ -2274,8 +2286,8 @@ public RegionSpaceUseReportResponse reportRegionSpaceUse(RpcController controlle
22742286 report .getRegionSize (), now );
22752287 }
22762288 } else {
2277- LOG .debug (
2278- "Received region space usage report but HMaster is not ready to process it, skipping" );
2289+ LOG .debug ("Received region space usage report but HMaster is not ready to process it, "
2290+ + " skipping" );
22792291 }
22802292 return RegionSpaceUseReportResponse .newBuilder ().build ();
22812293 } catch (Exception e ) {
@@ -2311,8 +2323,8 @@ public GetSpaceQuotaRegionSizesResponse getSpaceQuotaRegionSizes(
23112323 }
23122324 return builder .build ();
23132325 } else {
2314- LOG .debug (
2315- "Received space quota region size report but HMaster is not ready to process it, skipping" );
2326+ LOG .debug ("Received space quota region size report but HMaster is not ready to process it,"
2327+ + " skipping" );
23162328 }
23172329 return builder .build ();
23182330 } catch (Exception e ) {
@@ -2856,4 +2868,34 @@ private boolean shouldSubmitSCP(ServerName serverName) {
28562868 return true ;
28572869 }
28582870
2871+ @ Override
2872+ public GetClusterIdResponse getClusterId (RpcController rpcController , GetClusterIdRequest request )
2873+ throws ServiceException {
2874+ GetClusterIdResponse .Builder resp = GetClusterIdResponse .newBuilder ();
2875+ String clusterId = master .getClusterId ();
2876+ if (clusterId != null ) {
2877+ resp .setClusterId (clusterId );
2878+ }
2879+ return resp .build ();
2880+ }
2881+
2882+ @ Override
2883+ public GetActiveMasterResponse getActiveMaster (RpcController rpcController ,
2884+ GetActiveMasterRequest request ) throws ServiceException {
2885+ GetActiveMasterResponse .Builder resp = GetActiveMasterResponse .newBuilder ();
2886+ Optional <ServerName > serverName = master .getActiveMaster ();
2887+ serverName .ifPresent (name -> resp .setServerName (ProtobufUtil .toServerName (name )));
2888+ return resp .build ();
2889+ }
2890+
2891+ @ Override
2892+ public GetMetaRegionLocationsResponse getMetaRegionLocations (RpcController rpcController ,
2893+ GetMetaRegionLocationsRequest request ) throws ServiceException {
2894+ GetMetaRegionLocationsResponse .Builder response = GetMetaRegionLocationsResponse .newBuilder ();
2895+ Optional <List <HRegionLocation >> metaLocations =
2896+ master .getMetaRegionLocationCache ().getMetaRegionLocations ();
2897+ metaLocations .ifPresent (hRegionLocations -> hRegionLocations .forEach (
2898+ location -> response .addMetaLocations (ProtobufUtil .toRegionLocation (location ))));
2899+ return response .build ();
2900+ }
28592901}
0 commit comments