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
To get the region info about the table, you need to scan hbase:meta table. This command will give details of all the regions. Row key will have region name and there will be four column qualifiers.
To access the HBase shell, you have to navigate to the HBase home folder. You can start the HBase interactive shell using “hbase shell” command as shown below. If you have successfully installed HBase in your system, then it gives you the HBase shell prompt as shown below.
list is the command that is used to list all the tables in HBase. Given below is the syntax of the list command. When you type this command and execute in HBase prompt, it will display the list of all the tables in HBase as shown below. Here you can observe a table named emp.
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.
So let’s explore HBase Shell Commands. What is HBase Shell? In order to communicate with HBase, we use HBase Shell. Basically, to store the data, HBase uses the Hadoop File System, it has a master server as well as region servers and here the data storage will be in the form of regions (tables).
We use this command to know whether an HBase table is disabled or not. “Is_enabled” command helps to know whether an HBase table is enabled or not. We use this command to list all tables in hbase. Moreover, to filter the output, optional regular expression parameter could be used.
The only difference between these two is Java API use java code to connect with HBase and shell mode use shell commands to connect with HBase. HBase uses Hadoop files as storage system to store the large amounts of data. Hbase consists of Master Servers and Regions Servers The data that is going to store in HBase will be in the form of regions.
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
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
scan 'hbase:meta', {FILTER=>"PrefixFilter('tableName')", COLUMNS=>['info:regioninfo']}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With