1- /**
1+ /*
22 *
33 * Licensed to the Apache Software Foundation (ASF) under one
44 * or more contributor license agreements. See the NOTICE file
1919package org .apache .hadoop .hbase .master ;
2020
2121import static org .apache .hadoop .hbase .master .MasterWalManager .META_FILTER ;
22-
2322import java .io .FileNotFoundException ;
2423import java .io .IOException ;
2524import java .net .BindException ;
3130import java .util .List ;
3231import java .util .Map ;
3332import java .util .Map .Entry ;
33+ import java .util .Optional ;
3434import java .util .Set ;
3535import java .util .stream .Collectors ;
3636import org .apache .hadoop .conf .Configuration ;
3737import org .apache .hadoop .fs .Path ;
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 ;
117118import org .apache .zookeeper .KeeperException ;
118119import org .slf4j .Logger ;
119120import org .slf4j .LoggerFactory ;
120-
121121import org .apache .hbase .thirdparty .com .google .protobuf .RpcController ;
122122import org .apache .hbase .thirdparty .com .google .protobuf .ServiceException ;
123123import org .apache .hbase .thirdparty .com .google .protobuf .UnsafeByteOperations ;
124-
125124import org .apache .hadoop .hbase .shaded .protobuf .ProtobufUtil ;
126125import org .apache .hadoop .hbase .shaded .protobuf .ResponseConverter ;
127126import org .apache .hadoop .hbase .shaded .protobuf .generated .AccessControlProtos ;
162161import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .BalanceResponse ;
163162import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .ClearDeadServersRequest ;
164163import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .ClearDeadServersResponse ;
164+ import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .ClientMetaService ;
165165import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .CreateNamespaceRequest ;
166166import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .CreateNamespaceResponse ;
167167import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .CreateTableRequest ;
186186import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .ExecProcedureResponse ;
187187import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .FixMetaRequest ;
188188import 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 ;
189193import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetClusterStatusRequest ;
190194import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetClusterStatusResponse ;
191195import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetCompletedSnapshotsRequest ;
192196import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetCompletedSnapshotsResponse ;
193197import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetLocksRequest ;
194198import 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 ;
195201import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetNamespaceDescriptorRequest ;
196202import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetNamespaceDescriptorResponse ;
197203import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetProcedureResultRequest ;
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