有什么方法可以检查 Hadoop 文件是否已经打开进行写入?

Is there any way to check whether the Hadoop file is already opened for write?

多个 Java 实例在我的机器上 运行,我想检查 Hadoop 文件是否已经在任何实例中以写入 (fs.create(file) or fs.append(file)) 模式打开。

我在 Hadoop 文件的 FileStatus 中试过,没有找到任何东西。

有什么方法可以检查 Hadoop 文件是否已经打开进行写入?

一种方法是再次尝试 create/append 一个文件并捕获异常,但我有数千个文件并且不想尝试每个文件。另外,如果 create/append 成功,那么我必须关闭文件并且 lastModifiedTime 也会被更改。我不想修改 Hadoop 文件的 FileStatus。

DistributedFileSystem提供方法isFileClosed(path)检查文件是否打开写入

try {
    DistributedFileSystem dfs = new DistributedFileSystem();
    Path path = new Path("/path/to/hadoop/file");
    FileSystem fs = path.getFileSystem(conf);
    dfs.initialize(fs.getUri(),conf);

    if (dfs.exists(path) && !dfs.isFileClosed(path)) {
        System.out.println("File " + path +" already opened in write mode");
    }
} catch (IOException e) {
    e.printStackTrace();
}