Package org.apache.bookkeeper.bookie
Class SortedLedgerStorage
java.lang.Object
org.apache.bookkeeper.bookie.SortedLedgerStorage
- All Implemented Interfaces:
CacheCallback,CompactableLedgerStorage,DefaultEntryLogger.EntryLogListener,LedgerStorage,SkipListFlusher
public class SortedLedgerStorage
extends Object
implements LedgerStorage, CacheCallback, SkipListFlusher, CompactableLedgerStorage, DefaultEntryLogger.EntryLogListener
A
SortedLedgerStorage is an extension of InterleavedLedgerStorage. It
is comprised of two MemTables and a InterleavedLedgerStorage. All the
entries will be first added into a MemTable, and then be flushed back to the
InterleavedLedgerStorage when the MemTable becomes full.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.bookkeeper.bookie.LedgerStorage
LedgerStorage.DetectedInconsistency, LedgerStorage.LedgerDeletionListener, LedgerStorage.StorageState -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected -
Method Summary
Modifier and TypeMethodDescriptionlongaddEntry(io.netty.buffer.ByteBuf entry) Add an entry to the storage.voidcancelWaitForLastAddConfirmedUpdate(long ledgerId, Watcher<LastAddConfirmedUpdateNotification> watcher) Cancel a previous wait for last add confirmed update.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.voidClear a storage state flag for the storage instance.voiddeleteLedger(long ledgerId) booleanentryExists(long ledgerId, long entryId) Whether an entry exists.voidflush()Flushes all data in the storage.voidFlush 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.getActiveLedgersInRange(long firstLedgerId, long lastLedgerId) Get an iterator over a range of ledger ids stored in the bookie.io.netty.buffer.ByteBufgetEntry(long ledgerId, long entryId) Read an entry from storage.io.netty.buffer.ByteBufgetExplicitLac(long ledgerId) Get Garbage Collection status.longgetLastAddConfirmed(long ledgerId) Get last add confirmed.getListOfEntriesOfLedger(long ledgerId) Returns the primitive long iterator for entries of the ledger, stored in this LedgerStorage.(package private) ScheduledExecutorService(package private) BookieStateManagerGet 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.booleanisFenced(long ledgerId) Check whether the ledger is fenced in ledger storage or not.booleanWhether force triggered Garbage Collection is running or not.booleanbooleanbooleanledgerExists(long ledgerId) Whether a ledger exists.localConsistencyCheck(Optional<com.google.common.util.concurrent.RateLimiter> rateLimiter) Performs internal check of local storage logging any inconsistencies.(package private) static ScheduledExecutorServicevoidRotate a new entry log to write.voidProcess notification that cache size limit reached.voidprocess(long ledgerId, long entryId, io.netty.buffer.ByteBuf buffer) Process an entry.byte[]readMasterKey(long ledgerId) Get the master key for a ledger.voidRegister a listener for ledgers deletion notifications.voidvoidvoidsetCheckpointer(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) voidSet 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.voidvoidvoidupdateEntriesLocations(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, waitMethods inherited from interface org.apache.bookkeeper.bookie.LedgerStorage
entryLocationCompact, entryLocationCompact, getEntryLocationDBPath, isEntryLocationCompacting, isEntryLocationCompacting
-
Field Details
-
memTable
EntryMemTable memTable
-
-
Constructor Details
-
SortedLedgerStorage
public SortedLedgerStorage() -
SortedLedgerStorage
-
-
Method Details
-
initialize
public void initialize(ServerConfiguration conf, LedgerManager ledgerManager, LedgerDirsManager ledgerDirsManager, LedgerDirsManager indexDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator) throws IOException Description copied from interface:LedgerStorageInitialize the LedgerStorage implementation.- Specified by:
initializein interfaceLedgerStorage- Throws:
IOException
-
newScheduledExecutorService
-
setStateManager
- Specified by:
setStateManagerin interfaceLedgerStorage
-
setCheckpointSource
- Specified by:
setCheckpointSourcein interfaceLedgerStorage
-
setCheckpointer
- Specified by:
setCheckpointerin interfaceLedgerStorage
-
getScheduler
ScheduledExecutorService getScheduler() -
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
-
shutdown
Description copied from interface:LedgerStorageCleanup and free any resources being used by the storage system.- Specified by:
shutdownin interfaceLedgerStorage- Throws:
InterruptedException
-
ledgerExists
Description copied from interface:LedgerStorageWhether a ledger exists.- Specified by:
ledgerExistsin interfaceLedgerStorage- Throws:
IOException
-
entryExists
Description copied from interface:LedgerStorageWhether an entry exists.- Specified by:
entryExistsin interfaceLedgerStorage- Throws:
IOException
-
setFenced
Description copied from interface:LedgerStorageFenced the ledger id in ledger storage.- Specified by:
setFencedin interfaceLedgerStorage- Parameters:
ledgerId- Ledger Id.- Throws:
IOException- when failed to fence the ledger.
-
isFenced
Description copied from interface:LedgerStorageCheck whether the ledger is fenced in ledger storage or not.- Specified by:
isFencedin interfaceLedgerStorage- Parameters:
ledgerId- Ledger ID.- Throws:
IOException
-
setMasterKey
Description copied from interface:LedgerStorageSet the master key for a ledger.- Specified by:
setMasterKeyin interfaceLedgerStorage- Throws:
IOException
-
readMasterKey
Description copied from interface:LedgerStorageGet the master key for a ledger.- Specified by:
readMasterKeyin interfaceLedgerStorage- Throws:
IOException- if there is an error reading the from the ledgerBookieException- if no such ledger exists
-
addEntry
Description copied from interface:LedgerStorageAdd an entry to the storage.- Specified by:
addEntryin interfaceLedgerStorage- Returns:
- the entry id of the entry added
- Throws:
IOException
-
getEntry
public io.netty.buffer.ByteBuf getEntry(long ledgerId, long entryId) throws IOException, BookieException Description copied from interface:LedgerStorageRead an entry from storage.- Specified by:
getEntryin interfaceLedgerStorage- Throws:
IOExceptionBookieException
-
getLastAddConfirmed
Description copied from interface:LedgerStorageGet last add confirmed.- Specified by:
getLastAddConfirmedin interfaceLedgerStorage- Parameters:
ledgerId- ledger id.- Returns:
- last add confirmed.
- Throws:
IOException
-
waitForLastAddConfirmedUpdate
public boolean waitForLastAddConfirmedUpdate(long ledgerId, long previousLAC, Watcher<LastAddConfirmedUpdateNotification> watcher) throws IOException Description 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:
IOException
-
cancelWaitForLastAddConfirmedUpdate
public void cancelWaitForLastAddConfirmedUpdate(long ledgerId, Watcher<LastAddConfirmedUpdateNotification> watcher) throws IOException Description 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:
IOException
-
checkpoint
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:
IOException
-
deleteLedger
- Specified by:
deleteLedgerin interfaceLedgerStorage- Throws:
IOException
-
registerLedgerDeletionListener
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
-
setExplicitLac
- Specified by:
setExplicitLacin interfaceLedgerStorage- Throws:
IOException
-
getExplicitLac
public io.netty.buffer.ByteBuf getExplicitLac(long ledgerId) - Specified by:
getExplicitLacin interfaceLedgerStorage
-
process
Description copied from interface:SkipListFlusherProcess an entry.- Specified by:
processin interfaceSkipListFlusher- Parameters:
ledgerId- Ledger ID.entryId- The entry id this entry.buffer- Entry ByteBuffer- Throws:
IOException
-
flush
Description 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:
IOException
-
onSizeLimitReached
Description copied from interface:CacheCallbackProcess notification that cache size limit reached.- Specified by:
onSizeLimitReachedin interfaceCacheCallback- Throws:
IOException
-
onRotateEntryLog
public void onRotateEntryLog()Description copied from interface:DefaultEntryLogger.EntryLogListenerRotate a new entry log to write.- Specified by:
onRotateEntryLogin interfaceDefaultEntryLogger.EntryLogListener
-
getStateManager
BookieStateManager getStateManager() -
getEntryLogger
-
getActiveLedgersInRange
public Iterable<Long> getActiveLedgersInRange(long firstLedgerId, long lastLedgerId) throws IOException Description 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:
IOException
-
updateEntriesLocations
Description copied from interface:CompactableLedgerStorageUpdate the location of several entries.- Specified by:
updateEntriesLocationsin interfaceCompactableLedgerStorage- Parameters:
locations- the list of locations to update- Throws:
IOException
-
flushEntriesLocationsIndex
Description copied from interface:CompactableLedgerStorageFlush the entries locations index for the compacted entries.- Specified by:
flushEntriesLocationsIndexin interfaceCompactableLedgerStorage- Throws:
IOException
-
getUnderlyingLedgerStorage
- Specified by:
getUnderlyingLedgerStoragein 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
-
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
-
localConsistencyCheck
public List<LedgerStorage.DetectedInconsistency> localConsistencyCheck(Optional<com.google.common.util.concurrent.RateLimiter> rateLimiter) throws IOException Description copied from interface:LedgerStoragePerforms internal check of local storage logging any inconsistencies.- Specified by:
localConsistencyCheckin interfaceLedgerStorage- Parameters:
rateLimiter- Provide to rate of entry checking. null for unlimited.- Returns:
- List of inconsistencies detected
- Throws:
IOException
-
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
-
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
Description 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:
IOException
-
setLimboState
Description 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:
IOException
-
hasLimboState
Description copied from interface:LedgerStorageCheck whether a ledger is in limbo state.- Specified by:
hasLimboStatein interfaceLedgerStorage- Throws:
IOException- See Also:
-
clearLimboState
Description copied from interface:LedgerStorageClear the limbo state of a ledger.- Specified by:
clearLimboStatein interfaceLedgerStorage- Throws:
IOException- See Also:
-
getStorageStateFlags
Description copied from interface:LedgerStorageGet the storage state flags currently set for the storage instance.- Specified by:
getStorageStateFlagsin interfaceLedgerStorage- Throws:
IOException
-
setStorageStateFlag
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:
IOException
-
clearStorageStateFlag
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:
IOException
-