All Products
Search
Document Center

Lindorm:Use Lindorm Shell to connect to LindormTable

Last Updated:Apr 22, 2024

Lindorm Shell is an HBase client tool provided by Lindorm. It allows you to use HBase API for Java to connect to LindormTable and perform operations such as table creation, data inserting, and data query. This topic describes how to download Lindorm Shell and use it to connect to LindormTable.

Prerequisites

  • Java Development Kit (JDK) V1.8 or later is installed.

  • The IP address of your client is added to the whitelist of the Lindorm instance. For more information, see Configure whitelists.

Usage notes

  • After you use Lindorm Shell to connect to LindormTable, you can perform only simple DDL operations, data reading operations, and data writing operations. For more information, see Limits.

  • Do not use the HBase API to access wide tables created by using SQL.

  • We recommend that you deploy your client in a Linux or macOS environment when you use Lindorm Shell to connect to LindormTable.

    If you deploy your client in a Windows environment, an error may be returned because of library missing. In this case, you must add the corresponding library file to your operating system.

Procedure

  1. Download Lindorm Shell.

    1. Log on to the Lindorm console. In the upper-left corner of the page, select the region where your Lindorm instance is deployed. On the Instances page, find the instance and click the instance ID.

    2. In the left-side navigation pane, click Database Connections. On the page that appears, click the Wide Table Engine tab.

    3. Click HBase Compatibility Address, and then click Download Lindorm Shell to download the package of Lindorm Shell.

  2. Run the following command to decompress the downloaded package of Lindorm Shell to the target path. In this example, the package is decompressed to the alihbase-2.0.18 path.

    tar zxvf hbaseue-shell.tar.gz
  3. Configure connection parameters.

    1. Go to the alihbase-2.0.18/conf directory and open the hbase-site.xml file.

      vi hbase-site.xml
    2. Specify the endpoint, username, and password that you can to use to connect to LindormTable.

      <configuration>
          <property>
              <name>hbase.zookeeper.quorum</name>
              <value>ld-bp17j28j2y7pm****-proxy-lindorm-pub.lindorm.rds.aliyuncs.com:30020</value>
          </property>
          <property>
              <name>hbase.client.username</name>
              <value>testuser</value>
          </property>
          <property>
              <name>hbase.client.password</name>
              <value>password</value>
          </property>
      </configuration>

      You can configure the following connection parameters in the configuration file:

      • hbase.zookeeper.quorum: Replace this parameter with the LindormTable endpoint that is displayed after Access by Using HBase Java API on the Wide Table Engine tab of the Lindorm console.

        • If Lindorm Shell is deployed on an Elastic Compute Service (ECS) instance that is located in the same VPC as your Lindorm instance, replace this parameter with the VPC endpoint of LindormTable.

        • If Lindorm Shell is deployed on a local computer or an ECS instance that is not located in the same region as your Lindorm instance, replace this parameter with the public endpoint of LindormTable.

      • hbase.client.username and hbase.client.password: Replace the two parameters individually with the username and password that you use to connect to LindormTable. If you forget the password, you can change the password in the cluster management system of LindormTable. For more information, see Change the password of a user.

  4. Use Lindorm Shell to connect to LindormTable.

    Go to the alihbase-2.0.18/bin path and then run the following command:

    ./hbase shell

    If the following result is returned, your client is connected to LindormTable.

    Version 2.0.18, r08b8d58a9d6ce89765d5ebe2ddff425aed644c16, Mon Feb  1 12:46:39 CST 2021
    Took 0.0034 seconds
    Note

    For more information about the usage of Shell, see the Lindorm Shell reference section.

Lindorm Shell reference

Shell commands

For more information about the usage of Shell commands, see The Apache HBase Shell.

DDL commands

  • create: creates a table.

  • list: lists all table in Lindorm.

  • disable: disables a table.

  • is_disabled: checks whether a table is disabled.

  • enable: enables a table.

  • is_enabled: checks whether a table is enabled.

  • describe: describes the details of a specific table, including the attributes and schema of the table.

  • alter: alters the schema of a table.

  • exists: checks whether a table exists.

  • drop: deletes a table.

DML commands

  • put: updates the value in a specific column.

  • get: obtains the values in a specific row or column.

  • delete: deletes the value in a specific column.

  • deleteall: deletes all columns in a row.

  • scan: scans and returns data in a table.

  • count: counts and returns the number of columns in a table.

  • truncate_preserve: clear all data in a table. This operation is implemented by disabling and deleting the table and then creating a new table with the same regions as the original table.

Enter and exit Lindorm Shell

  • Enter Lindorm Shell.

    bin/hbase shell
  • Exit Lindorm Shell.

    quit

