Kevin Pauli
Kevin Pauli

Reputation: 8885

How to list the regions in an HBase table through the shell?

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

Upvotes: 22

Views: 38360

Answers (5)

Cyanny
Cyanny

Reputation: 530

scan 'hbase:meta', {FILTER=>"PrefixFilter('tableName')", COLUMNS=>['info:regioninfo']}

Upvotes: 5

Nishant Goyal
Nishant Goyal

Reputation: 31

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.

Upvotes: 3

LearningToCode
LearningToCode

Reputation: 651

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

Upvotes: 10

Kevin Pauli
Kevin Pauli

Reputation: 8885

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.

Upvotes: 3

Maddy RS
Maddy RS

Reputation: 1031

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

Upvotes: 44

Related Questions