ZBLOG

tools.DistCp: Exception encountered java.io.IOException: URI: har://ns/user/lbl_pro1261_role3/archives/gkgz/clean/router/20250410.har is an invalid Har URI since '-' not found. Expecting har://-/.

这个错误表明你在使用 distcp 操作 HAR (Hadoop Archive) 文件时,URI 格式不符合 Hadoop HAR 协议的要求


错误原因

HAR URI 的规范格式是:

har://<scheme>-<host>/<path>
  • <scheme>: HDFS 的访问协议(如 hdfs)。
  • <host>: NameNode 的主机名或地址(如 namenode:8020)。
  • <path>: HAR 文件在 HDFS 中的路径。

你的 URI (har://ns/user/lbl_pro1261_role3/archives/gkgz/clean/router/20250410.har) 缺少 scheme-host 部分,导致 Hadoop 无法正确解析。


解决方案

方法一:补全正确的 HAR URI

假设你的集群:

  • Scheme: hdfs
  • NameNode Host: namenode:8020

修正后的命令:

hadoop distcp har://hdfs-namenode:8020/user/lbl_pro1261_role3/archives/gkgz/clean/router/20250410.har /target/output/path/

方法二:直接使用默认 HDFS Scheme

如果 HAR 存储在默认的 HDFS Namespace,可以省略 <host>

hadoop distcp har:///-user/lbl_pro1261_role3/archives/gkgz/clean/router/20250410.har /target/output/path/

注意:这里用 / 代替 <scheme>-<host>,表示使用默认配置。


验证 HAR URI

先确认 HAR 文件是否能正常列出:

hadoop fs -ls har://hdfs-namenode:8020/user/lbl_pro1261_role3/archives/gkgz/clean/router/20250410.har/

如果成功返回文件列表,说明 URI 格式正确。


常见问题排查

  1. 权限不足
    确保执行用户有权限访问源 HAR 和目标目录:

    hadoop fs -ls /user/lbl_pro1261_role3/archives/gkgz/clean/router/
    hadoop fs -mkdir -p /target/output/path
    hadoop fs -chmod -R +w /target/output/path
    
  2. HAR 文件损坏
    检查 HAR 是否完整:

    hadoop fs -ls /user/lbl_pro1261_role3/archives/gkgz/clean/router/20250410.har/_index
    hadoop fs -ls /user/lbl_pro1261_role3/archives/gkgz/clean/router/20250410.har/_masterindex
    

    如果这两个索引文件缺失,说明 HAR 创建失败。


其他替代方案

如果仍报错,可以尝试通过编程方式提取(Java):

Configuration conf = new Configuration();
FileSystem srcFs = new Path("har://hdfs-namenode:8020/user/lbl_pro1261_role3/archives/gkgz...").getFileSystem(conf);
FileSystem dstFs = new Path("/target/output/path").getFileSystem(conf);

FileUtil.copy(srcFs, new Path("har://..."), dstFs, new Path("/target/output/path"), false, conf);

请根据实际集群配置调整参数!


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=23721

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?