Skip to content

Commit 0b5fdaa

Browse files
committed
HBASE-23647: Make MasterRegistry the default impl.
1 parent 62da419 commit 0b5fdaa

58 files changed

Lines changed: 556 additions & 173 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionRegistryFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ private ConnectionRegistryFactory() {
3636
*/
3737
static ConnectionRegistry getRegistry(Configuration conf) {
3838
Class<? extends ConnectionRegistry> clazz = conf.getClass(
39-
CLIENT_CONNECTION_REGISTRY_IMPL_CONF_KEY, ZKConnectionRegistry.class,
39+
CLIENT_CONNECTION_REGISTRY_IMPL_CONF_KEY, MasterRegistry.class,
4040
ConnectionRegistry.class);
4141
return ReflectionUtils.newInstance(clazz, conf);
4242
}

hbase-client/src/main/java/org/apache/hadoop/hbase/client/MasterRegistry.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public class MasterRegistry implements ConnectionRegistry {
9090
} else {
9191
finalConf = conf;
9292
}
93+
finalConf.set(MASTER_ADDRS_KEY, conf.get(MASTER_ADDRS_KEY, MASTER_ADDRS_DEFAULT));
9394
rpcTimeoutMs = (int) Math.min(Integer.MAX_VALUE, conf.getLong(HConstants.HBASE_RPC_TIMEOUT_KEY,
9495
HConstants.DEFAULT_HBASE_RPC_TIMEOUT));
9596
masterServers = new HashSet<>();
@@ -146,12 +147,13 @@ private <T, R> RpcCallback<T> getRpcCallBack(CompletableFuture<R> future,
146147
if (rpcResult == null) {
147148
future.completeExceptionally(
148149
new MasterRegistryFetchException(masterServers, hrc.getFailed()));
150+
return;
149151
}
150152
if (!isValidResp.test(rpcResult)) {
151153
// Rpc returned ok, but result was malformed.
152154
future.completeExceptionally(new IOException(
153155
String.format("Invalid result for request %s. Will be retried", debug)));
154-
156+
return;
155157
}
156158
future.complete(transformResult.apply(rpcResult));
157159
};

hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationPeerConfigUtil.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,6 @@ public static Configuration getPeerClusterConfiguration(Configuration conf,
606606
compound.addStringMap(peerConfig.getConfiguration());
607607
return compound;
608608
}
609-
610609
return otherConf;
611610
}
612611
}

hbase-client/src/main/java/org/apache/hadoop/hbase/security/SecurityInfo.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public class SecurityInfo {
4949
new SecurityInfo(SecurityConstants.MASTER_KRB_PRINCIPAL, Kind.HBASE_AUTH_TOKEN));
5050
infos.put(MasterProtos.HbckService.getDescriptor().getName(),
5151
new SecurityInfo(SecurityConstants.MASTER_KRB_PRINCIPAL, Kind.HBASE_AUTH_TOKEN));
52+
infos.put(MasterProtos.ClientMetaService.getDescriptor().getName(),
53+
new SecurityInfo(SecurityConstants.MASTER_KRB_PRINCIPAL, Kind.HBASE_AUTH_TOKEN));
5254
// NOTE: IF ADDING A NEW SERVICE, BE SURE TO UPDATE HBasePolicyProvider ALSO ELSE
5355
// new Service will not be found when all is Kerberized!!!!
5456
}

