Get all Regions of HBase avoiding Zookeeper client reconnection

Viewed 35

for project requirement I need to extract HBase metadata for all regions. Precisely for each region I need this fields:

  • Schema name
  • Table name
  • Encode name
  • Start key
  • End key

So I came up with this solution:

List<HTableDescriptor> hTableDescriptors = Arrays.asList(admin.listTables());
        for (HTableDescriptor hTableDescriptor : hTableDescriptors) {
            TableName name = hTableDescriptor.getTableName();
            List<HRegionInfo> tableRegions = admin.getTableRegions(name);
            LOG.info("Found {} regions",tableRegions.size());
            for (HRegionInfo region : tableRegions) {
                RegionDetailInfo detailInfo = new RegionDetailInfo();
                detailInfo.setSchemaName(name.getNamespaceAsString());
                detailInfo.setTableName(name.getNameAsString());
                detailInfo.setEncodeName(region.getEncodedName());
            detailInfo.setStartKey(Bytes.toString(region.getStartKey()));
                    detailInfo.setEndKey(Bytes.toString(region.getEndKey()));
/* other stuff */
                }
            }

The problem here is that the statement: admin.getTableRegions(name); need to establish a zookeeper connection for every table. So reading metadata is very very slow.

Is there any other way to accomplish the same task?

0 Answers
Related