gpt4 book ai didi

hadoop - 文件未正确放入分布式缓存

转载 作者:可可西里 更新时间:2023-11-01 14:20:31 27 4
gpt4 key购买 nike

我正在使用以下代码将文件添加到分布式缓存:

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

然后我将文件读入映射器:

protected void setup(Context context)throws IOException,InterruptedException{
Configuration conf = context.getConfiguration();

URI[] cacheFile = DistributedCache.getCacheFiles(conf);
FSDataInputStream in = FileSystem.get(conf).open(new Path(cacheFile[0].getPath()));
BufferedReader joinReader = new BufferedReader(new InputStreamReader(in));

String line;
try {
while ((line = joinReader.readLine()) != null) {
s = line.toString().split("\t");
do stuff to s
} finally {
joinReader.close();
}

问题是我只读了一行,它不是我放入缓存的文件。相反,它是:cm9vdA==,或 base64 中的 root。

有没有其他人遇到过这个问题,或者看看我是如何错误地使用分布式缓存的?我正在使用完全分布式的 Hadoop 0.20.2。

最佳答案

作业配置中的常见错误:

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

创建 Job 对象后,您需要拉回 Configuration 对象,因为 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);

您还应该检查分布式缓存中的文件数量,可能不止一个,并且您正在打开一个随机文件,它为您提供了您所看到的值。

我建议您使用符号链接(symbolic link),这将使文件在本地工作目录中可用,并具有已知名称:

DistributedCache.createSymlink(conf2);
DistributedCache.addCacheFile(new URI("hdfs://server:port/FilePath/part-r-00000#myfile"), conf2);

// then in your mapper setup:
BufferedReader joinReader = new BufferedReader(new FileInputStream("myfile"));

关于hadoop - 文件未正确放入分布式缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12708947/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com