Prepartitioning of HBase

Keywords: HBase Java vim Zookeeper

1. Why pre-partition?

* Increase data read-write efficiency

* Load balancing to prevent data skewing

* Convenient cluster disaster relief dispatch region

* Optimize the number of Map s

2. How to pre-partition?

Each region maintains the startRow and endRowKey, and if the data added matches the rowKey range maintained by a region, the data is given to that region for maintenance.

3. How to set the pre-partition?

1. Specify pre-partitions manually

hbase(main):001:0> create 'staff','info','partition1',SPLITS => ['1000','2000','3000','4000']

When finished, as shown in Fig.

 

2. Prepartition using hexadecimal algorithm

 

hbase(main):003:0> create 'staff2','info','partition2',{NUMREGIONS => 15, SPLITALGO => 'HexStringSplit'}

When finished, as shown in Fig.

 

3. Partition rules are created in files

Create the splits.txt file as follows:

cd /export/servers/

vim splits.txt

aaaa

bbbb

cccc

dddd

Then execute:

hbase(main):004:0> create 'staff3','partition2',SPLITS_FILE => '/export/servers/splits.txt'

After success, as shown in Fig.

 

4. Create pre-partitions using the Java API

The Java code is as follows:

/**

     * HBase table creation and pre-partitioning via Java API

     */

    @Test

    public void hbaseSplit() throws IOException {

        //Get Connections

        Configuration configuration = HBaseConfiguration.create();

        configuration.set("hbase.zookeeper.quorum", "node01:2181,node02:2181,node03:2181");

        Connection connection = ConnectionFactory.createConnection(configuration);

        Admin admin = connection.getAdmin();

        //A custom algorithm that produces a series of Hash hash values stored in a two-dimensional array

        byte[][] splitKeys = {{1,2,3,4,5},{'a','b','c','d','e'}};

 

        //Implement parameter settings for our tables via HTableDescriptor, including table names, column families, and so on

        HTableDescriptor hTableDescriptor = new HTableDescriptor(TableName.valueOf("stuff4"));

        //Add Column Family

        hTableDescriptor.addFamily(new HColumnDescriptor("f1"));

        //Add Column Family

        hTableDescriptor.addFamily(new HColumnDescriptor("f2"));

        admin.createTable(hTableDescriptor,splitKeys);

        admin.close();

    }

Posted by ChrisFlynn on Tue, 30 Jul 2019 10:48:52 -0700