Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

hbase

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

like image 945
Kevin Pauli Avatar asked Dec 03 '15 20:12

Kevin Pauli


People also ask

How do I know my HBase region?

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.

How do I run a HBase command from the shell?

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.

What is the command is used to list of tables available in HBase?

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.

How to get the region of a table in HBase?

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.

What are the HBase shell commands?

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).

How to know whether an HBase table is disabled or not?

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.

What is the difference between HBase and Hadoop shell mode?

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.


3 Answers

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

like image 54
Maddy RS Avatar answered Oct 20 '22 14:10

Maddy RS


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

like image 10
LearningToCode Avatar answered Oct 20 '22 13:10

LearningToCode


scan 'hbase:meta', {FILTER=>"PrefixFilter('tableName')", COLUMNS=>['info:regioninfo']}
like image 5
Cyanny Avatar answered Oct 20 '22 12:10

Cyanny