java.io.ioexception: file exists_java.io.IOException: Filesystem closed

问题是现在要拷贝其他目录下的文件到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.DistributedFileSystem

math?formula=17.doCall(DistributedFileSystem.java%3A1106)%20at%20org.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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值