Updated on 2022-09-14 GMT+08:00

Suggestions

Do Not Call the closeRegion Method of HBaseAdmin to Close a Region

HBaseAdmin provides an API to close a Region.

// You can specify hostAndPort or not.

public void closeRegion(final String regionname, final String hostAndPort)

When this method is used to close a Region, the HBase Client directly sends an RPC request to the RegionServer where the Region is located. The Master is unaware of the entire process. That is, the Master does not know even if the Region is closed. If the closeRegion method is called when the Master determines to migrate the Region based on the execution result of Balance, the Region cannot be closed or migrated. (In the current HBase version, this problem has not been resolved).

Therefore, do not call the closeRegion method of HBaseAdmin to close a Region.

Use the PutList Method to Write Data

The HTable class provides two types of APIs to write data:

  1. public void put(final Put put) throws IOException
  2. public void put(final List<Put> puts) throws IOException

The second one is recommended because it provides better performance than the first one.

Specify StartKey and EndKey for a Scan

A Scan with a specific range offers higher performance than a Scan without specific range.

Sample code:

Scan scan = new Scan();
scan.addColumn(Bytes.toBytes("familyname"),Bytes.toBytes("columnname"));
scan.setStartRow (Bytes.toBytes ("rowA")); // Assume that StartKey is rowA.
scan.setStopRow (Bytes.toBytes ("rowB")); // Assume that EndKey is rowB.
for(Result result : demoTable.getScanner(scan)) {
// process Result instance
}

Do Not Disable WAL

Write-Ahead-Log (WAL) allows data to be written in a log file before being written to the database, ensuring data security.

WAL is enabled by default. The Put class provides the following API to disable WAL:

public void setWriteToWAL(boolean write)

You are advised not to call this API to disable WAL, that is, set writeToWAL to False, because this may cause loss of data of the last 1s. The time can be specified by the hbase.regionserver.optionallogflushinterval parameter of the RegionServer and is 1s by default. However, if high data write speed is required and loss of data of the last 1s is allowed in actual application, you can disable WAL.

Set blockcache to true When Creating a Table or Scan

Set blockcache to true when you create a table or scan on an HBase client. If there are a large number of repeated records, setting this parameter to true can improve efficiency. Otherwise, set this parameter to false.

The default value is true. You are advised to retain the default setting. Do not forcibly set this parameter to false, for example,

HColumnDescriptor fieldADesc = new HColumnDescriptor("value".getBytes());

fieldADesc.setBlockCacheEnabled(false);