如何为保存在hadoop 2.5版本上的文件创建符号链接
问题描述:
我是一个关于HDFS的新手,我的问题是如何为保存在hadoop 2.5版本上的文件创建符号链接。我使用java API访问hdfs来创建符号链接符号连接)和一个例外如下:在线程 “主要” java.lang.UnsupportedOperationException如何为保存在hadoop 2.5版本上的文件创建符号链接
例外: 符号连接不支持 在org.apache.hadoop.hdfs.DistributedFileSystem.createSymlink(DistributedFileSystem.java:1328)
我的java代码如下:
1,在hdfs-site.xml中添加一些内容。
<property>
<name>test.SymlinkEnabledForTesting</name>
<value>true</value>
</property>
2,调用java API。
Configuration conf = new Configuration();
conf.set("mapred.create.symlink", "yes");
conf.set("fs.defaultFS", HdfsServer);
URI uri = URI.create(HdfsServer);
String target = "/tmp/target.csv";
Path targetPath = new Path(target);
String uriWithLink = "/tmp/link.csv";
Path linkPath= new Path(uriWithLink);
FileContext fc = FileContext.getFileContext(uri,conf);
fc.createSymlink(targetPath, linkPath, true);
有没有人可以给我一些建议?
答
java.lang.UnsupportedOperationException:符号连接不支持
可能会出现上述异常,由于没有实现,甚至你在HDFS-site.xml中给出的符号链接。请参阅此链接以获得更多理解link for Reason to Exception
因此,在FileContext之前,首先启用符号链接。
像这样
FileSystem.enableSymlinks(); // See linked patch: https://issues.apache.org/jira/browse/HADOOP-10020
希望这有助于。
谢谢。但仍然存在问题。第一,我修改在/ etc/hadoop的/ conf下HDFS-site.xml中,加入在该XML文件的某些内容 test.SymlinkEnabledForTesting 真 –
squall