Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ FileInfo getFileInfo(Long ledger, byte masterKey[]) throws IOException {
throw new Bookie.NoLedgerException(ledger);
}
// We don't have a ledger index file on disk, so create it.
lf = getNewLedgerIndexFile(ledger, null, true);
lf = getNewLedgerIndexFile(ledger, null);
createdNewFile = true;
}
}
Expand Down Expand Up @@ -176,38 +176,7 @@ private FileInfo putFileInfo(Long ledger, byte masterKey[], File lf, boolean cre
*/
private File getNewLedgerIndexFile(Long ledger, File excludedDir)
throws NoWritableLedgerDirException {
return getNewLedgerIndexFile(ledger, excludedDir, false);
}

/**
* Get a new index file for a ledger in a lazy way.
*
+ <p>If fallback is false, this function will throw exception when there are no writable dirs.
+ If fallback is true and there's no writable dirs, it will ignore the error and pick any dir.
+ Set fallback to true is useful when we want to delay disk check and just get the File pointer, e.g. fence ledger
*
* @param ledger
* Ledger id.
* @param excludedDir
* The ledger directory to exclude.
* @param fallback
* If fallback is false, the function will throw exception when there are no writable dirs;
* If it is true and there's no writable dirs, it will ignore the error and pick any dir.
* @return new index file object.
* @throws NoWritableLedgerDirException if there is no writable dir available.
*/
private File getNewLedgerIndexFile(Long ledger, File excludedDir, boolean fallback)
throws NoWritableLedgerDirException {
File dir = null;
try {
dir = ledgerDirsManager.pickRandomWritableDirForNewIndexFile(excludedDir);
} catch (NoWritableLedgerDirException e) {
if (fallback) {
dir = ledgerDirsManager.pickRandomDir(excludedDir);
} else {
throw e;
}
}
File dir = ledgerDirsManager.pickRandomWritableDirForNewIndexFile(excludedDir);
String ledgerName = getLedgerName(ledger);
return new File(dir, ledgerName);
}
Expand Down