HBASE-8501 The hbase zkcli will connection failure the first and the second ip from ZooKeeperMainServerArg return connection string

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1498784 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2013-07-02 05:30:25 +00:00
parent dfc29dcabf
commit 69b91b70ec
4 changed files with 20 additions and 18 deletions

View File

@ -108,6 +108,7 @@ public class RecoverableZooKeeper {
public RecoverableZooKeeper(String quorumServers, int sessionTimeout, public RecoverableZooKeeper(String quorumServers, int sessionTimeout,
Watcher watcher, int maxRetries, int retryIntervalMillis, String identifier) Watcher watcher, int maxRetries, int retryIntervalMillis, String identifier)
throws IOException { throws IOException {
// TODO: Add support for zk 'chroot'; we don't add it to the quorumServers String as we should.
this.zk = new ZooKeeper(quorumServers, sessionTimeout, watcher); this.zk = new ZooKeeper(quorumServers, sessionTimeout, watcher);
this.retryCounterFactory = this.retryCounterFactory =
new RetryCounterFactory(maxRetries, retryIntervalMillis); new RetryCounterFactory(maxRetries, retryIntervalMillis);

View File

@ -76,13 +76,17 @@ possible configurations would overwhelm and obscure the important.
<property> <property>
<name>hbase.zookeeper.quorum</name> <name>hbase.zookeeper.quorum</name>
<value>localhost</value> <value>localhost</value>
<description>Comma separated list of servers in the ZooKeeper Quorum. <description>Comma separated list of servers in the ZooKeeper ensemble
(This config. should have been named hbase.zookeeper.ensemble).
For example, "host1.mydomain.com,host2.mydomain.com,host3.mydomain.com". For example, "host1.mydomain.com,host2.mydomain.com,host3.mydomain.com".
By default this is set to localhost for local and pseudo-distributed modes By default this is set to localhost for local and pseudo-distributed modes
of operation. For a fully-distributed setup, this should be set to a full of operation. For a fully-distributed setup, this should be set to a full
list of ZooKeeper quorum servers. If HBASE_MANAGES_ZK is set in hbase-env.sh list of ZooKeeper ensemble servers. If HBASE_MANAGES_ZK is set in hbase-env.sh
this is the list of servers which hbase will start/stop ZooKeeper on as this is the list of servers which hbase will start/stop ZooKeeper on as
part of cluster start/stop. part of cluster start/stop. Client-side, we will take this list of
ensemble members and put it together with the hbase.zookeeper.clientPort
config. and pass it into zookeeper constructor as the connectString
parameter.
</description> </description>
</property> </property>
<!--The above are the important configurations for getting hbase up <!--The above are the important configurations for getting hbase up

View File

@ -38,7 +38,6 @@ public class ZooKeeperMainServer {
// HConstants.ZOOKEEPER_QUORUM from the HBaseConfiguration because the // HConstants.ZOOKEEPER_QUORUM from the HBaseConfiguration because the
// user may be using a zoo.cfg file. // user may be using a zoo.cfg file.
Properties zkProps = ZKConfig.makeZKProps(c); Properties zkProps = ZKConfig.makeZKProps(c);
String host = null;
String clientPort = null; String clientPort = null;
List<String> hosts = new ArrayList<String>(); List<String> hosts = new ArrayList<String>();
for (Entry<Object, Object> entry: zkProps.entrySet()) { for (Entry<Object, Object> entry: zkProps.entrySet()) {
@ -51,15 +50,15 @@ public class ZooKeeperMainServer {
clientPort = value; clientPort = value;
} }
} }
if (hosts.isEmpty() || clientPort == null) if (hosts.isEmpty() || clientPort == null) return null;
return null; StringBuilder host = new StringBuilder();
for (int i = 0; i < hosts.size(); i++) { for (int i = 0; i < hosts.size(); i++) {
if (i > 0) if (i > 0) host.append("," + hosts.get(i));
host += "," + hosts.get(i); else host.append(hosts.get(i));
else host.append(":");
host = hosts.get(i); host.append(clientPort);
} }
return host != null ? host + ":" + clientPort : null; return host.toString();
} }
/** /**

View File

@ -32,15 +32,13 @@ public class TestZooKeeperMainServer {
@Test public void test() { @Test public void test() {
Configuration c = HBaseConfiguration.create(); Configuration c = HBaseConfiguration.create();
assertEquals("localhost:" + c.get(HConstants.ZOOKEEPER_CLIENT_PORT), assertEquals("localhost:" + c.get(HConstants.ZOOKEEPER_CLIENT_PORT), parser.parse(c));
parser.parse(c));
final String port = "1234"; final String port = "1234";
c.set(HConstants.ZOOKEEPER_CLIENT_PORT, port); c.set(HConstants.ZOOKEEPER_CLIENT_PORT, port);
c.set("hbase.zookeeper.quorum", "example.com"); c.set("hbase.zookeeper.quorum", "example.com");
assertEquals("example.com:" + port, parser.parse(c)); assertEquals("example.com:" + port, parser.parse(c));
c.set("hbase.zookeeper.quorum", "example1.com,example2.com,example3.com"); c.set("hbase.zookeeper.quorum", "example1.com,example2.com,example3.com");
assertTrue(port, String ensemble = parser.parse(c);
parser.parse(c).matches("(example[1-3]\\.com,){2}example[1-3]\\.com:" + port)); assertTrue(port, ensemble.matches("(example[1-3]\\.com:1234,){2}example[1-3]\\.com:" + port));
} }
} }