我是关于HDFS的新手,我的问题是如何为hadoop 2.5版本保存的文件创建符号链接。我使用java API访问hdfs以创建符号链接(符号链接)和例外情况如下:
线程中的异常" main" java.lang.UnsupportedOperationException: 符号链接不受支持 在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);
有人可以给我一些建议吗?
答案 0 :(得分:1)
java.lang.UnsupportedOperationException:不支持符号链接
由于未启用符号链接,即使您在hdfs-site.xml中提供,也可能发生上述异常。请参阅此链接以了解更多link for Reason to Exception
因此,在FileContext之前,首先启用符号链接。
类似这样的事情
id keyword1 keyword2
------------------------
1 abc xyz
2 abc1
3 hjh pou
希望这有帮助。