A method, similar to #discoverRegion that parses the meta row but returns a region location object safe for use by users. @param meta_row The row to parse. May be empty but cannot be null @return A RegionLocation object with info about the region. @throws BrokenMetaException if the r
(final ArrayList<KeyValue> meta_row)
| 2568 | * @throws TableNotFoundException if the row was empty |
| 2569 | */ |
| 2570 | private RegionLocation toRegionLocation(final ArrayList<KeyValue> meta_row) { |
| 2571 | // TODO - there's a fair bit of duplication here with the discoverRegion() |
| 2572 | // code. Try cleaning it up. |
| 2573 | if (meta_row.isEmpty()) { |
| 2574 | throw new TableNotFoundException(); |
| 2575 | } |
| 2576 | String host = null; |
| 2577 | int port = -1; |
| 2578 | RegionInfo region = null; |
| 2579 | byte[] start_key = null; |
| 2580 | |
| 2581 | for (final KeyValue kv : meta_row) { |
| 2582 | final byte[] qualifier = kv.qualifier(); |
| 2583 | if (Arrays.equals(REGIONINFO, qualifier)) { |
| 2584 | final byte[][] tmp = new byte[1][]; // Yes, this is ugly. |
| 2585 | region = RegionInfo.fromKeyValue(kv, tmp); |
| 2586 | start_key = tmp[0]; |
| 2587 | } else if (Arrays.equals(SERVER, qualifier) |
| 2588 | && kv.value() != EMPTY_ARRAY) { // Empty during NSRE. |
| 2589 | final byte[] hostport = kv.value(); |
| 2590 | int colon = hostport.length - 1; |
| 2591 | for (/**/; colon > 0 /* Can't be at the beginning */; colon--) { |
| 2592 | if (hostport[colon] == ':') { |
| 2593 | break; |
| 2594 | } |
| 2595 | } |
| 2596 | if (colon == 0) { |
| 2597 | throw BrokenMetaException.badKV(region, "an `info:server' cell" |
| 2598 | + " doesn't contain `:' to separate the `host:port'" |
| 2599 | + Bytes.pretty(hostport), kv); |
| 2600 | } |
| 2601 | host = getIP(new String(hostport, 0, colon)); |
| 2602 | try { |
| 2603 | port = parsePortNumber(new String(hostport, colon + 1, |
| 2604 | hostport.length - colon - 1)); |
| 2605 | } catch (NumberFormatException e) { |
| 2606 | throw BrokenMetaException.badKV(region, "an `info:server' cell" |
| 2607 | + " contains an invalid port: " + e.getMessage() + " in " |
| 2608 | + Bytes.pretty(hostport), kv); |
| 2609 | } |
| 2610 | } |
| 2611 | } |
| 2612 | if (start_key == null) { |
| 2613 | throw new BrokenMetaException(null, "It didn't contain any" |
| 2614 | + " `info:regioninfo' cell: " + meta_row); |
| 2615 | } |
| 2616 | |
| 2617 | return new RegionLocation(region, start_key, host, port); |
| 2618 | } |
| 2619 | |
| 2620 | /** |
| 2621 | * Searches the meta table for all of the regions associated with the given |
no test coverage detected