HBase number of regions
What's inside this article
⌄
- Determine the number of keys in each region of the HBase table in Java
- HBase number of keys
- HBase keys number
- HBase count keys
Let’s imagine that you need to know the actual distribution of keys by regions of the HBase table. There is no direct way to find it. But you can use this workaround: you need to send scan queries with region boundaries:
private AtomicLong count = new AtomicLong(0L);
private void printRegionStats() throws IOException {
List<HRegionInfo> regions = connection.getAdmin().getTableRegions(tableName);
try (Table table = connection.getTable(tableName)) {
regions.forEach(r -> {
Scan scan = new Scan();
scan.setStartRow(r.getStartKey());
scan.setStopRow(r.getEndKey());
try (ResultScanner resultScanner = table.getScanner(scan)) {
resultScanner.forEach(result -> { count.incrementAndGet() });
} catch (IOException e) {
e.printStackTrace();
}
log.error("found new region. keys count: {}", counter);
counter.set(0L);
});
}
}
This code will display line by line the number of keys in each region of the table.