This post demonstrates how to migrate nearly any amount of data from an on-premises Apache Hadoop environment to Amazon Simple Storage Service (Amazon S3) by using S3DistCp on Amazon EMR with AWS Direct Connect.
To transfer resources from a target EMR cluster, the traditional Hadoop DistCp must be run on the source cluster to move data from one cluster to another, which invokes a MapReduce job on the source cluster and can consume a lot of cluster resources (depending on the data volume). To avoid this problem and minimize the load on the source cluster, you can use S3DistCp with Direct Connect to migrate terabytes of data from an on-premises Hadoop environment to Amazon S3. This process runs the job on the target EMR cluster, minimizing the burden on the source cluster.
This post provides instructions for using S3DistCp for migrating data to the AWS Cloud. Apache DistCp is an open source tool that you can use to copy large amounts of data. S3DistCp is similar to DistCp, but optimized to work with AWS, particularly Amazon S3. When compared to Hadoop DistCp, S3DistCp is more scalable, with higher throughput and efficient for parallel copying of large numbers of objects across s3 buckets and across AWS accounts.
Solution overview The architecture for this solution includes the following components:
The following architecture diagram shows how you can use the S3DistCp from the target EMR cluster to migrate huge volumes of data from an on-premises Hadoop environment through a private network connection, such as Direct Connect to Amazon S3.
This migration approach uses the following tools to perform the migration:
In the following sections, we discuss the steps to perform the data migration using S3DistCp.
Prerequisites Before you begin, you should have the following prerequisites:
Get the active NameNode from the source Hadoop cluster Sign in to any of the nodes on the source cluster and run the following commands on bash to get the active NameNode on the cluster.
In newer versions of Hadoop, run the following command to get the service status, which will list the active NameNode on the cluster:
[hadoop@hadoopcluster01 ~]$ hdfs haadmin -getAllServiceStatehadoopcluster01.test.amazon.local:8020 activehadoopcluster02.test.amazon.local:8020 standbyhadoopcluster03.test.amazon.local:8020 standby
On older versions of Hadoop, run the following method on bash to get the active NameNode on the cluster:
[hadoop@hadoopcluster01 ~]$ getActiveNameNode(){ nameservice=$(hdfs getconf -confKey dfs.nameservices); ns=$(hdfs getconf -confKey dfs.ha.namenodes.${nameservice}); IFS=',' read -ra ADDR <<< "$ns" activeNode='' for n in "${ADDR[@]}"; do state=$(hdfs haadmin -getServiceState $n) if [ $state = "active" ]; then echo "$state ==>$n" activeNode=$n fi done activeNodeFQDN=$(hdfs getconf -confKey dfs.namenode.rpc-address.${nameservice}.${activeNode}) echo $activeNodeFQDN;}[hadoop@hadoopcluster01 ~]$ getActiveNameNodeactive ==>namenode863hadoopcluster01.test.amazon.local:8020
Validate connectivity from the EMR cluster to the source Hadoop cluster As mentioned in the prerequisites, you should have an EMR cluster and attach a custom IAM role for Amazon EMR. Run the following command to validate the connectivity from the target EMR cluster to the source Hadoop cluster:
[hadoop@emrcluster01 ~]$ telnet hadoopcluster01.test.amazon.local 8020Trying 192.168.0.1...Connected to hadoopcluster01.test.amazon.local.Escape character is '^]'.^]
Alternatively, you can run the following command:
[hadoop@emrcluster01 ~]$ curl -v telnet://hadoopcluster01.test.amazon.local:8020* Trying 192.168.0.1:8020...* Connected to hadoopcluster01.test.amazon.local (192.168.0.1) port 8020 (#0)
Validate if the source HDFS path exists Check if the source HDFS path is valid. If the following command returns 0, indicating that it’s valid, you can proceed to the next step:
[hadoop@emrcluster01 ~]$ hdfs dfs -test -d hdfs://hadoopcluster01.test.amazon.local/user/hive/warehouse/test.db/test_table01[hadoop@emrcluster01 ~]$ echo $?0
Transfer data using S3DistCp To transfer the source HDFS folder to the target S3 bucket, use the following command:
s3-dist-cp --src hdfs://hadoopcluster01.test.amazon.local/user/hive/warehouse/test.db/test_table01 --dest s3://<BUCKET_NAME>/user/hive/warehouse/test.db/test_table01
To transfer large files in multipart chunks, use the following command to set the chuck size:
s3-dist-cp --src hdfs://hadoopcluster01.test.amazon.local/user/hive/warehouse/test.db/test_table01 --dest s3://<BUCKET_NAME>/user/hive/warehouse/test.db/test_table01 --multipartUploadChunkSize=1024
This will invoke a MapReduce job on the target EMR cluster. Depending on the volume of the data and the bandwidth speed, the job can take a few minutes up to a few hours to complete.
To get the list of running yarn applications on the cluster, run the following command:
yarn application -list
Validate the migrated data After the preceding MapReduce job completes successfully, use the following steps to validate the data copied over:
source_size=$(hdfs dfs -du -s hdfs://hadoopcluster01.test.amazon.local/user/hive/warehouse/test.db/test_table01 | awk -F' ' '{print $1}')target_size=$(aws s3 ls --summarize --recursive s3://<BUCKET_NAME>/user/hive/warehouse/test.db/test_table01 | grep "Total Size:" | awk -F' ' '{print $3}')printf "Source HDFS folder Size in bytes: $source_size"printf "Target S3 folder Size in bytes: $target_size"
If the source and target size aren’t equal, perform the cleanup step in the next section and repeat the preceding S3DistCp step.
Clean up partially copied or errored out partitions and files S3DistCp doesn’t clean up partially copied files and partitions if it fails while copying. Clean up partially copied or errored out partitions and files before you reinitiate the S3DistCp process. To clean up objects on Amazon S3, use the following AWS CLI command to perform the delete operation:
aws s3 rm s3://<BUCKET_NAME>/path/to/the/object –recursive
Best practices To avoid copy errors when using S3DistCP to copy a single file (instead of a directory) from Amazon S3 to HDFS, use Amazon EMR 5.33.0 or later, or Amazon EMR 6.3.0 or later.
Limitations The following are limitations of this approach:
Conclusion In this post, we demonstrated the power of S3DistCp to migrate huge volumes of data from a source Hadoop cluster to a target S3 bucket or HDFS on an EMR cluster. With S3DistCp, you can migrate terabytes of data without affecting the compute resources on the source cluster as compared to Hadoop DistCp.
For more information about using S3DistCp, see the following resources:
About the Author Vicky Wilson Jacob is a Senior Data Architect with AWS Professional Services Analytics Practice. Vicky specializes in Big Data, Data Engineering, Machine Learning, Data Science and Generative AI. He is passionate about technology and solving customer challenges. At AWS, he works with companies helping customers implement big data, machine learning, analytics, and generative AI solutions on cloud. Outside of work, he enjoys spending time with family, singing, and playing guitar.