/** * Gets the starting row key for every region in the currently open table. * <p> * This is mainly useful for the MapReduce integration. * @return Array of region starting row keys * @throws IOException if a remote or network exception occurs */ default byte[][] getStartKeys() throws IOException { return getStartEndKeys().getFirst(); }
/** * Gets the ending row key for every region in the currently open table. * <p> * This is mainly useful for the MapReduce integration. * @return Array of region ending row keys * @throws IOException if a remote or network exception occurs */ default byte[][] getEndKeys() throws IOException { return getStartEndKeys().getSecond(); }
protected Pair<byte[][],byte[][]> getStartEndKeys() throws IOException { return getRegionLocator().getStartEndKeys(); }
private void doBulkLoad(LoadIncrementalHFiles loadHFiles, Table table, Deque<LoadQueueItem> queue, RegionLocator locator, int maxRetries) throws IOException { int count = 0; Pair<byte[][], byte[][]> startEndKeys; while (!queue.isEmpty()) { // need to reload split keys each iteration. startEndKeys = locator.getStartEndKeys(); if (count != 0) { LOG.warn("Error occurred while replicating HFiles, retry attempt " + count + " with " + queue.size() + " files still remaining to replicate."); } if (maxRetries != 0 && count >= maxRetries) { throw new IOException("Retry attempted " + count + " times without completing, bailing out."); } count++; // Try bulk load loadHFiles.loadHFileQueue(table, connection, queue, startEndKeys); } }
@Override protected Pair<byte[][], byte[][]> getStartEndKeys() throws IOException { if (conf.get(SPLIT_TABLE) != null) { TableName splitTableName = TableName.valueOf(conf.get(SPLIT_TABLE)); try (Connection conn = ConnectionFactory.createConnection(getConf())) { try (RegionLocator rl = conn.getRegionLocator(splitTableName)) { return rl.getStartEndKeys(); } } } return super.getStartEndKeys(); }
private void generatePartitions(Path partitionsPath) throws IOException { Connection connection = ConnectionFactory.createConnection(getConf()); Pair<byte[][], byte[][]> regionKeys = connection.getRegionLocator(TableName.valueOf(tableHash.tableName)).getStartEndKeys(); connection.close(); tableHash.selectPartitions(regionKeys); LOG.info("Writing " + tableHash.partitions.size() + " partition keys to " + partitionsPath); tableHash.writePartitionFile(getConf(), partitionsPath); }
final Pair<byte[][], byte[][]> startEndKeys = regionLocator.getStartEndKeys(); if (count != 0) { LOG.info("Split occurred while grouping HFiles, retry attempt " + +count + " with " +
@Override protected Pair<byte[][], byte[][]> getStartEndKeys(TableName tableName) throws IOException { try (RegionLocator locator = UTIL.getConnection().getRegionLocator(tableName)) { return locator.getStartEndKeys(); } }
final Pair<byte[][], byte[][]> keys = table.getRegionLocator().getStartEndKeys(); if (keys == null || keys.getFirst() == null || keys.getFirst().length == 0) { throw new IOException("Expecting at least one region.");
Mockito.when(mockedRegionLocator.getStartEndKeys()). thenReturn(new Pair<byte [][], byte[][]>(startKeys, endKeys)); Mockito.when(mockedRegionLocator.getName()).thenReturn(tableName);
@Override public RegionLocator getRegionLocator(TableName tableName) throws IOException { final Map<byte[], HRegionLocation> locationMap = new TreeMap<>(Bytes.BYTES_COMPARATOR); for (byte[] startKey : START_KEYS) { HRegionLocation hrl = new HRegionLocation( RegionInfoBuilder.newBuilder(tableName).setStartKey(startKey).build(), ServerName.valueOf("localhost", 0, 0)); locationMap.put(startKey, hrl); } RegionLocator locator = mock(RegionLocator.class); when(locator.getRegionLocation(any(byte [].class), anyBoolean())). thenAnswer(new Answer<HRegionLocation>() { @Override public HRegionLocation answer(InvocationOnMock invocationOnMock) throws Throwable { Object [] args = invocationOnMock.getArguments(); byte [] key = (byte [])args[0]; return locationMap.get(key); } }); when(locator.getStartEndKeys()). thenReturn(new Pair<byte[][], byte[][]>(START_KEYS, END_KEYS)); return locator; }
Pair<byte[][], byte[][]> tmp = null; try (RegionLocator regionLocator = connection.getRegionLocator(tableName)) { tmp = regionLocator.getStartEndKeys();
RegionSizeCalculator sizeCalculator = new RegionSizeCalculator( regionLocator, conn.getAdmin()); Pair<byte[][], byte[][]> keys = regionLocator.getStartEndKeys(); for (Scan scan : scanList) { if (keys == null || keys.getFirst() == null || keys.getFirst().length == 0) {
/** verify region boundaries obtained from HTable.getStartEndKeys() */ void verifyRegionsUsingHTable() throws IOException { Table table = null; try { //HTable.getStartEndKeys() table = connection.getTable(tableName); try(RegionLocator rl = connection.getRegionLocator(tableName)) { Pair<byte[][], byte[][]> keys = rl.getStartEndKeys(); verifyStartEndKeys(keys); Set<RegionInfo> regions = new TreeSet<>(RegionInfo.COMPARATOR); for (HRegionLocation loc : rl.getAllRegionLocations()) { regions.add(loc.getRegionInfo()); } verifyTableRegions(regions); } } finally { IOUtils.closeQuietly(table); } }
.getRegionLocator(tableName).getStartEndKeys(); assertEquals(2, keys.getFirst().length); byte[][] startKeys = keys.getFirst();
private static void printTableRegions(String tableName) throws IOException { // co CreateTableWithRegionsExample-1-PrintTable Helper method to print the regions of a table. System.out.println("Printing regions of table: " + tableName); TableName tn = TableName.valueOf(tableName); RegionLocator locator = connection.getRegionLocator(tn); Pair<byte[][], byte[][]> pair = locator.getStartEndKeys(); // co CreateTableWithRegionsExample-2-GetKeys Retrieve the start and end keys from the newly created table. for (int n = 0; n < pair.getFirst().length; n++) { byte[] sk = pair.getFirst()[n]; byte[] ek = pair.getSecond()[n]; System.out.println("[" + (n + 1) + "]" + " start key: " + (sk.length == 8 ? Bytes.toLong(sk) : Bytes.toStringBinary(sk)) + // co CreateTableWithRegionsExample-3-Print Print the key, but guarding against the empty start (and end) key. ", end key: " + (ek.length == 8 ? Bytes.toLong(ek) : Bytes.toStringBinary(ek))); } locator.close(); } // ^^ CreateTableWithRegionsExample
private static void printTableRegions() throws IOException { System.out.println("Printing regions of table: " + tableName); Table table = connection.getTable(tableName); RegionLocator locator = connection.getRegionLocator(tableName); Pair<byte[][], byte[][]> pair = locator.getStartEndKeys(); for (int n = 0; n < pair.getFirst().length; n++) { byte[] sk = pair.getFirst()[n]; byte[] ek = pair.getSecond()[n]; System.out.println("[" + (n + 1) + "]" + " start key: " + (sk.length == 8 ? Bytes.toLong(sk) : Bytes.toStringBinary(sk)) + ", end key: " + (ek.length == 8 ? Bytes.toLong(ek) : Bytes.toStringBinary(ek))); } }
org.apache.hadoop.hbase.client.Connection hbaseConn = admin.getConnection(); Table indexTable = hbaseConn.getTable(TableName.valueOf(indexPhysicalTableName)); Pair<byte[][], byte[][]> startEndKeys = hbaseConn.getRegionLocator(TableName.valueOf(indexPhysicalTableName)).getStartEndKeys(); byte[][] startKeys = startEndKeys.getFirst(); byte[][] endKeys = startEndKeys.getSecond();
Pair<byte[][], byte[][]> startEndKeys = admin.getConnection().getRegionLocator(TableName.valueOf(tableName)) .getStartEndKeys(); byte[][] startKeys = startEndKeys.getFirst(); byte[][] endKeys = startEndKeys.getSecond();
Pair<byte[][], byte[][]> startEndKeys = admin.getConnection().getRegionLocator(TableName.valueOf(indexPhysicalTableName)) .getStartEndKeys(); byte[][] startKeys = startEndKeys.getFirst(); byte[][] endKeys = startEndKeys.getSecond();