【问题标题】:Files not stored in Distributed Cache未存储在分布式缓存中的文件
【发布时间】:2013-05-06 08:04:47
【问题描述】:

我正在使用分布式缓存。但是执行代码后缓存中没有文件。 我提到了其他类似的问题,但答案并没有解决我的问题。

请在下面找到代码:

   Configuration conf = new Configuration();
   Job job1 = new Job(conf, "distributed cache");
   Configuration conf1 = job1.getConfiguration();
   DistributedCache.addCacheFile(new Path("File").toUri(), conf1);
   System.out.println("distributed cache file "+DistributedCache.getLocalCacheFiles(conf1));

这给出了 null..

在 mapper 中给出同样的东西,因此也会给出 null。请告诉我您的建议。

谢谢

【问题讨论】:

  • 文件File是否存在于HDFS中?此外,对 getLocalCacheFiles 的最终调用将在您的驱动程序代码中不起作用(但应该适用于您的映射器 - 我假设您仅将这一行作为示例显示)。在工作跟踪器 Web UI 中找到您工作的 job.xml 并回传 mapred.cache.files 的值
  • 您可能想尝试更简单的 -files 选项。请在此处查看我的答案:stackoverflow.com/questions/16251788/…
  • 感谢 getLocalCacheFiles 在驱动程序中不起作用的信息,我只是想测试一下。然而,在地图类中,它也给出了空值。现在我刚刚发现它与 DistributedCache.getCacheFiles(conf) 配合得很好。这是否意味着我可以使用 getCacheFiles(conf) 而不是 getLocalCacheFiles(conf)?你能告诉我这两者的区别吗?

标签: hadoop distributed-cache


【解决方案1】:

尝试使用 getCacheFiles() 而不是 getLocalCacheFiles()

【讨论】:

  • 你有我的 +1,但你能解释一下两者之间的区别吗?
  • 这并不能解决问题。分布式缓存的全部意义在于创建本地副本。 getCacheFiles() 返回原始文件的 hdfs 路径。否决
【解决方案2】:

我相信这(至少部分)是由于 Chris White 写的here

创建 Job 对象后,您需要将 配置对象作为 Job 复制它,并配置值 在 conf2 中创建作业后对作业没有影响 本身。试试这个:

job = new Job(new Configuration());
Configuration conf2 = job.getConfiguration();
job.setJobName("Join with Cache");
DistributedCache.addCacheFile(new URI("hdfs://server:port/FilePath/part-r-00000"), conf2);

我猜如果它仍然不起作用,那么在某个地方还有另一个问题,但这并不意味着 Chris White 的观点是不正确的。

【讨论】:

  • 是的。我已经阅读了这些答案。我并不是说答案不正确。即使在尝试了这些事情之后,我仍然面临着这个问题。因此,请您提供帮助,以防有关 DistributedCache 遗漏任何其他要点
【解决方案3】:

分发时不要忘记本地链接名,最好使用相对路径:

URI 的形式为 hdfs://host:port/absolute-path#local-link-name

阅读时:

  • 如果你不使用分布式缓存的可能性,你应该使用HDFS的FileSystem来访问hdfs://host:port/absolute-path
  • 如果您使用分布式缓存,那么您必须使用标准 Java 文件实用程序来访问 local-link-name

【讨论】:

    【解决方案4】:

    缓存文件需要在 Hadoop 文件系统中。你可以这样做: void copyFileToHDFS(JobConf jobConf, String from, String to){

        try {
            FileSystem aFS = FileSystem.get(jobConf);
            aFS.copyFromLocalFile(false, true, new Path(
                    from), new Path(to));
        } catch (IOException e) {
            throw new RuntimeException(e);
        } 
    }
    

    复制文件后,您可以将它们添加到缓存中,如下所示:

        void fillCache(JobConf jobConf){
            Job job;
            copyFileToHDFS(jobConf, fromLocation, toLocation);
            job = Job.getInstance(jobConf);
            job.addCacheFile(new URI(toLocation));
            JobConf newJobConf = new JobConf(job.getConfiguration());
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-26
      相关资源
      最近更新 更多