Moving Data in/out of Hadoop Filesystem

Hadoop has a number of built-in mechanisms that can facilitate ingress and egress operations, to name a few:

  • Embedded NameNode HTTP server
  • WebHDFS and Hadoop interfaces
  • Hbase built-in API, be specifically the org.apache.hadoop.hbase.mapreduce.TableInputFormat and org.apache.hadoop.hbase.mapreduce.TableOutputFormat
  • Hadoop fs utility
  • Oozie workflow can also be leveraged to move data in/out of HDFS periodically
  • Log collector such as Flume, scribe, Chukwa...
  • Sqoop to import/export data from/to HDFS and relational databases

The first three are low-level utilities while the rest are high-level. These low-level mechanisms  don't provide complete systems to manage the entire ingress and egress process while the hig-level ones do. For ingress here I mean move data into HDFS from external filesystem, database, hbase etc.; for egress, I mean move data from external system into Hadoop HDFS.

 

But in this blog post, what I most interested in is a third-party script which could be used to move data in/out of HDFS from external filesystem. It's called hdfs-file-splurper which is hosted on GitHub. It's distributed under Apache license, so you can get a copy of it source code via this link.

 

With HDFS file slurper open source project, you can copy files of any format in/out of HDFS, but with log collector such as Flume, Chukwa or Scribe, you can only copy text file format. The HDFS file slurper was developed by Alex Holmes, who is also the author of Hadoop in Practice. It's an awesome book by the way. Here is brief demonstration of this useful project.

 

  • Case 1,  you want to move files in any format from external filesystem to HDFS, say, from the localhost directory /tmp/slurper/in to the HDFS directory /incoming/:
    shell$ cat conf/examples/basic.conf
    DATASOURCE_NAME = test
    SRC_DIR = file:/tmp/slurper/in
    WORK_DIR = file:/tmp/slurper/work
    COMPLETE_DIR = file:/tmp/slurper/complete
    ERROR_DIR = file:/tmp/slurper/error
    DEST_STAGING_DIR = hdfs:/incoming/stage
    DEST_DIR = hdfs:/incoming
     Run the Slurper in foreground mode in a console:
    shell$ bin/slurper.sh \
      --config-file /path/to/slurper/conf/examples/basic.conf
     In another console create an empty file and watch the Slurper do its stuff:
    shell$ echo "blocks of text" > /tmp/slurper/in/test.txt
     
  • Case 2, you want to move files of any format from HDFS to local filesystem.
    shell$ cat conf/exmaples/basic.conf
    SRC_DIR=hdfs:/tmp/slurper/in
    WORK_DIR=hdfs:/tmp/slurper/work
    COMPLETE_DIR=hdfs:/tmp/slurper/complete
    ERROR_DIR=hdfs:/tmp/slurper/error
    DEST_STAGING_DIR=file:/tmp/slurper/stage
    DEST_DIR=file:/tmp/slurper/dest
     Run Hadoop job to write output into the source directory, then see the Slurper do its job.

Important features of HDFS file slurper:

  • After a successful file copy you can either remove the source file, or have it moved into another directory.
  • Destination files can be compressed as part of the write codec with any compression codec which extends org.apache.hadoop.io.compress.CompressionCodec.
  • Capability to write "done" file after completion of copy
  • Verify destination file post-copy with CRC32 checksum comparison with source
  • Ignores hidden files (filenames that start with ".")
  • Customizable destination via a script which can be called for every source file. Or alternatively let the utility know a single destination directory
  • Customizable pre-processing of file prior to transfer via script and all files are copied into that location.
  • A daemon mode which is compatible with inittab respawn
  • Multi-threaded data transfer

For more information of this project, please visit its homepage on GitHub and get a copy of its source code.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值