Migrate HBase data online
This solution combines HBase Snapshot and HBase Replication to migrate both historical and incremental data without stopping the source HBase cluster. This method ensures that no data is lost during the migration.
Solution overview
Traditional snapshot-based HBase migration only supports offline migration, which cannot meet the requirement of keeping the source cluster running. Because the source cluster remains active during the migration, the following issues may occur:
-
Incremental data loss: Write or update operations performed on the source cluster during snapshot export and restoration might not be synchronized to the destination cluster.
-
Data consistency is difficult to guarantee: Snapshots alone cannot handle the real-time incremental data that is generated during the migration.
To address these issues, you can use the following online migration approach:
-
Establish a replication relationship (peer):
-
Use HBase Replication to create a table-level replication relationship between the source and destination clusters and then temporarily disable automatic synchronization.
-
The source cluster records real-time writes and changes to the table but does not immediately synchronize them to the destination cluster.
-
-
Migrate historical data:
-
Use HBase Snapshot to export the historical data from the source cluster.
-
If the storage systems, such as HDFS or OSS-HDFS, of the source and destination clusters are interconnected, you can export the snapshot directly to the destination cluster. Otherwise, you must first export it to an intermediate path on the source cluster and then synchronize it to the destination cluster.
-
-
Synchronize incremental data: After you restore the historical data, enable automatic synchronization for the replication peer to replay the incremental data that was generated during the migration. This ensures data consistency between the source and destination clusters.
These steps allow you to fully migrate both historical and incremental data while the source cluster continues to run, which avoids data loss.
Important considerations
-
HBase version compatibility:
-
HBase 1.x: Set
hbase.replication=trueand restart both the master and standby clusters to enable replication. -
HBase 2.x: The
hbase.replicationparameter is removed by default and does not require additional configuration.
-
-
Replication configuration: HBase enables replication for each column family. To migrate specific column families, you must ensure that their replication property is correctly configured.
-
Network connectivity:
-
Use Cloud Enterprise Network (CEN), leased lines, or a VPN to ensure network connectivity between the source and destination HBase clusters.
-
Establish network connectivity between the source and destination clusters. Ensure that the following ports are accessible from the source cluster:
-
ZooKeeper service port: Port
2181on the ECS instance that hosts ZooKeeper in the destination cluster. -
HBase service ports: Ports
16010,16020, and16030on the ECS instance that hosts EMR HBase in the destination cluster.
-
-
Procedure
Step 1: Create a Peer (replication relationship)
Create a table-level replication relationship between the source and destination clusters and temporarily disable automatic synchronization. You can re-enable it after you synchronize the historical snapshot data.
-
Log on to the master node of the source cluster. For more information, see Log on to a cluster.
-
Run the following command to enter the HBase Shell.
hbase shell -
Add a peer (replication relationship).
In the HBase Shell, run the following command to add a peer for the destination cluster and specify the table to migrate.
add_peer '${peer_name}', CLUSTER_KEY => "${slave_zk}:${port}:/hbase", TABLE_CFS => { "${table_name}" => [] }Parameters:
-
${peer_name}: The name of the replication relationship. You can define this name. This topic usespeer1as an example. -
${slave_zk}: The ZooKeeper address of the destination cluster. Typically, this is a list of internal IP addresses or hostnames of multiple ZooKeeper nodes in the format{slave_zk1}:2181,{slave_zk2}:2181,{slave_zk3}:2181. -
${port}: The ZooKeeper port of the destination cluster. The default port is 2181. -
${table_name}: The name of the table to migrate. This topic usest1as an example.
-
-
Enable table-level replication.
Enable table-level replication so that writes to the specified table are synchronized to the destination cluster.
enable_table_replication 't1' -
Temporarily disable automatic synchronization.
This command pauses data replication for the specified peer. After you disable replication, the source cluster stops sending new data changes to the destination cluster, but the existing data remains unaffected.
disable_peer 'peer1'
Step 2: Create a Snapshot
In the HBase Shell of the source cluster, run the following command to create a snapshot of the table to migrate. This snapshot is used to export historical data.
snapshot '${table_name}', '${snapshot_name}'
-
Parameters:
-
${table_name}: The name of the table to migrate. This topic usest1as an example. -
${snapshot_name}: A custom snapshot name. This topic usest1-snapshotas an example.
-
-
Example:
snapshot 't1', 't1-snapshot'
Step 3: Export the Snapshot to the destination cluster
Scenario 1: Storage systems of source and destination clusters are interconnected
If the storage systems are interconnected, run the following command on the source cluster to export the snapshot directly to the destination cluster.
hbase org.apache.hadoop.hbase.snapshot.ExportSnapshot -snapshot ${snapshot_name} -copy-to ${target_rootdir_path}
-
Parameters:
-
${snapshot_name}: A custom snapshot name. This topic usest1-snapshotas an example. -
${target_rootdir_path}: The root directory path of HBase in the destination cluster. Replace this with your actual path.-
OSS-HDFS: In the console, go to the HBase service of the destination cluster and check the hbase-site.xml file for the hbase.rootdir configuration item to obtain the exact path.
-
HDFS: In the console, go to the Hadoop-Common service of the destination cluster and check the core-site.xml file for the fs.defaultFS configuration item to obtain the exact path.
-
-
-
Example:
hbase org.apache.hadoop.hbase.snapshot.ExportSnapshot -snapshot t1-snapshot -copy-to oss://xxx.cn-hangzhou.oss-dls.aliyuncs.com/hbase/c-9d34bc8fxxx
Scenario 2: Storage systems of source and destination clusters are not interconnected
If the source cluster cannot directly access the destination storage path, you must first export the snapshot to an intermediate path on the source cluster, such as HDFS or OSS, and then synchronize it to the destination cluster. This topic uses the migration of data from HDFS to OSS-HDFS as an example.
-
Export the snapshot to an intermediate path.
On the source HBase cluster, run the following command to export the snapshot to an intermediate path.
hbase org.apache.hadoop.hbase.snapshot.ExportSnapshot -snapshot ${snapshot_name} -copy-to ${src_temp_path}/${table_name}-
Parameters:
-
${snapshot_name}: A custom snapshot name. This topic usest1-snapshotas an example. -
${src_temp_path}: The intermediate path on the source cluster. For example, if the source cluster uses HDFS, you can choose an HDFS path as the intermediate path. -
${table_name}: The name of the table to migrate. This topic usest1as an example.
-
-
Example:
hbase org.apache.hadoop.hbase.snapshot.ExportSnapshot -snapshot t1-snapshot -copy-to hdfs:///tmp/hbase-snapshot/t1
-
-
Migrate data to the destination path.
Run the following command to use JindoDistCp to migrate data from the intermediate path on the source cluster to the destination cluster. For more information about JindoDistCp, see JindoDistCp usage.
-
Configure the AccessKey for OSS or OSS-HDFS in the EMR console.
In the Hadoop-Common service, on the core-site.xml tab, add the following configuration items to avoid repeated entry. For more information about how to add configuration items, see Manage configuration items.
Parameter
Description
fs.oss.accessKeyId
AccessKey ID for OSS/OSS-HDFS.
fs.oss.accessKeySecret
AccessKey secret for OSS/OSS-HDFS.
-
On the source HBase cluster, go to the directory that contains the
jindo-distcp-tool-*.jarfile.cd /opt/apps/JINDOSDK/jindosdk-current/toolsNote-
EMR cluster: JindoDistCp is deployed on EMR clusters that run EMR V5.6.0 or later, or EMR V3.40.0 or later. You can find the
jindo-distcp-tool-*.jarfile in the/opt/apps/JINDOSDK/jindosdk-current/toolsdirectory. -
Non-EMR cluster: You must download JindoSDK, which includes JindoDistCp. For more information, see Download, install, and upgrade JindoSDK.
-
-
Run the following command to migrate the snapshot to the destination HBase cluster.
hadoop jar jindo-distcp-tool-*.jar --src ${src_temp_path}/${table_name} --dest ${target_temp_path}/${table_name} --disableChecksum --parallelism 10-
Parameters:
-
${src_temp_path}: The intermediate path on the source cluster. -
${target_temp_path}: The intermediate path on the destination cluster. -
${target_bucket}: The name of the destination bucket.
-
-
Example:
hadoop jar jindo-distcp-tool-4.6.11.jar --src hdfs:///tmp/hbase-snapshot/t1 --dest oss://hbase-test.cn-hangzhou.oss-dls.aliyuncs.com/hbase/recv/t1 --disableChecksum --parallelism 10
-
-
Import the snapshot into the destination HBase cluster.
On the destination HBase cluster, run the following command to import the snapshot from the destination path into the HBase root directory.
hbase org.apache.hadoop.hbase.snapshot.ExportSnapshot -snapshot ${snapshot_name} -copy-from ${target_temp_path} -copy-to ${target_rootdir_path}-
Parameters:
-
${target_temp_path}: The temporary path on the destination cluster. -
${target_rootdir_path}: The root directory path of the destination HBase cluster.In the console, go to the HBase service of the destination cluster and check the hbase-site.xml file for the hbase.rootdir configuration item to obtain the exact path.
-
-
Example:
hbase org.apache.hadoop.hbase.snapshot.ExportSnapshot -snapshot t1-snapshot -copy-from oss://hbase-test.cn-hangzhou.oss-dls.aliyuncs.com/hbase/recv/t1 -copy-to oss://hbase-target.cn-hangzhou.oss-dls.aliyuncs.com/hbase/c-5418ce2a4xxx
-
-
-
Check the migration result.
After the migration is complete, run the following command to verify that the data in the destination path is complete.
hdfs dfs -ls ${target_rootdir_path}
Step 4: Restore historical data using the Snapshot
-
Log on to the master node of the destination cluster. For more information, see Log on to a cluster.
-
Run the following command to enter the HBase Shell.
hbase shell -
Run the following commands to restore the snapshot and enable the table on the destination cluster.
restore_snapshot '${snapshot_name}' enable '${table_name}'-
Parameters:
-
${snapshot_name}: A custom snapshot name. -
${table_name}: The name of the table to migrate.
-
-
Example:
restore_snapshot 't1-snapshot' enable 't1'
-
Step 5: Enable incremental data synchronization
In the HBase Shell of the source cluster, run the following command to enable peer synchronization.
enable_peer '${peer_name}'
Example:
enable_peer 'peer1'
Step 6: Validate data
Verify that the migrated data is complete.
-
Small data volume: Use the scan command for validation.
scan '${table_name}'Example:
scan 't1' -
Medium data volume: Use the count command for validation.
count '${table_name}' -
Large data volume: Use the get command for sampling validation.
get '${table_name}', '${rowkey}'In the code,
${rowkey}is the unique identifier for each row in the HBase table.
Step 7: Delete the Snapshot
After the validation is successful, run the following command to delete all snapshots that are related to the destination table and free up storage space.
delete_table_snapshots '${table_name}'
Example:
delete_table_snapshots 't1'
Step 8: Clean up the Peer
After the incremental data synchronization is complete, perform dual-write or cutover operations to switch all read and write requests to the destination HBase cluster. To prevent duplicate data synchronization, delete the replication relationship (peer) between the source and destination clusters after the switch is complete.
-
Migrate clients.
Switch the upstream and downstream applications that interact with the HBase cluster to the destination HBase cluster. This includes applications that read data from or write data to HBase through APIs or the command line. Perform the following steps:
-
Update the connection configuration: Modify the application configuration files or code to change the HBase connection information, such as the ZooKeeper address and port, from the source cluster to the destination cluster.
-
Validate functionality: Ensure that the application can read data from and write data to the destination cluster as expected. You must also perform the necessary functional testing and data validation.
-
Dual-run or cutover: Based on your business needs, you can choose to perform a dual-run, where you read data from and write data to both the source and destination clusters simultaneously, or perform a direct cutover to the destination cluster.
-
-
Disable automatic synchronization for the peer.
In the HBase Shell of the source cluster, disable automatic synchronization for the specified peer to immediately stop data synchronization.
disable_peer '${peer_name}'Example:
disable_peer 'peer1' -
Delete the peer.
After you disable the peer, delete it to completely remove the replication relationship between the source and destination clusters.
remove_peer '${peer_name}'Example:
remove_peer 'peer1' -
Verify that the peer was deleted.
Run the following command to list all current peers and confirm that
peer1in this example is deleted.list_peers