介面 LeaseRecoverable

LeaseRecoverable 介面表示當前檔案系統的給定路徑是否可以對未明確更新租約或持有它的用戶端消失的開啟檔案執行租約復原。

如果需要,此介面應相應地實作到支援租約復原的任何檔案系統,例如 DistributedFileSystem (HDFS) 和 ViewDistributedFileSystem

public interface LeaseRecoverable {
  boolean recoverLease(Path file) throws IOException;
  boolean isFileClosed(Path file) throws IOException;
}

此介面有兩個主要功能,一個執行租約復原,另一個驗證檔案是否已關閉。

boolean recoverLease(Path file)

此函數執行給定檔案路徑的租約復原,且不支援目錄路徑復原。1. 如果檔案已關閉或不需要租約復原,則傳回 true。1. 如果租約復原尚未完成,則傳回 false。1. 如果輸入為目錄路徑,則擲回 IOException

boolean isFileClosed(Path file)

此函數僅檢查給定的檔案路徑是否已關閉,且不支援目錄驗證。1. 如果檔案已關閉,則傳回 true。1. 如果檔案仍開啟,則傳回 false。1. 如果輸入為目錄路徑,則擲回 IOException

應宣告 Path Capabilities

如果檔案系統支援 LeaseRecoverable,則應對給定路徑傳回 truePathCapabilities.hasPathCapability(path, "fs.capability.lease.recoverable")