Package org.apache.bookkeeper.bookie
Class LedgerDirsManager
- java.lang.Object
-
- org.apache.bookkeeper.bookie.LedgerDirsManager
-
public class LedgerDirsManager extends java.lang.Object
This class manages ledger directories used by the bookie.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
LedgerDirsManager.LedgerDirsListener
Listener for the disk check events will be notified from theLedgerDirsManager
whenever disk full/failure detected.static class
LedgerDirsManager.NoWritableLedgerDirException
Indicates All configured ledger directories are full.
-
Constructor Summary
Constructors Constructor Description LedgerDirsManager(ServerConfiguration conf, java.io.File[] dirs, DiskChecker diskChecker)
LedgerDirsManager(ServerConfiguration conf, java.io.File[] dirs, DiskChecker diskChecker, StatsLogger statsLogger)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addLedgerDirsListener(LedgerDirsManager.LedgerDirsListener listener)
void
addToFilledDirs(java.io.File dir)
Add the dir to filled dirs list.void
addToWritableDirs(java.io.File dir, boolean underWarnThreshold)
Add the dir to writable dirs list.java.util.List<java.io.File>
getAllLedgerDirs()
Get all ledger dirs configured.(package private) java.util.List<java.io.File>
getDirsAboveUsableThresholdSize(long thresholdSize, boolean loggingNoWritable)
DiskChecker
getDiskChecker()
java.util.concurrent.ConcurrentMap<java.io.File,java.lang.Float>
getDiskUsages()
Get disk usages map.java.util.List<java.io.File>
getFullFilledLedgerDirs()
java.util.List<LedgerDirsManager.LedgerDirsListener>
getListeners()
Get all dir listeners.long
getTotalDiskSpace(java.util.List<java.io.File> dirs)
Calculate the total amount of disk space in all of the ledger directories put together.long
getTotalFreeSpace(java.util.List<java.io.File> dirs)
Calculate the total amount of free space available in all of the ledger directories put together.java.util.List<java.io.File>
getWritableLedgerDirs()
Get only writable ledger dirs.java.util.List<java.io.File>
getWritableLedgerDirsForNewLog()
boolean
hasWritableLedgerDirs()
boolean
isDirFull(java.io.File dir)
Get dirs, which are full more than threshold.(package private) boolean
isDirWritableForNewIndexFile(java.io.File indexDir)
(package private) java.io.File
pickRandomDir(java.io.File excludedDir)
Return one dir from all dirs, regardless writable or not.(package private) java.io.File
pickRandomDir(java.util.List<java.io.File> dirs, java.io.File excludedDir)
(package private) java.io.File
pickRandomWritableDir()
Returns one of the ledger dir from writable dirs list randomly.(package private) java.io.File
pickRandomWritableDir(java.io.File excludedDir)
Pick up a writable dir from available dirs list randomly.(package private) java.io.File
pickRandomWritableDirForNewIndexFile(java.io.File excludedDir)
Pick up a dir randomly from writableLedgerDirectories.
-
-
-
Constructor Detail
-
LedgerDirsManager
public LedgerDirsManager(ServerConfiguration conf, java.io.File[] dirs, DiskChecker diskChecker) throws java.io.IOException
- Throws:
java.io.IOException
-
LedgerDirsManager
public LedgerDirsManager(ServerConfiguration conf, java.io.File[] dirs, DiskChecker diskChecker, StatsLogger statsLogger) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
getAllLedgerDirs
public java.util.List<java.io.File> getAllLedgerDirs()
Get all ledger dirs configured.
-
getListeners
public java.util.List<LedgerDirsManager.LedgerDirsListener> getListeners()
Get all dir listeners.- Returns:
- list of listeners
-
getTotalFreeSpace
public long getTotalFreeSpace(java.util.List<java.io.File> dirs) throws java.io.IOException
Calculate the total amount of free space available in all of the ledger directories put together.- Returns:
- freeDiskSpace in bytes
- Throws:
java.io.IOException
-
getTotalDiskSpace
public long getTotalDiskSpace(java.util.List<java.io.File> dirs) throws java.io.IOException
Calculate the total amount of disk space in all of the ledger directories put together.- Returns:
- totalDiskSpace in bytes
- Throws:
java.io.IOException
-
getDiskUsages
public java.util.concurrent.ConcurrentMap<java.io.File,java.lang.Float> getDiskUsages()
Get disk usages map.- Returns:
- disk usages map
-
getWritableLedgerDirs
public java.util.List<java.io.File> getWritableLedgerDirs() throws LedgerDirsManager.NoWritableLedgerDirException
Get only writable ledger dirs.
-
hasWritableLedgerDirs
public boolean hasWritableLedgerDirs()
- Returns:
- true if the writableLedgerDirs list has entries
-
getWritableLedgerDirsForNewLog
public java.util.List<java.io.File> getWritableLedgerDirsForNewLog() throws LedgerDirsManager.NoWritableLedgerDirException
-
getDirsAboveUsableThresholdSize
java.util.List<java.io.File> getDirsAboveUsableThresholdSize(long thresholdSize, boolean loggingNoWritable) throws LedgerDirsManager.NoWritableLedgerDirException
-
getFullFilledLedgerDirs
public java.util.List<java.io.File> getFullFilledLedgerDirs()
- Returns:
- full-filled ledger dirs.
-
isDirFull
public boolean isDirFull(java.io.File dir)
Get dirs, which are full more than threshold.
-
addToFilledDirs
public void addToFilledDirs(java.io.File dir)
Add the dir to filled dirs list.
-
addToWritableDirs
public void addToWritableDirs(java.io.File dir, boolean underWarnThreshold)
Add the dir to writable dirs list.- Parameters:
dir
- Dir
-
pickRandomWritableDir
java.io.File pickRandomWritableDir() throws LedgerDirsManager.NoWritableLedgerDirException
Returns one of the ledger dir from writable dirs list randomly.
-
pickRandomWritableDir
java.io.File pickRandomWritableDir(java.io.File excludedDir) throws LedgerDirsManager.NoWritableLedgerDirException
Pick up a writable dir from available dirs list randomly. TheexcludedDir
will not be pickedup.- Parameters:
excludedDir
- The directory to exclude during pickup.- Throws:
LedgerDirsManager.NoWritableLedgerDirException
- if there is no writable dir available.
-
pickRandomWritableDirForNewIndexFile
java.io.File pickRandomWritableDirForNewIndexFile(java.io.File excludedDir) throws LedgerDirsManager.NoWritableLedgerDirException
Pick up a dir randomly from writableLedgerDirectories. If writableLedgerDirectories is empty then pick up a dir randomly from the ledger/indexdirs which have usable space more than minUsableSizeForIndexFileCreation.- Parameters:
excludedDir
- The directory to exclude during pickup.- Returns:
- Throws:
LedgerDirsManager.NoWritableLedgerDirException
- if there is no dir available.
-
isDirWritableForNewIndexFile
boolean isDirWritableForNewIndexFile(java.io.File indexDir)
-
pickRandomDir
java.io.File pickRandomDir(java.io.File excludedDir) throws LedgerDirsManager.NoWritableLedgerDirException
Return one dir from all dirs, regardless writable or not.
-
pickRandomDir
java.io.File pickRandomDir(java.util.List<java.io.File> dirs, java.io.File excludedDir) throws LedgerDirsManager.NoWritableLedgerDirException
-
addLedgerDirsListener
public void addLedgerDirsListener(LedgerDirsManager.LedgerDirsListener listener)
-
getDiskChecker
public DiskChecker getDiskChecker()
-
-