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

use*_*071 4 hadoop distributed-cache

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

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);
Run Code Online (Sandbox Code Playgroud)

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

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();
                }
Run Code Online (Sandbox Code Playgroud)

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

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

Chr*_*ite 14

工作配置中常见的错误:

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);
Run Code Online (Sandbox Code Playgroud)

创建Job对象后,需要在Job复制它时拉回Configuration对象,并在创建作业后在conf2中配置值对job iteself没有影响.试试这个:

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);
Run Code Online (Sandbox Code Playgroud)

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

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

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"));
Run Code Online (Sandbox Code Playgroud)