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 ;
3535import org .apache .hadoop .conf .Configuration ;
3636import org .apache .hadoop .fs .Path ;
3737import org .apache .hadoop .hbase .ClusterMetricsBuilder ;
3838import org .apache .hadoop .hbase .DoNotRetryIOException ;
3939import org .apache .hadoop .hbase .HConstants ;
40+ import org .apache .hadoop .hbase .HRegionLocation ;
4041import org .apache .hadoop .hbase .MetaTableAccessor ;
4142import org .apache .hadoop .hbase .NamespaceDescriptor ;
4243import org .apache .hadoop .hbase .Server ;
116117import org .apache .zookeeper .KeeperException ;
117118import org .slf4j .Logger ;
118119import org .slf4j .LoggerFactory ;
119-
120120import org .apache .hbase .thirdparty .com .google .protobuf .RpcController ;
121121import org .apache .hbase .thirdparty .com .google .protobuf .ServiceException ;
122122import org .apache .hbase .thirdparty .com .google .protobuf .UnsafeByteOperations ;
123-
124123import org .apache .hadoop .hbase .shaded .protobuf .ProtobufUtil ;
125124import org .apache .hadoop .hbase .shaded .protobuf .ResponseConverter ;
126125import org .apache .hadoop .hbase .shaded .protobuf .generated .AccessControlProtos ;
161160import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .BalanceResponse ;
162161import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .ClearDeadServersRequest ;
163162import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .ClearDeadServersResponse ;
163+ import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .ClientMetaService ;
164164import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .CreateNamespaceRequest ;
165165import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .CreateNamespaceResponse ;
166166import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .CreateTableRequest ;
185185import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .ExecProcedureResponse ;
186186import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .FixMetaRequest ;
187187import 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 ;
188192import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetClusterStatusRequest ;
189193import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetClusterStatusResponse ;
190194import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetCompletedSnapshotsRequest ;
191195import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetCompletedSnapshotsResponse ;
192196import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetLocksRequest ;
193197import 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 ;
194200import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetNamespaceDescriptorRequest ;
195201import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetNamespaceDescriptorResponse ;
196202import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetProcedureResultRequest ;
351357 */
352358@ InterfaceAudience .Private
353359@ SuppressWarnings ("deprecation" )
354- public class MasterRpcServices extends RSRpcServices
355- implements MasterService .BlockingInterface , RegionServerStatusService .BlockingInterface ,
356- LockService .BlockingInterface , HbckService .BlockingInterface {
360+ public class MasterRpcServices extends RSRpcServices implements
361+ MasterService .BlockingInterface , RegionServerStatusService .BlockingInterface ,
362+ LockService .BlockingInterface , HbckService .BlockingInterface ,
363+ ClientMetaService .BlockingInterface {
357364 private static final Logger LOG = LoggerFactory .getLogger (MasterRpcServices .class .getName ());
358365 private static final Logger AUDITLOG =
359366 LoggerFactory .getLogger ("SecurityLogger." +MasterRpcServices .class .getName ());
@@ -362,7 +369,7 @@ public class MasterRpcServices extends RSRpcServices
362369
363370 /**
364371 * @return Subset of configuration to pass initializing regionservers: e.g.
365- * the filesystem to use and root directory to use.
372+ * the filesystem to use and root directory to use.
366373 */
367374 private RegionServerStartupResponse .Builder createConfigurationSubset () {
368375 RegionServerStartupResponse .Builder resp = addConfig (
@@ -488,15 +495,17 @@ boolean synchronousBalanceSwitch(final boolean b) throws IOException {
488495 protected List <BlockingServiceAndInterface > getServices () {
489496 List <BlockingServiceAndInterface > bssi = new ArrayList <>(5 );
490497 bssi .add (new BlockingServiceAndInterface (
491- MasterService .newReflectiveBlockingService (this ),
492- MasterService .BlockingInterface .class ));
498+ MasterService .newReflectiveBlockingService (this ),
499+ MasterService .BlockingInterface .class ));
493500 bssi .add (new BlockingServiceAndInterface (
494- RegionServerStatusService .newReflectiveBlockingService (this ),
495- RegionServerStatusService .BlockingInterface .class ));
501+ RegionServerStatusService .newReflectiveBlockingService (this ),
502+ RegionServerStatusService .BlockingInterface .class ));
496503 bssi .add (new BlockingServiceAndInterface (LockService .newReflectiveBlockingService (this ),
497504 LockService .BlockingInterface .class ));
498505 bssi .add (new BlockingServiceAndInterface (HbckService .newReflectiveBlockingService (this ),
499506 HbckService .BlockingInterface .class ));
507+ bssi .add (new BlockingServiceAndInterface (ClientMetaService .newReflectiveBlockingService (this ),
508+ ClientMetaService .BlockingInterface .class ));
500509 bssi .addAll (super .getServices ());
501510 return bssi ;
502511 }
@@ -623,7 +632,9 @@ public AssignRegionResponse assignRegion(RpcController controller,
623632
624633 final byte [] regionName = req .getRegion ().getValue ().toByteArray ();
625634 final RegionInfo regionInfo = master .getAssignmentManager ().getRegionInfo (regionName );
626- if (regionInfo == null ) throw new UnknownRegionException (Bytes .toStringBinary (regionName ));
635+ if (regionInfo == null ) {
636+ throw new UnknownRegionException (Bytes .toStringBinary (regionName ));
637+ }
627638
628639 final AssignRegionResponse arr = AssignRegionResponse .newBuilder ().build ();
629640 if (master .cpHost != null ) {
@@ -668,7 +679,7 @@ public CreateNamespaceResponse createNamespace(RpcController controller,
668679
669680 @ Override
670681 public CreateTableResponse createTable (RpcController controller , CreateTableRequest req )
671- throws ServiceException {
682+ throws ServiceException {
672683 TableDescriptor tableDescriptor = ProtobufUtil .toTableDescriptor (req .getTableSchema ());
673684 byte [][] splitKeys = ProtobufUtil .getSplitKeysArray (req );
674685 try {
@@ -1062,7 +1073,7 @@ public GetSchemaAlterStatusResponse getSchemaAlterStatus(
10621073 * Get list of TableDescriptors for requested tables.
10631074 * @param c Unused (set to null).
10641075 * @param req GetTableDescriptorsRequest that contains:
1065- * - tableNames: requested tables, or if empty, all are requested
1076+ * - tableNames: requested tables, or if empty, all are requested.
10661077 * @return GetTableDescriptorsResponse
10671078 * @throws ServiceException
10681079 */
@@ -1206,9 +1217,9 @@ public IsProcedureDoneResponse isProcedureDone(RpcController controller,
12061217 /**
12071218 * Checks if the specified snapshot is done.
12081219 * @return true if the snapshot is in file system ready to use,
1209- * false if the snapshot is in the process of completing
1220+ * false if the snapshot is in the process of completing
12101221 * @throws ServiceException wrapping UnknownSnapshotException if invalid snapshot, or
1211- * a wrapped HBaseSnapshotException with progress failure reason.
1222+ * a wrapped HBaseSnapshotException with progress failure reason.
12121223 */
12131224 @ Override
12141225 public IsSnapshotDoneResponse isSnapshotDone (RpcController controller ,
@@ -1450,7 +1461,9 @@ public OfflineRegionResponse offlineRegion(RpcController controller,
14501461
14511462 final byte [] regionName = request .getRegion ().getValue ().toByteArray ();
14521463 final RegionInfo hri = master .getAssignmentManager ().getRegionInfo (regionName );
1453- if (hri == null ) throw new UnknownRegionException (Bytes .toStringBinary (regionName ));
1464+ if (hri == null ) {
1465+ throw new UnknownRegionException (Bytes .toStringBinary (regionName ));
1466+ }
14541467
14551468 if (master .cpHost != null ) {
14561469 master .cpHost .preRegionOffline (hri );
@@ -2311,8 +2324,8 @@ public RegionSpaceUseReportResponse reportRegionSpaceUse(RpcController controlle
23112324 report .getRegionSize (), now );
23122325 }
23132326 } else {
2314- LOG .debug (
2315- "Received region space usage report but HMaster is not ready to process it, skipping" );
2327+ LOG .debug ("Received region space usage report but HMaster is not ready to process it, "
2328+ + " skipping" );
23162329 }
23172330 return RegionSpaceUseReportResponse .newBuilder ().build ();
23182331 } catch (Exception e ) {
@@ -2348,8 +2361,8 @@ public GetSpaceQuotaRegionSizesResponse getSpaceQuotaRegionSizes(
23482361 }
23492362 return builder .build ();
23502363 } else {
2351- LOG .debug (
2352- "Received space quota region size report but HMaster is not ready to process it, skipping" );
2364+ LOG .debug ("Received space quota region size report but HMaster is not ready to process it,"
2365+ + " skipping" );
23532366 }
23542367 return builder .build ();
23552368 } catch (Exception e ) {
@@ -2893,4 +2906,34 @@ private boolean shouldSubmitSCP(ServerName serverName) {
28932906 return true ;
28942907 }
28952908
2909+ @ Override
2910+ public GetClusterIdResponse getClusterId (RpcController rpcController , GetClusterIdRequest request )
2911+ throws ServiceException {
2912+ GetClusterIdResponse .Builder resp = GetClusterIdResponse .newBuilder ();
2913+ String clusterId = master .getClusterId ();
2914+ if (clusterId != null ) {
2915+ resp .setClusterId (clusterId );
2916+ }
2917+ return resp .build ();
2918+ }
2919+
2920+ @ Override
2921+ public GetActiveMasterResponse getActiveMaster (RpcController rpcController ,
2922+ GetActiveMasterRequest request ) throws ServiceException {
2923+ GetActiveMasterResponse .Builder resp = GetActiveMasterResponse .newBuilder ();
2924+ Optional <ServerName > serverName = master .getActiveMaster ();
2925+ serverName .ifPresent (name -> resp .setServerName (ProtobufUtil .toServerName (name )));
2926+ return resp .build ();
2927+ }
2928+
2929+ @ Override
2930+ public GetMetaRegionLocationsResponse getMetaRegionLocations (RpcController rpcController ,
2931+ GetMetaRegionLocationsRequest request ) throws ServiceException {
2932+ GetMetaRegionLocationsResponse .Builder response = GetMetaRegionLocationsResponse .newBuilder ();
2933+ Optional <List <HRegionLocation >> metaLocations =
2934+ master .getMetaRegionLocationCache ().getMetaRegionLocations ();
2935+ metaLocations .ifPresent (hRegionLocations -> hRegionLocations .forEach (
2936+ location -> response .addMetaLocations (ProtobufUtil .toRegionLocation (location ))));
2937+ return response .build ();
2938+ }
28962939}
0 commit comments