hbase-common/src/main/java/org/apache/hadoop/hbase/HBaseConfiguration.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,19 @@ public static Configuration createClusterConf(Configuration baseConf, String clu
268268
* used to communicate with distant clusters
269269
* @param conf configuration object to configure
270270
* @param key string that contains the 3 required configuratins
271-
* @throws IOException
272271
*/
273272
private static void applyClusterKeyToConf(Configuration conf, String key)
274-
throws IOException{
273+
throws IOException {
275274
ZKConfig.ZKClusterKey zkClusterKey = ZKConfig.transformClusterKey(key);
276275
conf.set(HConstants.ZOOKEEPER_QUORUM, zkClusterKey.getQuorumString());
277276
conf.setInt(HConstants.ZOOKEEPER_CLIENT_PORT, zkClusterKey.getClientPort());
278277
conf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, zkClusterKey.getZnodeParent());
278+
// Without the right registry, the above configs are useless. Also, we don't use setClass()
279+
// here because the ConnectionRegistry* classes are not resolvable from this module.
280+
// This will be broken if ZkConnectionRegistry class gets renamed or moved. Is there a better
281+
// way?
282+
conf.set(HConstants.CLIENT_CONNECTION_REGISTRY_IMPL_CONF_KEY,
283+
HConstants.ZK_CONNECTION_REGISTRY_CLASS);
279284
}
280285

281286
/**

hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ public enum OperationStatusCode {
183183

184184
public static final String MASTER_ADDRS_DEFAULT = "localhost:" + DEFAULT_MASTER_PORT;
185185

186+
/** Full class name of the Zookeeper based connection registry implementation */
187+
public static final String ZK_CONNECTION_REGISTRY_CLASS =
188+
"org.apache.hadoop.hbase.client.ZKConnectionRegistry";
189+
186190
/** Configuration to enable hedged reads on master registry **/
187191
public static final String MASTER_REGISTRY_ENABLE_HEDGED_READS_KEY =
188192
"hbase.client.master_registry.enable_hedged_reads";

hbase-server/src/main/java/org/apache/hadoop/hbase/LocalHBaseCluster.java

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public LocalHBaseCluster(final Configuration conf)
9191
*/
9292
public LocalHBaseCluster(final Configuration conf, final int noRegionServers)
9393
throws IOException {
94-
this(conf, 1, noRegionServers, getMasterImplementation(conf),
94+
this(conf, 1, 0, noRegionServers, getMasterImplementation(conf),
9595
getRegionServerImplementation(conf));
9696
}
9797

@@ -106,7 +106,7 @@ public LocalHBaseCluster(final Configuration conf, final int noRegionServers)
106106
public LocalHBaseCluster(final Configuration conf, final int noMasters,
107107
final int noRegionServers)
108108
throws IOException {
109-
this(conf, noMasters, noRegionServers, getMasterImplementation(conf),
109+
this(conf, noMasters, 0, noRegionServers, getMasterImplementation(conf),
110110
getRegionServerImplementation(conf));
111111
}
112112

@@ -122,6 +122,12 @@ private static Class<? extends HMaster> getMasterImplementation(final Configurat
122122
HMaster.class);
123123
}
124124

125+
public LocalHBaseCluster(final Configuration conf, final int noMasters, final int noRegionServers,
126+
final Class<? extends HMaster> masterClass,
127+
final Class<? extends HRegionServer> regionServerClass) throws IOException {
128+
this(conf, noMasters, 0, noRegionServers, masterClass, regionServerClass);
129+
}
130+
125131
/**
126132
* Constructor.
127133
* @param conf Configuration to use. Post construction has the master's
@@ -134,9 +140,9 @@ private static Class<? extends HMaster> getMasterImplementation(final Configurat
134140
*/
135141
@SuppressWarnings("unchecked")
136142
public LocalHBaseCluster(final Configuration conf, final int noMasters,
137-
final int noRegionServers, final Class<? extends HMaster> masterClass,
138-
final Class<? extends HRegionServer> regionServerClass)
139-
throws IOException {
143+
final int noAlwaysStandByMasters, final int noRegionServers,
144+
final Class<? extends HMaster> masterClass,
145+
final Class<? extends HRegionServer> regionServerClass) throws IOException {
140146
this.conf = conf;
141147

142148
// When active, if a port selection is default then we switch to random
@@ -170,24 +176,22 @@ public LocalHBaseCluster(final Configuration conf, final int noMasters,
170176
this.masterClass = (Class<? extends HMaster>)
171177
conf.getClass(HConstants.MASTER_IMPL, masterClass);
172178
// Start the HMasters.
173-
for (int i = 0; i < noMasters; i++) {
179+
int i;
180+
for (i = 0; i < noMasters; i++) {
174181
addMaster(new Configuration(conf), i);
175182
}
176-
177-
// Populate the master address host ports in the config. This is needed if a master based
178-
// registry is configured for client metadata services (HBASE-18095)
179-
List<String> masterHostPorts = new ArrayList<>();
180-
getMasters().forEach(masterThread ->
181-
masterHostPorts.add(masterThread.getMaster().getServerName().getAddress().toString()));
182-
conf.set(HConstants.MASTER_ADDRS_KEY, String.join(",", masterHostPorts));
183-
183+
for (int j = 0; j < noAlwaysStandByMasters; j++) {
184+
Configuration c = new Configuration(conf);
185+
c.set(HConstants.MASTER_IMPL, "org.apache.hadoop.hbase.master.AlwaysStandByHMaster");
186+
addMaster(c, i + j);
187+
}
184188
// Start the HRegionServers.
185189
this.regionServerClass =
186190
(Class<? extends HRegionServer>)conf.getClass(HConstants.REGION_SERVER_IMPL,
187191
regionServerClass);
188192

189-
for (int i = 0; i < noRegionServers; i++) {
190-
addRegionServer(new Configuration(conf), i);
193+
for (int j = 0; j < noRegionServers; j++) {
194+
addRegionServer(new Configuration(conf), j);
191195
}
192196
}
193197

@@ -233,8 +237,13 @@ public JVMClusterUtil.MasterThread addMaster(Configuration c, final int index)
233237
// its Connection instance rather than share (see HBASE_INSTANCES down in
234238
// the guts of ConnectionManager.
235239
JVMClusterUtil.MasterThread mt = JVMClusterUtil.createMasterThread(c,
236-
(Class<? extends HMaster>) conf.getClass(HConstants.MASTER_IMPL, this.masterClass), index);
240+
(Class<? extends HMaster>) c.getClass(HConstants.MASTER_IMPL, this.masterClass), index);
237241
this.masterThreads.add(mt);
242+
// Refresh the master address config.
243+
List<String> masterHostPorts = new ArrayList<>();
244+
getMasters().forEach(masterThread ->
245+
masterHostPorts.add(masterThread.getMaster().getServerName().getAddress().toString()));
246+
conf.set(HConstants.MASTER_ADDRS_KEY, String.join(",", masterHostPorts));
238247
return mt;
239248
}
240249

hbase-server/src/main/java/org/apache/hadoop/hbase/master/ActiveMasterManager.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ public class ActiveMasterManager extends ZKListener {
5656
final AtomicBoolean clusterHasActiveMaster = new AtomicBoolean(false);
5757
final AtomicBoolean clusterShutDown = new AtomicBoolean(false);
5858

59-
// This server's information.
60-
private final ServerName sn;
61-
private int infoPort;
62-
private final Server master;
59+
// This server's information. Package-private for child implementations.
60+
int infoPort;
61+
final ServerName sn;
62+
final Server master;
6363

6464
// Active master's server name. Invalidated anytime active master changes (based on ZK
6565
// notifications) and lazily fetched on-demand.
6666
// ServerName is immutable, so we don't need heavy synchronization around it.
67-
private volatile ServerName activeMasterServerName;
67+
volatile ServerName activeMasterServerName;
6868

6969
/**
7070
* @param watcher ZK watcher

hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ public HMaster(final Configuration conf) throws IOException {
575575
// Some unit tests don't need a cluster, so no zookeeper at all
576576
if (!conf.getBoolean("hbase.testing.nocluster", false)) {
577577
this.metaRegionLocationCache = new MetaRegionLocationCache(this.zooKeeper);
578-
this.activeMasterManager = new ActiveMasterManager(zooKeeper, this.serverName, this);
578+
this.activeMasterManager = createActiveMasterManager(zooKeeper, serverName, this);
579579
} else {
580580
this.metaRegionLocationCache = null;
581581
this.activeMasterManager = null;
@@ -589,6 +589,15 @@ public HMaster(final Configuration conf) throws IOException {
589589
}
590590
}
591591

592+
/**
593+
* Protected to have custom implementations in tests override the default ActiveMaster
594+
* implementation.
595+
*/
596+
protected ActiveMasterManager createActiveMasterManager(
597+
ZKWatcher zk, ServerName sn, org.apache.hadoop.hbase.Server server) {
598+
return new ActiveMasterManager(zk, sn, server);
599+
}
600+
592601
@Override
593602
protected String getUseThisHostnameInstead(Configuration conf) {
594603
return conf.get(MASTER_HOSTNAME_KEY);

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,8 +789,17 @@ public boolean registerService(com.google.protobuf.Service instance) {
789789
return true;
790790
}
791791

792-
private Configuration unsetClientZookeeperQuorum() {
792+
private Configuration cleanupConfiguration() {
793793
Configuration conf = this.conf;
794+
// We use ZKConnectionRegistry for all the internal communication, primarily for these reasons:
795+
// - Decouples RS and master life cycles. RegionServers can continue be up independent of
796+
// masters' availability.
797+
// - Configuration management for region servers (cluster internal) is much simpler when adding
798+
// new masters or removing existing masters, since only clients' config needs to be updated.
799+
// - We need to retain ZKConnectionRegistry for replication use anyway, so we just extend it for
800+
// other internal connections too.
801+
conf.set(HConstants.CLIENT_CONNECTION_REGISTRY_IMPL_CONF_KEY,
802+
HConstants.ZK_CONNECTION_REGISTRY_CLASS);
794803
if (conf.get(HConstants.CLIENT_ZOOKEEPER_QUORUM) != null) {
795804
// Use server ZK cluster for server-issued connections, so we clone
796805
// the conf and unset the client ZK related properties
@@ -824,7 +833,7 @@ public String getClusterId() {
824833
*/
825834
protected final synchronized void setupClusterConnection() throws IOException {
826835
if (asyncClusterConnection == null) {
827-
Configuration conf = unsetClientZookeeperQuorum();
836+
Configuration conf = cleanupConfiguration();
828837
InetSocketAddress localAddress = new InetSocketAddress(this.rpcServices.isa.getAddress(), 0);
829838
User user = userProvider.getCurrent();
830839
asyncClusterConnection =

0 commit comments

Comments
 (0)