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 ;
351
357
*/
352
358
@ InterfaceAudience .Private
353
359
@ 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 {
357
364
private static final Logger LOG = LoggerFactory .getLogger (MasterRpcServices .class .getName ());
358
365
private static final Logger AUDITLOG =
359
366
LoggerFactory .getLogger ("SecurityLogger." +MasterRpcServices .class .getName ());
@@ -362,7 +369,7 @@ public class MasterRpcServices extends RSRpcServices
362
369
363
370
/**
364
371
* @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.
366
373
*/
367
374
private RegionServerStartupResponse .Builder createConfigurationSubset () {
368
375
RegionServerStartupResponse .Builder resp = addConfig (
@@ -488,15 +495,17 @@ boolean synchronousBalanceSwitch(final boolean b) throws IOException {
488
495
protected List <BlockingServiceAndInterface > getServices () {
489
496
List <BlockingServiceAndInterface > bssi = new ArrayList <>(5 );
490
497
bssi .add (new BlockingServiceAndInterface (
491
- MasterService .newReflectiveBlockingService (this ),
492
- MasterService .BlockingInterface .class ));
498
+ MasterService .newReflectiveBlockingService (this ),
499
+ MasterService .BlockingInterface .class ));
493
500
bssi .add (new BlockingServiceAndInterface (
494
- RegionServerStatusService .newReflectiveBlockingService (this ),
495
- RegionServerStatusService .BlockingInterface .class ));
501
+ RegionServerStatusService .newReflectiveBlockingService (this ),
502
+ RegionServerStatusService .BlockingInterface .class ));
496
503
bssi .add (new BlockingServiceAndInterface (LockService .newReflectiveBlockingService (this ),
497
504
LockService .BlockingInterface .class ));
498
505
bssi .add (new BlockingServiceAndInterface (HbckService .newReflectiveBlockingService (this ),
499
506
HbckService .BlockingInterface .class ));
507
+ bssi .add (new BlockingServiceAndInterface (ClientMetaService .newReflectiveBlockingService (this ),
508
+ ClientMetaService .BlockingInterface .class ));
500
509
bssi .addAll (super .getServices ());
501
510
return bssi ;
502
511
}
@@ -623,7 +632,9 @@ public AssignRegionResponse assignRegion(RpcController controller,
623
632
624
633
final byte [] regionName = req .getRegion ().getValue ().toByteArray ();
625
634
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
+ }
627
638
628
639
final AssignRegionResponse arr = AssignRegionResponse .newBuilder ().build ();
629
640
if (master .cpHost != null ) {
@@ -668,7 +679,7 @@ public CreateNamespaceResponse createNamespace(RpcController controller,
668
679
669
680
@ Override
670
681
public CreateTableResponse createTable (RpcController controller , CreateTableRequest req )
671
- throws ServiceException {
682
+ throws ServiceException {
672
683
TableDescriptor tableDescriptor = ProtobufUtil .toTableDescriptor (req .getTableSchema ());
673
684
byte [][] splitKeys = ProtobufUtil .getSplitKeysArray (req );
674
685
try {
@@ -1065,7 +1076,7 @@ public GetSchemaAlterStatusResponse getSchemaAlterStatus(
1065
1076
* Get list of TableDescriptors for requested tables.
1066
1077
* @param c Unused (set to null).
1067
1078
* @param req GetTableDescriptorsRequest that contains:
1068
- * - tableNames: requested tables, or if empty, all are requested
1079
+ * - tableNames: requested tables, or if empty, all are requested.
1069
1080
* @return GetTableDescriptorsResponse
1070
1081
* @throws ServiceException
1071
1082
*/
@@ -1209,9 +1220,9 @@ public IsProcedureDoneResponse isProcedureDone(RpcController controller,
1209
1220
/**
1210
1221
* Checks if the specified snapshot is done.
1211
1222
* @return true if the snapshot is in file system ready to use,
1212
- * false if the snapshot is in the process of completing
1223
+ * false if the snapshot is in the process of completing
1213
1224
* @throws ServiceException wrapping UnknownSnapshotException if invalid snapshot, or
1214
- * a wrapped HBaseSnapshotException with progress failure reason.
1225
+ * a wrapped HBaseSnapshotException with progress failure reason.
1215
1226
*/
1216
1227
@ Override
1217
1228
public IsSnapshotDoneResponse isSnapshotDone (RpcController controller ,
@@ -1453,7 +1464,9 @@ public OfflineRegionResponse offlineRegion(RpcController controller,
1453
1464
1454
1465
final byte [] regionName = request .getRegion ().getValue ().toByteArray ();
1455
1466
final RegionInfo hri = master .getAssignmentManager ().getRegionInfo (regionName );
1456
- if (hri == null ) throw new UnknownRegionException (Bytes .toStringBinary (regionName ));
1467
+ if (hri == null ) {
1468
+ throw new UnknownRegionException (Bytes .toStringBinary (regionName ));
1469
+ }
1457
1470
1458
1471
if (master .cpHost != null ) {
1459
1472
master .cpHost .preRegionOffline (hri );
@@ -2314,8 +2327,8 @@ public RegionSpaceUseReportResponse reportRegionSpaceUse(RpcController controlle
2314
2327
report .getRegionSize (), now );
2315
2328
}
2316
2329
} else {
2317
- LOG .debug (
2318
- "Received region space usage report but HMaster is not ready to process it, skipping" );
2330
+ LOG .debug ("Received region space usage report but HMaster is not ready to process it, "
2331
+ + " skipping" );
2319
2332
}
2320
2333
return RegionSpaceUseReportResponse .newBuilder ().build ();
2321
2334
} catch (Exception e ) {
@@ -2351,8 +2364,8 @@ public GetSpaceQuotaRegionSizesResponse getSpaceQuotaRegionSizes(
2351
2364
}
2352
2365
return builder .build ();
2353
2366
} else {
2354
- LOG .debug (
2355
- "Received space quota region size report but HMaster is not ready to process it, skipping" );
2367
+ LOG .debug ("Received space quota region size report but HMaster is not ready to process it,"
2368
+ + " skipping" );
2356
2369
}
2357
2370
return builder .build ();
2358
2371
} catch (Exception e ) {
@@ -2896,4 +2909,34 @@ private boolean shouldSubmitSCP(ServerName serverName) {
2896
2909
return true ;
2897
2910
}
2898
2911
2912
+ @ Override
2913
+ public GetClusterIdResponse getClusterId (RpcController rpcController , GetClusterIdRequest request )
2914
+ throws ServiceException {
2915
+ GetClusterIdResponse .Builder resp = GetClusterIdResponse .newBuilder ();
2916
+ String clusterId = master .getClusterId ();
2917
+ if (clusterId != null ) {
2918
+ resp .setClusterId (clusterId );
2919
+ }
2920
+ return resp .build ();
2921
+ }
2922
+
2923
+ @ Override
2924
+ public GetActiveMasterResponse getActiveMaster (RpcController rpcController ,
2925
+ GetActiveMasterRequest request ) throws ServiceException {
2926
+ GetActiveMasterResponse .Builder resp = GetActiveMasterResponse .newBuilder ();
2927
+ Optional <ServerName > serverName = master .getActiveMaster ();
2928
+ serverName .ifPresent (name -> resp .setServerName (ProtobufUtil .toServerName (name )));
2929
+ return resp .build ();
2930
+ }
2931
+
2932
+ @ Override
2933
+ public GetMetaRegionLocationsResponse getMetaRegionLocations (RpcController rpcController ,
2934
+ GetMetaRegionLocationsRequest request ) throws ServiceException {
2935
+ GetMetaRegionLocationsResponse .Builder response = GetMetaRegionLocationsResponse .newBuilder ();
2936
+ Optional <List <HRegionLocation >> metaLocations =
2937
+ master .getMetaRegionLocationCache ().getMetaRegionLocations ();
2938
+ metaLocations .ifPresent (hRegionLocations -> hRegionLocations .forEach (
2939
+ location -> response .addMetaLocations (ProtobufUtil .toRegionLocation (location ))));
2940
+ return response .build ();
2941
+ }
2899
2942
}
0 commit comments