Examples

Create a table and insert data into the table

  1. Creates a table. You must specify the names of the table and column family.

    create 'Table name', 'Column family name'

    Example:

    // Create a table named test with a column family named cf.
    create 'test', 'cf'
  2. Insert data to the table.

    put 'Table name', 'Rowkey', 'Column family name:Column name', 'Value'

    Example:

    put 'test', 'row1', 'cf:a', 'value1'
    put 'test', 'row2', 'cf:b', 'value2'
    put 'test', 'row3', 'cf:c', 'value3'
    Note

    In the preceding commands, test is the name of the table, row1 is the row key of the table, cf:a is the column family name and column name, and value1 is the value of the column.

Query data

  • Query the information about all tables. You can use regular expressions to filter the table that you want to query.

    list
    list 'abc.*'
    list 'test'
  • Query data in the specified table.

    The scan command can be used to access data in HBase tables. It can also be used to flexibly query all data in a table or data within a specified range. The query speed of this command is slightly slower than the get command. You can execute the following command to query data in the test table:

    scan 'Table name'

    Example:

    scan 'test'

    The following result is returned:

    ROW                                      COLUMN+CELL
     row1                                    column=cf:a, timestamp=1421762485768, value=value1
     row2                                    column=cf:b, timestamp=1421762491785, value=value2
     row3                                    column=cf:c, timestamp=1421762496210, value=value3
    3 row(s) in 0.0230 seconds
  • Query a specific row of data in a table.

    get 'Table name', 'Rowkey' 

    Example:

    get 'test', 'row1' 

    The following result is returned:

    COLUMN CELL
     cf:a timestamp=1421762485768, value=value1
    1 row(s) in 0.0350 seconds

Enable and disable a table

You can enable or disable a specific table. Before you delete or modify the settings of a table, you must run the disable command to disable the table first. After you delete or modify the settings, you can run the enable command to enable this table.

disable 'Table name'
enable 'Table name'

Delete a table

Delete a specific table.

drop 'Table name'

Reference settings

Common settings

  • Configure the interval at which the major compaction operation is performed. The unit of the interval is millisecond. We recommend that you do not configure the interval unless you have specific requirements.

    You can run the following command to set the interval at which the major compaction operation is performed to seven days:

    alter 'Table name', {NAME => 'Column family name', CONFIGURATION => {'hbase.hregion.majorcompaction' => 16800000}}
    Note

    The default interval is calculated by using the following formula: Math.Min(TTL,1728000000ms). If no TTL is specified for the table, the default interval is 1728000000ms, which is equal to 20 days.

  • Configure an encryption algorithm for the column family of the specified table.

    alter 'Table name', NAME => 'Column family name', COMPRESSION => 'ZSTD'
  • Configure the block encoding type of the column family of the specified table.

    You can run the following command to set the block encoding type of the column family of the test table to DATA_BLOCK_ENCODING:

    alter 'Table name', NAME => 'Column family name', DATA_BLOCK_ENCODING => 'DIFF'
  • Configure a TTL for the column family of the specified table. The unit of the TTL is second. You can run the following command to set the TTL of the column family to 2592000s, which is equal to 30 days:

    alter 'Table name', NAME => 'Column family name', TTL => 2592000

    If you want to permanently retain data, you can set TTL to FOREVER. Example:

    alter 'Table name' , {NAME => 'Column family name', TTL => 'FOREVER'}
  • Configure pre-partitioning for an HBase table.

    create'Table name',{NAME => 'Column family name',COMPRESSION => 'snappy' }, { NUMREGIONS => 50, SPLITALGO => 'HexStringSplit' }

    Parameters

    Parameter

    Description

    NAME

    The column family name of the HBase table.

    COMPRESSION

    The algorithm used to compress data in the HBase table. This parameter does not have a default value. Valid values:

    • ZSTD (Recommended)

    • SNAPPY

    • LZ4

    NUMREGIONS

    The number of partitions. When you calculate the number of partitions, you can assume that 6 to 8 GB of storage is used by each partition. You can configure multiple partitions based on the size of your instance.

    SPLITALGO

    The algorithm used to initialize regions. The following algorithms are supported:

    • HexStringSplit: This algorithm is applicable to tables in which row keys are prefixed with a hexadecimal string.

    • DecimalStringSplit: This algorithm is applicable to tables in which row keys are prefixed with a decimal string.

    • UniformSplit: This algorithm is applicable to tables in which the prefix of row keys is random.

After you modify the parameter settings, you can run the following command to check whether the modification takes effect:

describe 'Table name'