HDFS でファイルを開いて書き込みを担当するオブジェクトがあります。close()
このオブジェクトは、メソッドが呼び出されると、書き込んだばかりのファイルの名前を変更します。このメカニズムは、ローカル モードで実行すると機能しますが、クラスター モードでファイルの名前を変更することはできません。
//Constructor
public WriteStream() {
path = String.format("in_progress/file");
try {
OutputStream outputStream = fileSystem.create(new Path(hdfs_path+path), new Progressable() {public void progress() { System.out.print("."); }
});
writer = new BufferedWriter(new OutputStreamWriter(outputStream));
} catch (IOException e) {
e.printStackTrace();
}
}
public void close() {
String newPath = String.format("%s_dir/%s_file", date, timestamp);
try {
fileSystem.rename(new Path(hdfs_path+path), new Path(hdfs_path+newPath));
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
以前にそれを経験しましたか?