| 4330 | private byte found_meta; // HBase 0.95 and up |
| 4331 | |
| 4332 | public void processResult(final int rc, final String path, |
| 4333 | final Object ctx, final byte[] data, |
| 4334 | final Stat stat) { |
| 4335 | final boolean is_root; // True if ROOT znode, false if META znode. |
| 4336 | if (path.endsWith("/root-region-server")) { |
| 4337 | is_root = true; |
| 4338 | } else if (path.endsWith("/meta-region-server")) { |
| 4339 | is_root = false; |
| 4340 | } else { |
| 4341 | LOG.error("WTF? We got a callback from ZooKeeper for a znode we did" |
| 4342 | + " not expect: " + path + " / stat: " + stat + " / data: " |
| 4343 | + Bytes.pretty(data)); |
| 4344 | retryGetRootRegionLater(); |
| 4345 | return; |
| 4346 | } |
| 4347 | |
| 4348 | if (rc == Code.NONODE.intValue()) { |
| 4349 | final boolean both_znode_failed; |
| 4350 | if (is_root) { |
| 4351 | found_root = NOTFOUND; |
| 4352 | both_znode_failed = found_meta == NOTFOUND; |
| 4353 | } else { // META (HBase 0.95 and up) |
| 4354 | found_meta = NOTFOUND; |
| 4355 | both_znode_failed = found_root == NOTFOUND; |
| 4356 | } |
| 4357 | if (both_znode_failed) { |
| 4358 | LOG.error("The znode for the -ROOT- region doesn't exist!"); |
| 4359 | retryGetRootRegionLater(); |
| 4360 | } |
| 4361 | return; |
| 4362 | } else if (rc != Code.OK.intValue()) { |
| 4363 | LOG.error("Looks like our ZK session expired or is broken, rc=" |
| 4364 | + rc + ": " + Code.get(rc)); |
| 4365 | disconnectZK(); |
| 4366 | connectZK(); |
| 4367 | return; |
| 4368 | } |
| 4369 | if (data == null || data.length == 0 || data.length > Short.MAX_VALUE) { |
| 4370 | LOG.error("The location of the -ROOT- region in ZooKeeper is " |
| 4371 | + (data == null || data.length == 0 ? "empty" |
| 4372 | : "too large (" + data.length + " bytes!)")); |
| 4373 | retryGetRootRegionLater(); |
| 4374 | return; // TODO(tsuna): Add a watch to wait until the file changes. |
| 4375 | } |
| 4376 | |
| 4377 | final RegionClient client; |
| 4378 | if (is_root) { |
| 4379 | found_root = FOUND; |
| 4380 | client = handleRootZnode(data); |
| 4381 | } else { // META (HBase 0.95 and up) |
| 4382 | found_meta = FOUND; |
| 4383 | client = handleMetaZnode(data); |
| 4384 | } |
| 4385 | |
| 4386 | if (client == null) { // We failed to get a client. |
| 4387 | retryGetRootRegionLater(); // So retry later. |
| 4388 | return; |
| 4389 | } |