【问题标题】:Distributed Cache feature in YARNYARN 中的分布式缓存功能
【发布时间】:2014-11-28 17:42:55
【问题描述】:

目前我正在使用 MAP-REDUCE YARN 框架。并在伪分布式模式下使用hadoop。 我想在这里使用“分布式缓存”功能来添加一些文件来缓存并在我的地图功能中使用它。我怎样才能做到这一点。

【问题讨论】:

    标签: hadoop


    【解决方案1】:

    如何将文件添加到分布式缓存:

    • 使用 hadoop 选项

    .

    hadoop jar <application jar> <main class> <input> <output> -files <absolute path to distributed cache file>
    
    • 使用分布式缓存 API:

    .

    job.addCacheFile(uri); 
    

    hadoop -files 选项或分布式缓存 API 将缓存文件复制到所有任务节点,并使其在执行期间可用于 mapper/reducer。

    如何访问分布式缓存:

    覆盖 Mapper/reducer 中的 setup 方法并从上下文调用 getCacheFiles。 示例代码如下:

        @Override
        protected void setup(Context context)
                throws IOException, InterruptedException {
    
            Path[] localPaths = context.getCacheFiles();
            if (localPaths.length == 0) {
                throw new FileNotFoundException("Distributed cache file not found.");
            }
            File localFile = new File(localPaths[0].toString());
            // code to process cache file
    
        }
    

    context.getCacheFiles 方法返回配置中设置的文件的 URI 数组。

    【讨论】:

    猜你喜欢
    • 2018-09-21
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-13
    相关资源
    最近更新 更多