Class SingleDirectoryDbLedgerStorage
- java.lang.Object
-
- org.apache.bookkeeper.bookie.storage.ldb.SingleDirectoryDbLedgerStorage
-
- All Implemented Interfaces:
CompactableLedgerStorage,LedgerStorage
public class SingleDirectoryDbLedgerStorage extends java.lang.Object implements CompactableLedgerStorage
Single directory implementation of LedgerStorage that uses RocksDB to keep the indexes for entries stored in EntryLogs.This is meant only to be used from
DbLedgerStorage.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceSingleDirectoryDbLedgerStorage.LedgerLoggerProcessorInterface which process ledger logger.-
Nested classes/interfaces inherited from interface org.apache.bookkeeper.bookie.LedgerStorage
LedgerStorage.DetectedInconsistency, LedgerStorage.LedgerDeletionListener, LedgerStorage.StorageState
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.locks.ReentrantLockflushMutexprotected java.util.concurrent.atomic.AtomicBooleanhasFlushBeenTriggeredprotected WriteCachewriteCacheprotected WriteCachewriteCacheBeingFlushed
-
Constructor Summary
Constructors Constructor Description SingleDirectoryDbLedgerStorage(ServerConfiguration conf, LedgerManager ledgerManager, LedgerDirsManager ledgerDirsManager, LedgerDirsManager indexDirsManager, EntryLogger entryLogger, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator, long writeCacheSize, long readCacheSize, int readAheadCacheBatchSize, long readAheadCacheBatchBytesSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longaddEntry(io.netty.buffer.ByteBuf entry)Add an entry to the storage.longaddLedgerToIndex(long ledgerId, boolean isFenced, byte[] masterKey, LedgerCache.PageEntriesIterable pages)Add an already existing ledger to the index.voidcancelWaitForLastAddConfirmedUpdate(long ledgerId, Watcher<LastAddConfirmedUpdateNotification> watcher)Cancel a previous wait for last add confirmed update.protected booleanchargeReadAheadCache(int currentReadAheadCount, long currentReadAheadBytes)voidcheckpoint(CheckpointSource.Checkpoint checkpoint)Ask the ledger storage to sync data until the given checkpoint.voidclearLimboState(long ledgerId)Clear the limbo state of a ledger.voidclearStorageStateFlag(LedgerStorage.StorageState flag)Clear a storage state flag for the storage instance.voiddeleteLedger(long ledgerId)booleanentryExists(long ledgerId, long entryId)Whether an entry exists.voidentryLocationCompact()voidflush()Flushes all data in the storage.voidflushEntriesLocationsIndex()Flush the entries locations index for the compacted entries.voidforceGC()Force trigger Garbage Collection.voidforceGC(boolean forceMajor, boolean forceMinor)Force trigger Garbage Collection with forceMajor or forceMinor parameter.java.lang.Iterable<java.lang.Long>getActiveLedgersInRange(long firstLedgerId, long lastLedgerId)Get an iterator over a range of ledger ids stored in the bookie.(package private) DbLedgerStorageStatsgetDbLedgerStorageStats()io.netty.buffer.ByteBufgetEntry(long ledgerId, long entryId)Read an entry from storage.java.util.List<java.lang.String>getEntryLocationDBPath()EntryLocationIndexgetEntryLocationIndex()(package private) EntryLoggergetEntryLogger()io.netty.buffer.ByteBufgetExplicitLac(long ledgerId)java.util.List<GarbageCollectionStatus>getGarbageCollectionStatus()Get Garbage Collection status.java.lang.StringgetIndexBaseDir()longgetLastAddConfirmed(long ledgerId)Get last add confirmed.io.netty.buffer.ByteBufgetLastEntry(long ledgerId)java.lang.StringgetLedgerBaseDir()java.util.PrimitiveIterator.OfLonggetListOfEntriesOfLedger(long ledgerId)Returns the primitive long iterator for entries of the ledger, stored in this LedgerStorage.java.util.EnumSet<LedgerStorage.StorageState>getStorageStateFlags()Get the storage state flags currently set for the storage instance.booleanhasLimboState(long ledgerId)Check whether a ledger is in limbo state.voidinitialize(ServerConfiguration conf, LedgerManager ledgerManager, LedgerDirsManager ledgerDirsManager, LedgerDirsManager indexDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator)Initialize the LedgerStorage implementation.booleanisEntryLocationCompacting()booleanisFenced(long ledgerId)Check whether the ledger is fenced in ledger storage or not.(package private) booleanisFlushRequired()booleanisInForceGC()Whether force triggered Garbage Collection is running or not.booleanisMajorGcSuspended()booleanisMinorGcSuspended()booleanledgerExists(long ledgerId)Whether a ledger exists.byte[]readMasterKey(long ledgerId)Get the master key for a ledger.voidregisterLedgerDeletionListener(LedgerStorage.LedgerDeletionListener listener)Register a listener for ledgers deletion notifications.voidresumeMajorGC()voidresumeMinorGC()voidsetCheckpointer(Checkpointer checkpointer)voidsetCheckpointSource(CheckpointSource checkpointSource)voidsetExplicitLac(long ledgerId, io.netty.buffer.ByteBuf lac)booleansetFenced(long ledgerId)Fenced the ledger id in ledger storage.voidsetLimboState(long ledgerId)Set a ledger to limbo state.voidsetMasterKey(long ledgerId, byte[] masterKey)Set the master key for a ledger.voidsetStateManager(StateManager stateManager)voidsetStorageStateFlag(LedgerStorage.StorageState flag)Set a storage state flag for the storage instance.voidshutdown()Cleanup and free any resources being used by the storage system.voidstart()Start any background threads belonging to the storage system.voidsuspendMajorGC()voidsuspendMinorGC()voidupdateEntriesLocations(java.lang.Iterable<EntryLocation> locations)Update the location of several entries.booleanwaitForLastAddConfirmedUpdate(long ledgerId, long previousLAC, Watcher<LastAddConfirmedUpdateNotification> watcher)Wait for last add confirmed update.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.bookkeeper.bookie.LedgerStorage
entryLocationCompact, getUnderlyingLedgerStorage, isEntryLocationCompacting, localConsistencyCheck
-
-
-
-
Field Detail
-
writeCache
protected volatile WriteCache writeCache
-
writeCacheBeingFlushed
protected volatile WriteCache writeCacheBeingFlushed
-
flushMutex
protected final java.util.concurrent.locks.ReentrantLock flushMutex
-
hasFlushBeenTriggered
protected final java.util.concurrent.atomic.AtomicBoolean hasFlushBeenTriggered
-
-
Constructor Detail
-
SingleDirectoryDbLedgerStorage
public SingleDirectoryDbLedgerStorage(ServerConfiguration conf, LedgerManager ledgerManager, LedgerDirsManager ledgerDirsManager, LedgerDirsManager indexDirsManager, EntryLogger entryLogger, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator, long writeCacheSize, long readCacheSize, int readAheadCacheBatchSize, long readAheadCacheBatchBytesSize) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
initialize
public void initialize(ServerConfiguration conf, LedgerManager ledgerManager, LedgerDirsManager ledgerDirsManager, LedgerDirsManager indexDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator) throws java.io.IOException
Description copied from interface:LedgerStorageInitialize the LedgerStorage implementation.- Specified by:
initializein interfaceLedgerStorage- Throws:
java.io.IOException
-
setStateManager
public void setStateManager(StateManager stateManager)
- Specified by:
setStateManagerin interfaceLedgerStorage
-
setCheckpointSource
public void setCheckpointSource(CheckpointSource checkpointSource)
- Specified by:
setCheckpointSourcein interfaceLedgerStorage
-
setCheckpointer
public void setCheckpointer(Checkpointer checkpointer)
- Specified by:
setCheckpointerin interfaceLedgerStorage
-
start
public void start()
Description copied from interface:LedgerStorageStart any background threads belonging to the storage system. For example, garbage collection.- Specified by:
startin interfaceLedgerStorage
-
forceGC
public void forceGC()
Description copied from interface:LedgerStorageForce trigger Garbage Collection.- Specified by:
forceGCin interfaceLedgerStorage
-
forceGC
public void forceGC(boolean forceMajor, boolean forceMinor)Description copied from interface:LedgerStorageForce trigger Garbage Collection with forceMajor or forceMinor parameter.- Specified by:
forceGCin interfaceLedgerStorage
-
isInForceGC
public boolean isInForceGC()
Description copied from interface:LedgerStorageWhether force triggered Garbage Collection is running or not.- Specified by:
isInForceGCin interfaceLedgerStorage- Returns:
- true -- force triggered Garbage Collection is running, false -- force triggered Garbage Collection is not running
-
suspendMinorGC
public void suspendMinorGC()
- Specified by:
suspendMinorGCin interfaceLedgerStorage
-
suspendMajorGC
public void suspendMajorGC()
- Specified by:
suspendMajorGCin interfaceLedgerStorage
-
resumeMinorGC
public void resumeMinorGC()
- Specified by:
resumeMinorGCin interfaceLedgerStorage
-
resumeMajorGC
public void resumeMajorGC()
- Specified by:
resumeMajorGCin interfaceLedgerStorage
-
isMajorGcSuspended
public boolean isMajorGcSuspended()
- Specified by:
isMajorGcSuspendedin interfaceLedgerStorage
-
isMinorGcSuspended
public boolean isMinorGcSuspended()
- Specified by:
isMinorGcSuspendedin interfaceLedgerStorage
-
entryLocationCompact
public void entryLocationCompact()
- Specified by:
entryLocationCompactin interfaceLedgerStorage
-
isEntryLocationCompacting
public boolean isEntryLocationCompacting()
- Specified by:
isEntryLocationCompactingin interfaceLedgerStorage
-
getEntryLocationDBPath
public java.util.List<java.lang.String> getEntryLocationDBPath()
- Specified by:
getEntryLocationDBPathin interfaceLedgerStorage
-
shutdown
public void shutdown() throws java.lang.InterruptedExceptionDescription copied from interface:LedgerStorageCleanup and free any resources being used by the storage system.- Specified by:
shutdownin interfaceLedgerStorage- Throws:
java.lang.InterruptedException
-
ledgerExists
public boolean ledgerExists(long ledgerId) throws java.io.IOExceptionDescription copied from interface:LedgerStorageWhether a ledger exists.- Specified by:
ledgerExistsin interfaceLedgerStorage- Throws:
java.io.IOException
-
entryExists
public boolean entryExists(long ledgerId, long entryId) throws java.io.IOException, BookieExceptionDescription copied from interface:LedgerStorageWhether an entry exists.- Specified by:
entryExistsin interfaceLedgerStorage- Throws:
java.io.IOExceptionBookieException
-
isFenced
public boolean isFenced(long ledgerId) throws java.io.IOException, BookieExceptionDescription copied from interface:LedgerStorageCheck whether the ledger is fenced in ledger storage or not.- Specified by:
isFencedin interfaceLedgerStorage- Parameters:
ledgerId- Ledger ID.- Throws:
java.io.IOExceptionBookieException
-
setFenced
public boolean setFenced(long ledgerId) throws java.io.IOExceptionDescription copied from interface:LedgerStorageFenced the ledger id in ledger storage.- Specified by:
setFencedin interfaceLedgerStorage- Parameters:
ledgerId- Ledger Id.- Throws:
java.io.IOException- when failed to fence the ledger.
-
setMasterKey
public void setMasterKey(long ledgerId, byte[] masterKey) throws java.io.IOExceptionDescription copied from interface:LedgerStorageSet the master key for a ledger.- Specified by:
setMasterKeyin interfaceLedgerStorage- Throws:
java.io.IOException
-
readMasterKey
public byte[] readMasterKey(long ledgerId) throws java.io.IOException, BookieExceptionDescription copied from interface:LedgerStorageGet the master key for a ledger.- Specified by:
readMasterKeyin interfaceLedgerStorage- Throws:
java.io.IOException- if there is an error reading the from the ledgerBookieException- if no such ledger exists
-
addEntry
public long addEntry(io.netty.buffer.ByteBuf entry) throws java.io.IOException, BookieExceptionDescription copied from interface:LedgerStorageAdd an entry to the storage.- Specified by:
addEntryin interfaceLedgerStorage- Returns:
- the entry id of the entry added
- Throws:
java.io.IOExceptionBookieException
-
getEntry
public io.netty.buffer.ByteBuf getEntry(long ledgerId, long entryId) throws java.io.IOException, BookieExceptionDescription copied from interface:LedgerStorageRead an entry from storage.- Specified by:
getEntryin interfaceLedgerStorage- Throws:
java.io.IOExceptionBookieException
-
chargeReadAheadCache
protected boolean chargeReadAheadCache(int currentReadAheadCount, long currentReadAheadBytes)
-
getLastEntry
public io.netty.buffer.ByteBuf getLastEntry(long ledgerId) throws java.io.IOException, BookieException- Throws:
java.io.IOExceptionBookieException
-
isFlushRequired
boolean isFlushRequired()
-
checkpoint
public void checkpoint(CheckpointSource.Checkpoint checkpoint) throws java.io.IOException
Description copied from interface:LedgerStorageAsk the ledger storage to sync data until the given checkpoint. The ledger storage implementation do checkpoint and return the real checkpoint that it finished. The returned the checkpoint indicates that all entries added before that point already persist.- Specified by:
checkpointin interfaceLedgerStorage- Parameters:
checkpoint- Check Point thatCheckpointSource.Checkpointproposed.- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOExceptionDescription copied from interface:LedgerStorageFlushes all data in the storage. Once this is called, add data written to the LedgerStorage up until this point has been persisted to perminant storage- Specified by:
flushin interfaceLedgerStorage- Throws:
java.io.IOException
-
deleteLedger
public void deleteLedger(long ledgerId) throws java.io.IOException- Specified by:
deleteLedgerin interfaceLedgerStorage- Throws:
java.io.IOException
-
getActiveLedgersInRange
public java.lang.Iterable<java.lang.Long> getActiveLedgersInRange(long firstLedgerId, long lastLedgerId) throws java.io.IOExceptionDescription copied from interface:CompactableLedgerStorageGet an iterator over a range of ledger ids stored in the bookie.- Specified by:
getActiveLedgersInRangein interfaceCompactableLedgerStorage- Parameters:
firstLedgerId- first ledger id in the sequence (included)lastLedgerId- last ledger id in the sequence (not included)- Returns:
- Throws:
java.io.IOException
-
updateEntriesLocations
public void updateEntriesLocations(java.lang.Iterable<EntryLocation> locations) throws java.io.IOException
Description copied from interface:CompactableLedgerStorageUpdate the location of several entries.- Specified by:
updateEntriesLocationsin interfaceCompactableLedgerStorage- Parameters:
locations- the list of locations to update- Throws:
java.io.IOException
-
getEntryLogger
EntryLogger getEntryLogger()
-
getLastAddConfirmed
public long getLastAddConfirmed(long ledgerId) throws java.io.IOException, BookieExceptionDescription copied from interface:LedgerStorageGet last add confirmed.- Specified by:
getLastAddConfirmedin interfaceLedgerStorage- Parameters:
ledgerId- ledger id.- Returns:
- last add confirmed.
- Throws:
java.io.IOExceptionBookieException
-
waitForLastAddConfirmedUpdate
public boolean waitForLastAddConfirmedUpdate(long ledgerId, long previousLAC, Watcher<LastAddConfirmedUpdateNotification> watcher) throws java.io.IOExceptionDescription copied from interface:LedgerStorageWait for last add confirmed update.- Specified by:
waitForLastAddConfirmedUpdatein interfaceLedgerStoragepreviousLAC- - The threshold beyond which we would wait for the updatewatcher- - Watcher to notify on update- Returns:
- Throws:
java.io.IOException
-
cancelWaitForLastAddConfirmedUpdate
public void cancelWaitForLastAddConfirmedUpdate(long ledgerId, Watcher<LastAddConfirmedUpdateNotification> watcher) throws java.io.IOExceptionDescription copied from interface:LedgerStorageCancel a previous wait for last add confirmed update.- Specified by:
cancelWaitForLastAddConfirmedUpdatein interfaceLedgerStorage- Parameters:
ledgerId- The ledger being watched.watcher- The watcher to cancel.- Throws:
java.io.IOException
-
setExplicitLac
public void setExplicitLac(long ledgerId, io.netty.buffer.ByteBuf lac) throws java.io.IOException- Specified by:
setExplicitLacin interfaceLedgerStorage- Throws:
java.io.IOException
-
getExplicitLac
public io.netty.buffer.ByteBuf getExplicitLac(long ledgerId) throws java.io.IOException, BookieException- Specified by:
getExplicitLacin interfaceLedgerStorage- Throws:
java.io.IOExceptionBookieException
-
flushEntriesLocationsIndex
public void flushEntriesLocationsIndex() throws java.io.IOExceptionDescription copied from interface:CompactableLedgerStorageFlush the entries locations index for the compacted entries.- Specified by:
flushEntriesLocationsIndexin interfaceCompactableLedgerStorage- Throws:
java.io.IOException
-
addLedgerToIndex
public long addLedgerToIndex(long ledgerId, boolean isFenced, byte[] masterKey, LedgerCache.PageEntriesIterable pages) throws java.lang.ExceptionAdd an already existing ledger to the index.This method is only used as a tool to help the migration from InterleaveLedgerStorage to DbLedgerStorage
- Parameters:
ledgerId- the ledger idpages- Iterator over index pages from Indexed- Returns:
- the number of
- Throws:
java.lang.Exception
-
registerLedgerDeletionListener
public void registerLedgerDeletionListener(LedgerStorage.LedgerDeletionListener listener)
Description copied from interface:LedgerStorageRegister a listener for ledgers deletion notifications.- Specified by:
registerLedgerDeletionListenerin interfaceLedgerStorage- Parameters:
listener- object that will be notified every time a ledger is deleted
-
getEntryLocationIndex
public EntryLocationIndex getEntryLocationIndex()
-
getGarbageCollectionStatus
public java.util.List<GarbageCollectionStatus> getGarbageCollectionStatus()
Description copied from interface:LedgerStorageGet Garbage Collection status. Since DbLedgerStorage is a list of storage instances, we should return a list.- Specified by:
getGarbageCollectionStatusin interfaceLedgerStorage
-
getListOfEntriesOfLedger
public java.util.PrimitiveIterator.OfLong getListOfEntriesOfLedger(long ledgerId) throws java.io.IOExceptionDescription copied from interface:LedgerStorageReturns the primitive long iterator for entries of the ledger, stored in this LedgerStorage. The returned iterator provide weakly consistent state of the ledger. It is guaranteed that entries of the ledger added to this LedgerStorage by the time this method is called will be available but modifications made after method invocation may not be available.- Specified by:
getListOfEntriesOfLedgerin interfaceLedgerStorage- Parameters:
ledgerId- - id of the ledger- Returns:
- the list of entries of the ledger available in this ledgerstorage.
- Throws:
java.io.IOException
-
setLimboState
public void setLimboState(long ledgerId) throws java.io.IOExceptionDescription copied from interface:LedgerStorageSet a ledger to limbo state. When a ledger is in limbo state, we cannot answer any requests about it. For example, if a client asks for an entry, we cannot say we don't have it because it may have been written to us in the past, but we are waiting for data integrity checks to copy it over.- Specified by:
setLimboStatein interfaceLedgerStorage- Throws:
java.io.IOException
-
hasLimboState
public boolean hasLimboState(long ledgerId) throws java.io.IOExceptionDescription copied from interface:LedgerStorageCheck whether a ledger is in limbo state.- Specified by:
hasLimboStatein interfaceLedgerStorage- Throws:
java.io.IOException- See Also:
LedgerStorage.setLimboState(long)
-
clearLimboState
public void clearLimboState(long ledgerId) throws java.io.IOExceptionDescription copied from interface:LedgerStorageClear the limbo state of a ledger.- Specified by:
clearLimboStatein interfaceLedgerStorage- Throws:
java.io.IOException- See Also:
LedgerStorage.setLimboState(long)
-
getStorageStateFlags
public java.util.EnumSet<LedgerStorage.StorageState> getStorageStateFlags() throws java.io.IOException
Description copied from interface:LedgerStorageGet the storage state flags currently set for the storage instance.- Specified by:
getStorageStateFlagsin interfaceLedgerStorage- Throws:
java.io.IOException
-
setStorageStateFlag
public void setStorageStateFlag(LedgerStorage.StorageState flag) throws java.io.IOException
Description copied from interface:LedgerStorageSet a storage state flag for the storage instance. Implementations must ensure this method is atomic, and the flag is persisted to storage when the method returns.- Specified by:
setStorageStateFlagin interfaceLedgerStorage- Throws:
java.io.IOException
-
clearStorageStateFlag
public void clearStorageStateFlag(LedgerStorage.StorageState flag) throws java.io.IOException
Description copied from interface:LedgerStorageClear a storage state flag for the storage instance. Implementations must ensure this method is atomic, and the flag is persisted to storage when the method returns.- Specified by:
clearStorageStateFlagin interfaceLedgerStorage- Throws:
java.io.IOException
-
getDbLedgerStorageStats
DbLedgerStorageStats getDbLedgerStorageStats()
-
getLedgerBaseDir
public java.lang.String getLedgerBaseDir()
-
getIndexBaseDir
public java.lang.String getIndexBaseDir()
-
-