Hadoop HDFS copyMergeFromLocal
2015-10-24 22:49
435 查看
在谈到HDFS优化中,其中HDFS擅长处理大文件,而对于小文件常用的优化策略有压缩合并。在此列举小文件合并工具类供参考。
在HDFS文件上传时,可以设置过滤条件,使小文件自动合并。
/** * Get all the files in the directories that match the source file pattern * and merge and sort them to only one file on HDFS is kept. * * Also adds a string between the files (useful for adding \n * to a text file) * @param srcf: a file pattern specifying source files * @param dstf: a destination local file/directory * @param endline: if an end of line character is added to a text file * @exception: IOException */ public static void copyMergeFromLocal(String srcf, Path dst, boolean endline) throws IOException { Configuration conf = new Configuration(); Path srcPath = new Path(srcf); FileSystem dstFs = srcPath.getFileSystem(conf); FileSystem srcFs = FileSystem.getLocal(conf); Path[] srcs = FileUtil.stat2Paths(srcFs.globStatus(srcPath), srcPath); for (Path src : srcs) { FileUtil.copyMerge(srcFs, src, dstFs, dst, false, conf, endline ? "\n" : null); } } void copyMergeFromLocal(String srcf, Path dst) throws IOException { copyMergeFromLocal(srcf, dst, false); }
在HDFS文件上传时,可以设置过滤条件,使小文件自动合并。
相关文章推荐
- 软件级负载均衡器(LVS/HAProxy/Nginx)的特点简介和对比
- 【鸟哥的linux私房菜-学习笔记】文件与目录管理
- linux下的tar解压命令参数详解
- 使用powershell部署WSP包
- Shell实现(三)读取命令的实现
- linux基本命令三の管理进程
- 记一次tomcat web应用压测调优
- Linux基本命令一の安装及管理应用程序
- Windows和Linux通信
- CentOS 6.5 (CentOS 7)安装过程记录
- LinuxCNC+EtherCAT(6)之LinuxCNC使用,翻译
- LinuxCNC+EtherCAT(5)之关于LinuxCNC和EMC
- Linux管道基础知识
- webshell、XSS
- hadoop 读书笔记(4)
- 做网站记录
- Linux top
- 十大好用的Linux实用工具推荐
- shell实现(二) 打印提示信息的实现
- 安全参透之旅第1章 KALI LINUX安装