Connects to ZooKeeper. @throws NonRecoverableException if something from which we can't recover happened -- e.g. us being unable to resolve the hostname of any of the zookeeper servers.
()
| 4244 | * of any of the zookeeper servers. |
| 4245 | */ |
| 4246 | private void connectZK() { |
| 4247 | try { |
| 4248 | // Session establishment is asynchronous, so this won't block. |
| 4249 | synchronized (this) { |
| 4250 | if (zk != null) { // Already connected. |
| 4251 | return; |
| 4252 | } |
| 4253 | zk = new ZooKeeper(quorum_spec, |
| 4254 | config.getInt("hbase.zookeeper.session.timeout"), this); |
| 4255 | } |
| 4256 | } catch (UnknownHostException e) { |
| 4257 | // No need to retry, we usually cannot recover from this. |
| 4258 | throw new NonRecoverableException("Cannot connect to ZooKeeper," |
| 4259 | + " is the quorum specification valid? " + quorum_spec, e); |
| 4260 | } catch (IOException e) { |
| 4261 | LOG.error("Failed to connect to ZooKeeper", e); |
| 4262 | // XXX don't retry recursively, create a timer with an exponential |
| 4263 | // backoff and schedule the reconnection attempt for later. |
| 4264 | connectZK(); |
| 4265 | } |
| 4266 | } |
| 4267 | |
| 4268 | /** |
| 4269 | * Disconnects from ZooKeeper. |
no test coverage detected