当HDFS上文件在被写入时,在未关闭文件之前,写入操作异常终止,此文件就会保有openforwrite的状态。
常见场景:Flume在对HDFS进行文件写入操作时,HDFS服务终止,文件没及时关闭。
当MR读取该文件时,也无法使用cp或者get命令,会抛异常:Cannot obtain block length for LocatedBlock
解决方法
1、先定位到文件
hadoop fsck <path-of-the-directory> -openforwrite
2、释放租约(关闭文件)
hdfs debug recoverLease -path <path-of-the-file> -retries <retry times>
批量处理命令
hdfs fsck <path-of-the-directory> -openforwrite | grep '^\.' | grep 'OPENFORWRITE' | grep -o "/[^ ]*" | xargs -Ixarg hdfs debug recoverLease -path xarg
来源:CSDN
作者:轻风细雨
链接:https://blog.csdn.net/hxiaowang/article/details/103493115