希望你能帮助我。我在使用hadoop map-reduce时遇到了一个令人费解的问题。我在hadoop1.0.3版本的map-reduce上成功地使用了"-files“选项。但是,当我使用"-archives“选项时,它会复制文件,但不会解压缩它们。我遗漏了什么?文档上写着"Archives (zip, tar and tgz/tar.gz files) are un-archived at the slave nodes",但这不是我看到的。
我已经创建了3个文件-一个文本文件"alice.txt",一个压缩文件"bob.zip“(包含b1.txt和bdir/b2.txt)和一个tar文件"claire.tar”(包含c1.txt和cdir/c2.txt)。然后我通过以下方式调用hadoop作业
hadoop jar myJar myClass -files ./etc/alice.txt -archives ./etc/bob.zip,./etc/claire.tar <input_path> <output_path>这些文件确实存在并且格式良好:
% ls -l etc/alice.txt etc/bob.zip etc/claire.tar
-rw-rw-r-- 1 hadoop hadoop 6 Aug 20 18:44 etc/alice.txt
-rw-rw-r-- 1 hadoop hadoop 282 Aug 20 18:44 etc/bob.zip
-rw-rw-r-- 1 hadoop hadoop 10240 Aug 20 18:44 etc/claire.tar
% tar tf etc/claire.tar
c1.txt
cdir/c2.txt然后,我对存在问题的文件进行映射器测试,如下所示,其中'lineNumber‘是传递到映射器的键:
String key = Long.toString(lineNumber.get());
String [] files = {
"alice.txt",
"bob.zip",
"claire.tar",
"bdir",
"cdir",
"b1.txt",
"b2.txt",
"bdir/b2.txt",
"c1.txt",
"c2.txt",
"cdir/c2.txt"
};
String fName = files[ (int) (lineNumber.get() % files.length)];
String val = codeFile(fName);
output.collect(new Text(key), new Text(val)); 支持例程'codeFile‘是:
private String codeFile(String fName) {
Vector<String> clauses = new Vector<String>();
clauses.add(fName);
File f = new File(fName);
if (!f.exists()) {
clauses.add("nonexistent");
} else {
if (f.canRead()) clauses.add("readable");
if (f.canWrite()) clauses.add("writable");
if (f.canExecute()) clauses.add("executable");
if (f.isDirectory()) clauses.add("dir");
if (f.isFile()) clauses.add("file");
}
return Joiner.on(',').join(clauses);
}使用Guava 'Joiner‘类。映射器的输出值如下所示:
alice.txt,readable,writable,executable,file
bob.zip,readable,writable,executable,dir
claire.tar,readable,writable,executable,dir
bdir,nonexistent
b1.txt,nonexistent
b2.txt,nonexistent
bdir/b2.txt,nonexistent
cdir,nonexistent
c1.txt,nonexistent
c2.txt,nonexistent
cdir/c2.txt,nonexistent因此,您看到了问题所在-归档文件在那里,但它们没有解压。我遗漏了什么?我也尝试过使用DistributedCache.addCacheArchive()而不是-archives,但问题仍然存在。
发布于 2013-08-23 07:54:34
分布式缓存不会将存档文件解压到任务的本地工作目录中--每个任务跟踪器上都有一个位置,作为一个整体,它会在那里解压。
您需要检查DistributedCache以找到此位置并在那里查找文件。DistributedCache的Javadoc显示了一个提取此信息的示例映射器。
在定义-files和-archives通用选项时,您可以使用符号链接,并且将在映射/缩减任务的本地工作目录中创建符号链接,从而简化此操作:
hadoop jar myJar myClass -files ./etc/alice.txt#file1.txt \
-archives ./etc/bob.zip#bob,./etc/claire.tar#claire然后,在尝试打开归档中的文件时,您可以在映射器中使用片段名称:
new File("bob").isDirectory() == truehttps://stackoverflow.com/questions/18343371
复制相似问题