hadoop分布式缓存文件?

pwuypxnk  于 2021-05-30  发布在  Hadoop
关注(0)|答案(1)|浏览(508)

我正在迁移到yarn的过程中,distributedcache的行为似乎发生了变化。
以前,我会将一些文件添加到缓存中,如下所示:

  1. for (String file : args) {
  2. Path path = new Path(cache_root, file);
  3. URI uri = new URI(path.toUri().toString());
  4. DistributedCache.addCacheFile(uri, conf);
  5. }

路径通常看起来像

  1. /some/path/to/my/file.txt

它预先存在于hdfs上,基本上会作为

  1. /$DISTRO_CACHE/some/path/to/my/file.txt

我可以在我当前的工作目录中符号链接到它并与一起使用 DistributedCache.getLocalCacheFiles() 使用yarn时,此文件似乎在缓存中结束为:

  1. /$DISTRO_CACHE/file.txt

也就是说,文件uri的“路径”部分被删除,只剩下文件名。
with如何处理以相同文件名结尾的不同绝对路径?考虑以下情况:

  1. DistributedCache.addCacheFile("some/path/to/file.txt", conf);
  2. DistributedCache.addCacheFile("some/other/path/to/file.txt", conf);

可以说有人可以使用碎片:

  1. DistributedCache.addCacheFile("some/path/to/file.txt#file1", conf);
  2. DistributedCache.addCacheFile("some/other/path/to/file.txt#file2", conf);

但这似乎不必要地难以管理。想象一下,如果这些是命令行参数,您需要管理这两个文件名,尽管不同的绝对路径肯定会在distributedcache中发生冲突,因此需要将这些文件名重新Map到片段并将其传播到程序的其余部分?
有没有更简单的方法来处理这个问题?

zwghvu4y

zwghvu4y1#

尝试将文件添加到作业中
这很可能是您实际如何配置作业,然后在Map器中访问它们。
当你准备工作的时候,你会做一些

  1. job.addCacheFile(new Path("cache/file1.txt").toUri());
  2. job.addCacheFile(new Path("cache/file2.txt").toUri());

然后在Map器代码中,url将存储在一个数组中,可以这样访问。

  1. URI file1Uri = context.getCacheFiles()[0];
  2. URI file2Uri = context.getCacheFiles()[1];

希望这能帮到你。

相关问题