![](/img/trans.png)
[英]hadoop hdfs java - what is the best way to copy a list of files from hdfs to hdfs
[英]What is the recommended way to append to files on HDFS?
我無法找出一種安全的方法來附加到HDFS
文件。
我正在使用一個小型的3-node Hadoop cluster (CDH v.5.3.9 to be specific)
。 我們的進程是一個multi-threaded (8 threads)
的數據管道,它有一個階段將分隔文本行附加到HDFS
上專用目錄中的文件。 我正在使用鎖來同步線程對附加數據的緩沖寫入器的訪問。
我的第一個問題是一般地決定方法。
方法 A是打開文件,附加到它,然后對附加的每一行關閉它。 這看起來很慢,而且似乎會產生太多的小塊,或者至少我在各種帖子中看到了一些這樣的情緒。
方法 B是緩存編寫器,但定期刷新它們以確保編寫器列表不會無限增長(目前,管道器處理的每個輸入文件都有一個編寫器)。 這似乎是一種更有效的方法,但我想在一段時間內打開流但受控可能是一個問題,尤其是對於輸出文件閱讀器(?)
除此之外,我真正的問題有兩個。 我正在使用FileSystem Java Hadoop API
進行追加,並且間歇性地收到以下 2 個異常:
org.apache.hadoop.ipc.RemoteException: failed to create file /output/acme_20160524_1.txt for DFSClient_NONMAPREDUCE_271210261_1 for client XXX.XX.XXX.XX because current leaseholder is trying to recreate file.
org.apache.hadoop.ipc.RemoteException: BP-1999982165-XXX.XX.XXX.XX-1463070000410:blk_1073760252_54540 does not exist or is not under Constructionblk_1073760252_545 40{blockUCState=UNDER_RECOVERY, primaryNodeIndex=1, replicas=[ReplicaUnderConstruction[[DISK]DS-ccdf4e55-234b-4e17-955f-daaed1afdd92:NORMAL|RBW], ReplicaUnderConst ruction[[DISK]DS-1f66db61-759f-4c5d-bb3b-f78c260e338f:NORMAL|RBW]]}
有人對其中任何一個有任何想法嗎?
對於第一個問題,我嘗試了在這篇文章中討論的檢測邏輯,但似乎沒有幫助。
如果適用,我也對dfs.support.append
屬性的作用感興趣。
我獲取文件系統的代碼:
userGroupInfo = UserGroupInformation.createRemoteUser("hdfs"); Configuration conf = new Configuration();
conf.set(key1, val1);
...
conf.set(keyN, valN);
fileSystem = userGroupInfo.doAs(new PrivilegedExceptionAction<FileSystem>() {
public FileSystem run() throws Exception {
return FileSystem.get(conf);
}
});
我獲取OutputStream的代碼:
org.apache.hadoop.fs.path.Path file = ...
public OutputStream getOutputStream(boolean append) throws IOException {
OutputStream os = null;
synchronized (file) {
if (isFile()) {
os = (append) ? fs.append(file) : fs.create(file, true);
} else if (append) {
// Create the file first, to avoid "failed to append to non-existent file" exception
FSDataOutputStream dos = fs.create(file);
dos.close();
// or, this can be: fs.createNewFile(file);
os = fs.append(file);
}
// Creating a new file
else {
os = fs.create(file);
}
}
return os;
}
我在 CDH 5.3 / HDFS 2.5.0 上附加了文件。 到目前為止,我的結論如下:
java.io.IOException: Failed to replace a bad datanode on the existing pipeline due to no more good datanodes being available to try. (Nodes: current=[XXX.XX.XXX.XX:50010, XXX.XX.XXX.XX:50010], original=[XXX.XX.XXX.XX:50010, XXX.XX.XXX.XX:50010]). The current failed datanode replacement policy is DEFAULT, and a client may configure this via 'dfs.client.block.write.replace-datanode-on-failure.policy' in its configuration.
at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.findNewDatanode(DFSOutputStream.java:969) ~[hadoop-hdfs-2.5.0.jar:?]
at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.addDatanode2ExistingPipeline(DFSOutputStream.java:1035) ~[hadoop-hdfs-2.5.0.jar:?]
at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.setupPipelineForAppendOrRecovery(DFSOutputStream.java:1184) ~[hadoop-hdfs-2.5.0.jar:?]
at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.run(DFSOutputStream.java:532) ~[hadoop-hdfs-2.5.0.jar:?]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.