22

I would like to get the same information about the regions of a table that appear in the web UI (i.e. region name, region server, start/end key, locality), but through the hbase shell.

(The UI is flaky/slow, and furthermore I want to process this information as part of a script.)

After much googling, I can't find out how, and this surprises me immensely. version is 1.0.0.-cdh5.4.0

Kevin Pauli
  • 8,577
  • 15
  • 49
  • 70
  • Turns out you can't (yet). There's an open ticket https://issues.apache.org/jira/browse/HBASE-14925 to add it. – Kevin Pauli Dec 04 '15 at 14:56
  • FYI, one of the major reasons I wanted this was that the UI wouldn't always show the table regions. I found out through luck that if you do a major_compact on the table, somehow this refreshes the table metadata in a way that causes the UI to show the table regions. So at least I can get the info now. But still would be super nice to be able to use this info in a script in an easy way that didn't use screen scraping! – Kevin Pauli Dec 14 '15 at 15:32

5 Answers5

44

To get the region info about the table, you need to scan hbase:meta table.

scan 'hbase:meta',{FILTER=>"PrefixFilter('table_name')"}

This command will give details of all the regions. Row key will have region name and there will be four column qualifiers. You may need following two column qualifiers:

info:regioninfo - This qualifier contains STARTKEY and ENDKEY.

info:server - This qualifier contains region server details

Maddy RS
  • 1,031
  • 8
  • 9
  • 4
    Now there is an official command for it, check out https://issues.apache.org/jira/browse/HBASE-14925 Starting from version 1.4 – LearningToCode May 09 '17 at 01:37
10

Use the "official" list_regions shell command to list out all the regions. Note that this tool is available only starting from HBase versions 1.4 and above.

Some examples are 
        Examples:
        hbase> list_regions 'table_name'
        hbase> list_regions 'table_name', 'server_name'
        hbase> list_regions 'table_name', {SERVER_NAME => 'server_name', LOCALITY_THRESHOLD => 0.8}
        hbase> list_regions 'table_name', {SERVER_NAME => 'server_name', LOCALITY_THRESHOLD => 0.8}, ['SERVER_NAME']
        hbase> list_regions 'table_name', {}, ['SERVER_NAME', 'start_key']
        hbase> list_regions 'table_name', '', ['SERVER_NAME', 'start_key']

Details on its implementation are at: https://issues.apache.org/jira/browse/HBASE-14925

LearningToCode
  • 631
  • 1
  • 12
  • 23
5
scan 'hbase:meta', {FILTER=>"PrefixFilter('tableName')", COLUMNS=>['info:regioninfo']}
Y.H.
  • 2,687
  • 1
  • 29
  • 38
Cyanny
  • 520
  • 6
  • 9
3

Here's a response from the HBase mailing list:

status 'detailed' would show you enough information e.g.

t1,30,1449175546660.da5f3853f6e59d1ada0a8554f12885ab." 
  numberOfStores=1, numberOfStorefiles=0, 
  storefileUncompressedSizeMB=0, lastMajorCompactionTimestamp=0, 
  storefileSizeMB=0, memstoreSizeMB=0, storefileIndexSizeMB=0, 
  readRequestsCount=0, writeRequestsCount=0, rootIndexSizeKB=0, 
  totalStaticIndexSizeKB=0, totalStaticBloomSizeKB=0, totalCompactingKVs=0, 
  currentCompactedKVs=0, compactionProgressPct=NaN, completeSequenceId=-1, 
  dataLocality=0.0 

However, this returns info from all the tables, and you need to parse the regions of the table you're interested in.

Kevin Pauli
  • 8,577
  • 15
  • 49
  • 70
3

There is a tool in hbase which is used for table recovery and checking consistency, called hbase hbck. Although this will not be running inside the hbase shell, but can be used to get the list of regions.

The command hbase hbck -details <tablename> can be used to get the table details and will contain the region information required.

The output of the above-mentioned command can be parsed to obtain the region-info for the required table.