我通过–Dmapred.cache.archives=hdfs://host:port/path/archive.zip#foldername –D.mapred.create.symlink=yes
向分布式缓存发送存档,并在工作目录中创建一个新文件夹,并在那里取消存档文件。问题是我需要工作目录中的那些文件,我已经尝试使用.
和./
作为文件夹名称以及发送空文件。关于如何解决这个问题的任何想法,除了在我的Java代码中显式移动文件?
答案 0 :(得分:0)
文件在工作目录中的具体需求是什么(所以我可以理解,并建议一些替代方案)。
无论如何,看起来分布式缓存中的存档将始终解压缩到目录中,所以我认为您无法使用存档解决此问题 - 但是,根据您希望放置在工作目录中的文件数量,您可以使用DistributedCache中的文件。
例如,使用GenericOptionsParser参数,您可以指定要包含的文件和文件夹,然后在工作目录中提供这些文件和文件夹:
public static class DistCacheMapper extends
Mapper<LongWritable, Text, NullWritable, NullWritable> {
@Override
public void run(Context context) throws IOException,
InterruptedException {
Configuration conf = context.getConfiguration();
System.err.println("Local Files:");
listFiles(new File("."), "");
}
private void listFiles(File dir, String ident) {
for (File f : dir.listFiles()) {
System.out.println(ident + (f.isDirectory() ? "d" : "-") + "\t"
+ f.getName());
if (f.isDirectory()) {
listFiles(f, ident + " ");
}
}
}
}
例如,使用hadoop jar myjar.jar -files pom.xml,.project,.classpath,src dummy.txt
在stderr上给出以下内容(您可以看到它已经获取了src文件夹):
- .classpath
- .project
d tmp
- pom.xml
d src
d test
d resources
d java
d main
d resources
d java
d csw
d sandbox
- DistCacheJob.java
- .DistCacheJob.java.crc
- job.jar
- .job.jar.crc
因此,您需要列出Dist Cache文件中工作目录中所需的所有文件,并且子目录可以列为存档,也可以使用文件列出。 / p>