java.io.IOException: Filesystem

2019-12-03  本文已影响0人  无我_a50f

问题是现在要拷贝其他目录下的文件到HDFS中(在多线程下),会出现如下的错误,
java.io.IOException: Filesystem closed
at org.apache.hadoop.hdfs.DFSClient.checkOpen(DFSClient.java:629)
at org.apache.hadoop.hdfs.DFSClient.getFileInfo(DFSClient.java:1677)
at org.apache.hadoop.hdfs.DistributedFileSystem17.doCall(DistributedFileSystem.java:1106) at org.apache.hadoop.hdfs.DistributedFileSystem17.doCall(DistributedFileSystem.java:1102)
at org.apache.hadoop.fs.FileSystemLinkResolver.resolve(FileSystemLinkResolver.java:81)
at org.apache.hadoop.hdfs.DistributedFileSystem.getFileStatus(DistributedFileSystem.java:1102)
at org.apache.hadoop.fs.FileUtil.checkDest(FileUtil.java:497)
at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:348)
at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:338)
at org.apache.hadoop.fs.FileSystem.copyFromLocalFile(FileSystem.java:2021)
at org.apache.hadoop.fs.FileSystem.copyFromLocalFile(FileSystem.java:1989)
at org.apache.hadoop.fs.FileSystem.copyFromLocalFile(FileSystem.java:1954)
at cn.com.yeexun.jnfc.utils.HdfsLearn.copyFile(HdfsLearn.java:48)
at cn.com.yeexun.jnfc.collector.Collector.collector_loop(Collector.java:482)
at cn.com.yeexun.jnfc.collector.Collector$3.exec(Collector.java:256)
at cn.com.yeexun.jnfc.utils.ServiceThread.run(ServiceThread.java:18)
解决这个问题:
1、创建文件系统实例的时候使用下面:
FileSystem fs=FileSystem.newInstance(conf);
而不是:fs = FileSystem.get(conf);
2、在线程中创建实例的时候,要注意以下顺序,否则还是会出现以上错误。
hdfs1 =new HdfsCopy();
hdfs1.copyFile(srcpath, dstpath);
hdfs2 =new HdfsCopy();
hdfs2.copyFile(srcpath, dstpath);
hdfs3 =new HdfsCopy();
hdfs3.copyFile(srcpath, dstpath);
而不是以下方式:
hdfs1 =new HdfsCopy();
hdfs2 =new HdfsCopy();
hdfs3 =new HdfsCopy();
hdfs1.copyFile(srcpath, dstpath);
hdfs2.copyFile(srcpath, dstpath);
hdfs3.copyFile(srcpath, dstpath);

————————————————
版权声明:本文为CSDN博主「qiumengkai」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qiumengkai/article/details/48682143

上一篇 下一篇

猜你喜欢

热点阅读