18
18
package org .apache .hadoop .hbase .master ;
19
19
20
20
import static org .apache .hadoop .hbase .master .MasterWalManager .META_FILTER ;
21
-
22
21
import java .io .FileNotFoundException ;
23
22
import java .io .IOException ;
24
23
import java .net .BindException ;
30
29
import java .util .List ;
31
30
import java .util .Map ;
32
31
import java .util .Map .Entry ;
32
+ import java .util .Optional ;
33
33
import java .util .Set ;
34
34
import java .util .stream .Collectors ;
35
35
import org .apache .hadoop .conf .Configuration ;
36
36
import org .apache .hadoop .fs .Path ;
37
37
import org .apache .hadoop .hbase .ClusterMetricsBuilder ;
38
38
import org .apache .hadoop .hbase .DoNotRetryIOException ;
39
39
import org .apache .hadoop .hbase .HConstants ;
40
+ import org .apache .hadoop .hbase .HRegionLocation ;
40
41
import org .apache .hadoop .hbase .MetaTableAccessor ;
41
42
import org .apache .hadoop .hbase .NamespaceDescriptor ;
42
43
import org .apache .hadoop .hbase .Server ;
116
117
import org .apache .zookeeper .KeeperException ;
117
118
import org .slf4j .Logger ;
118
119
import org .slf4j .LoggerFactory ;
119
-
120
120
import org .apache .hbase .thirdparty .com .google .protobuf .RpcController ;
121
121
import org .apache .hbase .thirdparty .com .google .protobuf .ServiceException ;
122
122
import org .apache .hbase .thirdparty .com .google .protobuf .UnsafeByteOperations ;
123
-
124
123
import org .apache .hadoop .hbase .shaded .protobuf .ProtobufUtil ;
125
124
import org .apache .hadoop .hbase .shaded .protobuf .ResponseConverter ;
126
125
import org .apache .hadoop .hbase .shaded .protobuf .generated .AccessControlProtos ;
161
160
import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .BalanceResponse ;
162
161
import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .ClearDeadServersRequest ;
163
162
import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .ClearDeadServersResponse ;
163
+ import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .ClientMetaService ;
164
164
import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .CreateNamespaceRequest ;
165
165
import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .CreateNamespaceResponse ;
166
166
import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .CreateTableRequest ;
185
185
import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .ExecProcedureResponse ;
186
186
import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .FixMetaRequest ;
187
187
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 ;
188
192
import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetClusterStatusRequest ;
189
193
import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetClusterStatusResponse ;
190
194
import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetCompletedSnapshotsRequest ;
191
195
import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetCompletedSnapshotsResponse ;
192
196
import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetLocksRequest ;
193
197
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 ;
194
200
import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetNamespaceDescriptorRequest ;
195
201
import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetNamespaceDescriptorResponse ;
196
202
import org .apache .hadoop .hbase .shaded .protobuf .generated .MasterProtos .GetProcedureResultRequest ;
349
355
*/
350
356
@ InterfaceAudience .Private
351
357
@ 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 {
355
362
private static final Logger LOG = LoggerFactory .getLogger (MasterRpcServices .class .getName ());
356
363
private static final Logger AUDITLOG =
357
364
LoggerFactory .getLogger ("SecurityLogger." +MasterRpcServices .class .getName ());
@@ -360,7 +367,7 @@ public class MasterRpcServices extends RSRpcServices
360
367
361
368
/**
362
369
* @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.
364
371
*/
365
372
private RegionServerStartupResponse .Builder createConfigurationSubset () {
366
373
RegionServerStartupResponse .Builder resp = addConfig (
@@ -486,15 +493,17 @@ boolean synchronousBalanceSwitch(final boolean b) throws IOException {
486
493
protected List <BlockingServiceAndInterface > getServices () {
487
494
List <BlockingServiceAndInterface > bssi = new ArrayList <>(5 );
488
495
bssi .add (new BlockingServiceAndInterface (
489
- MasterService .newReflectiveBlockingService (this ),
490
- MasterService .BlockingInterface .class ));
496
+ MasterService .newReflectiveBlockingService (this ),
497
+ MasterService .BlockingInterface .class ));
491
498
bssi .add (new BlockingServiceAndInterface (
492
- RegionServerStatusService .newReflectiveBlockingService (this ),
493
- RegionServerStatusService .BlockingInterface .class ));
499
+ RegionServerStatusService .newReflectiveBlockingService (this ),
500
+ RegionServerStatusService .BlockingInterface .class ));
494
501
bssi .add (new BlockingServiceAndInterface (LockService .newReflectiveBlockingService (this ),
495
502
LockService .BlockingInterface .class ));
496
503
bssi .add (new BlockingServiceAndInterface (HbckService .newReflectiveBlockingService (this ),
497
504
HbckService .BlockingInterface .class ));
505
+ bssi .add (new BlockingServiceAndInterface (ClientMetaService .newReflectiveBlockingService (this ),
506
+ ClientMetaService .BlockingInterface .class ));
498
507
bssi .addAll (super .getServices ());
499
508
return bssi ;
500
509
}
@@ -621,7 +630,9 @@ public AssignRegionResponse assignRegion(RpcController controller,
621
630
622
631
final byte [] regionName = req .getRegion ().getValue ().toByteArray ();
623
632
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
+ }
625
636
626
637
final AssignRegionResponse arr = AssignRegionResponse .newBuilder ().build ();
627
638
if (master .cpHost != null ) {
@@ -666,7 +677,7 @@ public CreateNamespaceResponse createNamespace(RpcController controller,
666
677
667
678
@ Override
668
679
public CreateTableResponse createTable (RpcController controller , CreateTableRequest req )
669
- throws ServiceException {
680
+ throws ServiceException {
670
681
TableDescriptor tableDescriptor = ProtobufUtil .toTableDescriptor (req .getTableSchema ());
671
682
byte [][] splitKeys = ProtobufUtil .getSplitKeysArray (req );
672
683
try {
@@ -1063,7 +1074,7 @@ public GetSchemaAlterStatusResponse getSchemaAlterStatus(
1063
1074
* Get list of TableDescriptors for requested tables.
1064
1075
* @param c Unused (set to null).
1065
1076
* @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.
1067
1078
* @return GetTableDescriptorsResponse
1068
1079
* @throws ServiceException
1069
1080
*/
@@ -1207,9 +1218,9 @@ public IsProcedureDoneResponse isProcedureDone(RpcController controller,
1207
1218
/**
1208
1219
* Checks if the specified snapshot is done.
1209
1220
* @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
1211
1222
* @throws ServiceException wrapping UnknownSnapshotException if invalid snapshot, or
1212
- * a wrapped HBaseSnapshotException with progress failure reason.
1223
+ * a wrapped HBaseSnapshotException with progress failure reason.
1213
1224
*/
1214
1225
@ Override
1215
1226
public IsSnapshotDoneResponse isSnapshotDone (RpcController controller ,
@@ -1451,7 +1462,9 @@ public OfflineRegionResponse offlineRegion(RpcController controller,
1451
1462
1452
1463
final byte [] regionName = request .getRegion ().getValue ().toByteArray ();
1453
1464
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
+ }
1455
1468
1456
1469
if (master .cpHost != null ) {
1457
1470
master .cpHost .preRegionOffline (hri );
@@ -2298,8 +2311,8 @@ public RegionSpaceUseReportResponse reportRegionSpaceUse(RpcController controlle
2298
2311
report .getRegionSize (), now );
2299
2312
}
2300
2313
} 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" );
2303
2316
}
2304
2317
return RegionSpaceUseReportResponse .newBuilder ().build ();
2305
2318
} catch (Exception e ) {
@@ -2335,8 +2348,8 @@ public GetSpaceQuotaRegionSizesResponse getSpaceQuotaRegionSizes(
2335
2348
}
2336
2349
return builder .build ();
2337
2350
} 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" );
2340
2353
}
2341
2354
return builder .build ();
2342
2355
} catch (Exception e ) {
@@ -2880,4 +2893,34 @@ private boolean shouldSubmitSCP(ServerName serverName) {
2880
2893
return true ;
2881
2894
}
2882
2895
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
+ }
2883
2926
}
0 commit comments