租约问题
问题描述:当往hdfs里面写入文件时,输出流如果异常关闭,会导致hdfs认为当前client仍然持有当前租约,当下一次获取同一文件的输出流时,会认为当前client在重复创建file,会报类似错误:because current leaseholder is trying to recreate file 或者: because this file lease is currently owned by DFSClient_NONMAPREDUCE_-502044238_1 on ...
解决方案:当流关闭异常时,流本身已经不能再使用了,需要强制恢复,代码如下:
try {
out.close();
} catch (IOException e) {
try {
((DistributedFileSystem)fileSystem).recoverLease(new Path(path));
} catch (IOException ex) {
//todo
}
}
网友评论