HBASE-24525 [branch-1] Support ZooKeeper 3.6.0+ (#1879)
Signed-off-by: Bharath Vissapragada <bharathv@apache.org>
This commit is contained in:
parent
e07aaf7fef
commit
f74d181914
|
@ -85,14 +85,26 @@ public class HQuorumPeer {
|
|||
}
|
||||
|
||||
private static void runZKServer(QuorumPeerConfig zkConfig) throws UnknownHostException, IOException {
|
||||
if (zkConfig.isDistributed()) {
|
||||
QuorumPeerMain qp = new QuorumPeerMain();
|
||||
qp.runFromConfig(zkConfig);
|
||||
} else {
|
||||
ZooKeeperServerMain zk = new ZooKeeperServerMain();
|
||||
ServerConfig serverConfig = new ServerConfig();
|
||||
serverConfig.readFrom(zkConfig);
|
||||
zk.runFromConfig(serverConfig);
|
||||
try {
|
||||
if (zkConfig.isDistributed()) {
|
||||
QuorumPeerMain qp = new QuorumPeerMain();
|
||||
qp.runFromConfig(zkConfig);
|
||||
} else {
|
||||
ZooKeeperServerMain zk = new ZooKeeperServerMain();
|
||||
ServerConfig serverConfig = new ServerConfig();
|
||||
serverConfig.readFrom(zkConfig);
|
||||
zk.runFromConfig(serverConfig);
|
||||
}
|
||||
} catch (UnknownHostException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
// The current signature proposes we throw IOException or
|
||||
// UnknownHostException. ZK 3.6 throws another type of checked
|
||||
// exception, which causes a compilation error. Therefore we catch
|
||||
// that and potentially others, and wrap it into an IOE. Adding a
|
||||
// new checked exception to the signature would cause a compilation
|
||||
// problem with 3.4.
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1811,9 +1811,10 @@ public class ZKUtil {
|
|||
*/
|
||||
public static void multiOrSequential(ZooKeeperWatcher zkw, List<ZKUtilOp> ops,
|
||||
boolean runSequentialOnMultiFailure) throws KeeperException {
|
||||
if (ops == null) return;
|
||||
if (ops == null || ops.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
boolean useMulti = zkw.getConfiguration().getBoolean(HConstants.ZOOKEEPER_USEMULTI, false);
|
||||
|
||||
if (useMulti) {
|
||||
List<Op> zkOps = new LinkedList<Op>();
|
||||
for (ZKUtilOp op : ops) {
|
||||
|
@ -1846,7 +1847,6 @@ public class ZKUtil {
|
|||
// run sequentially
|
||||
processSequentially(zkw, ops);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void processSequentially(ZooKeeperWatcher zkw, List<ZKUtilOp> ops)
|
||||
|
|
|
@ -294,7 +294,7 @@ AssignmentManager assignmentManager = master.getAssignmentManager();
|
|||
</tr>
|
||||
<tr>
|
||||
<td>ZooKeeper Client Version</td>
|
||||
<td><% org.apache.zookeeper.Version.getVersion() %>, revision=<% org.apache.zookeeper.Version.getRevision() %></td>
|
||||
<td><% org.apache.zookeeper.Version.getVersion() %></td>
|
||||
<td>ZooKeeper client version and revision</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
|
|
@ -168,7 +168,7 @@ org.apache.hadoop.hbase.zookeeper.MasterAddressTracker;
|
|||
</tr>
|
||||
<tr>
|
||||
<td>ZooKeeper Client Version</td>
|
||||
<td><% org.apache.zookeeper.Version.getVersion() %>, revision=<% org.apache.zookeeper.Version.getRevision() %></td>
|
||||
<td><% org.apache.zookeeper.Version.getVersion() %></td>
|
||||
<td>ZooKeeper client version and revision</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
|
|
@ -66,8 +66,20 @@ public class ZooKeeperMainServer {
|
|||
* @throws IOException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
void runCmdLine() throws KeeperException, IOException, InterruptedException {
|
||||
processCmd(this.cl);
|
||||
void runCmdLine() throws IOException, InterruptedException {
|
||||
try {
|
||||
processCmd(this.cl);
|
||||
} catch (IOException | InterruptedException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
// The current signature proposes we throw IOException or
|
||||
// InterruptedException. ZK 3.6 throws another type of checked
|
||||
// exception, which causes a compilation error. Therefore we catch
|
||||
// that and potentially others, and wrap it into an IOE. Adding a
|
||||
// new checked exception to the signature would cause a compilation
|
||||
// problem with 3.4.
|
||||
throw new IOException(e);
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,9 @@ package org.apache.hadoop.hbase.zookeeper;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
|
@ -111,25 +114,45 @@ public class TestHQuorumPeer {
|
|||
QuorumPeerConfig config = new QuorumPeerConfig();
|
||||
config.parseProperties(properties);
|
||||
|
||||
assertEquals(this.dataDir.toString(), config.getDataDir());
|
||||
assertEquals(this.dataDir.toString(), config.getDataDir().toString());
|
||||
assertEquals(2181, config.getClientPortAddress().getPort());
|
||||
Map<Long,QuorumServer> servers = config.getServers();
|
||||
assertEquals(3, servers.size());
|
||||
assertTrue(servers.containsKey(Long.valueOf(0)));
|
||||
QuorumServer server = servers.get(Long.valueOf(0));
|
||||
assertEquals("localhost", server.addr.getHostName());
|
||||
assertEquals("localhost", getHostName(server));
|
||||
|
||||
// Override with system property.
|
||||
System.setProperty("hbase.master.hostname", "foo.bar");
|
||||
is = new ByteArrayInputStream(s.getBytes());
|
||||
properties = ZKConfig.parseZooCfg(conf, is);
|
||||
assertEquals("foo.bar:2888:3888", properties.get("server.0"));
|
||||
|
||||
config.parseProperties(properties);
|
||||
|
||||
servers = config.getServers();
|
||||
server = servers.get(Long.valueOf(0));
|
||||
assertEquals("foo.bar", server.addr.getHostName());
|
||||
assertEquals("foo.bar", getHostName(server));
|
||||
}
|
||||
|
||||
// The reflection in this method is needed to smooth over internal differences
|
||||
// between ZK 3.4 and 3.6. The type of 'addr' in 3.4 is InetSocketAddress. In
|
||||
// 3.6 it becomes org.apache.zookeeper.server.quorum.MultipleAddresses, a set
|
||||
// of InetSocketAddress.
|
||||
private static String getHostName(QuorumServer server) throws Exception {
|
||||
String hostname;
|
||||
switch (server.addr.getClass().getName()) {
|
||||
case "org.apache.zookeeper.server.quorum.MultipleAddresses":
|
||||
// ZK 3.6 and up
|
||||
Method m = server.addr.getClass().getDeclaredMethod("getOne");
|
||||
hostname = ((InetSocketAddress)m.invoke(server.addr)).getHostName();
|
||||
break;
|
||||
default:
|
||||
// ZK <= 3.5
|
||||
Field f = server.getClass().getField("addr");
|
||||
hostname = ((InetSocketAddress)f.get(server)).getHostName();
|
||||
break;
|
||||
}
|
||||
return hostname;
|
||||
}
|
||||
|
||||
@Test public void testShouldAssignDefaultZookeeperClientPort() {
|
||||
|
|
Loading…
Reference in New Issue