Package org.apache.bookkeeper.bookie
Class GarbageCollectorThread
java.lang.Object
org.apache.bookkeeper.bookie.GarbageCollectorThread
- All Implemented Interfaces:
Runnable
This is the garbage collector thread that runs in the background to
remove any entry log files that no longer contains any active ledger.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final AtomicBoolean(package private) AbstractLogCompactor(package private) final ServerConfiguration(package private) boolean(package private) boolean(package private) final long(package private) final EntryLogger(package private) final AtomicBoolean(package private) final GarbageCollector.GarbageCleaner(package private) final ScanAndCompareGarbageCollector(package private) final long(package private) final boolean(package private) boolean(package private) boolean(package private) long(package private) long(package private) long(package private) final LedgerDirsManager(package private) final CompactableLedgerStorage(package private) final AtomicBoolean(package private) final long(package private) long(package private) final double(package private) final AtomicBoolean(package private) final long(package private) final long(package private) final double(package private) long(package private) boolean(package private) Future<?>(package private) final AtomicBoolean(package private) final AtomicBoolean(package private) final AbstractLogCompactor.Throttler -
Constructor Summary
ConstructorsConstructorDescriptionGarbageCollectorThread(ServerConfiguration conf, LedgerManager ledgerManager, LedgerDirsManager ledgerDirsManager, CompactableLedgerStorage ledgerStorage, EntryLogger entryLogger, StatsLogger statsLogger) Create a garbage collector thread.GarbageCollectorThread(ServerConfiguration conf, LedgerManager ledgerManager, LedgerDirsManager ledgerDirsManager, CompactableLedgerStorage ledgerStorage, EntryLogger entryLogger, StatsLogger statsLogger, ScheduledExecutorService gcExecutor) Create a garbage collector thread. -
Method Summary
Modifier and TypeMethodDescription(package private) intcalculateUsageIndex(int numBuckets, double usage) Calculate the index for the batch based on the usage between 0 and 1.protected voidcompactEntryLog(EntryLogMetadata entryLogMeta) Compact an entry log.void(package private) voiddoCompactEntryLogs(double threshold, long maxTimeMillis) Compact entry logs if necessary.voidvoidenableForceGC(boolean forceMajor, boolean forceMinor) protected voidMethod to read in all of the entry logs (those that we haven't done so yet), and find the set of ledger ID's that make up each entry log file.(package private) EntryLogMetadataMap(package private) CompactableLedgerStoragelongwhen number of ledger's Dir are more than 1,the same of GarbageCollectorThread will do the same thing, Especially 1) deleting ledger, then SyncThread will be timed to do rocksDB compact 2) compact: entry, cost cpu.booleanbooleanbooleanboolean(package private) static ScheduledExecutorServiceprotected booleanremoveEntryLog(long entryLogId) Remove entry log.voidvoidvoidrun()voidrunWithFlags(boolean force, boolean suspendMajor, boolean suspendMinor) voidshutdown()Shutdown the garbage collector thread.voidstart()voidvoid(package private) Future<?>(package private) Future<?>triggerGC(boolean force, boolean suspendMajor, boolean suspendMinor)
-
Field Details
-
scheduledFuture
Future<?> scheduledFuture -
gcWaitTime
final long gcWaitTime -
isForceMinorCompactionAllow
boolean isForceMinorCompactionAllow -
enableMinorCompaction
boolean enableMinorCompaction -
minorCompactionThreshold
final double minorCompactionThreshold -
minorCompactionInterval
final long minorCompactionInterval -
minorCompactionMaxTimeMillis
final long minorCompactionMaxTimeMillis -
lastMinorCompactionTime
long lastMinorCompactionTime -
isForceMajorCompactionAllow
boolean isForceMajorCompactionAllow -
enableMajorCompaction
boolean enableMajorCompaction -
majorCompactionThreshold
final double majorCompactionThreshold -
majorCompactionInterval
final long majorCompactionInterval -
majorCompactionMaxTimeMillis
long majorCompactionMaxTimeMillis -
lastMajorCompactionTime
long lastMajorCompactionTime -
entryLocationCompactionInterval
final long entryLocationCompactionInterval -
randomCompactionDelay
long randomCompactionDelay -
lastEntryLocationCompactionTime
long lastEntryLocationCompactionTime -
isForceGCAllowWhenNoSpace
final boolean isForceGCAllowWhenNoSpace -
entryLogger
-
compactor
AbstractLogCompactor compactor -
ledgerStorage
-
compacting
-
minorCompacting
-
majorCompacting
-
running
volatile boolean running -
forceGarbageCollection
-
suspendMajorCompaction
-
suspendMinorCompaction
-
garbageCollector
-
garbageCleaner
-
conf
-
ledgerDirsManager
-
throttler
-
-
Constructor Details
-
GarbageCollectorThread
public GarbageCollectorThread(ServerConfiguration conf, LedgerManager ledgerManager, LedgerDirsManager ledgerDirsManager, CompactableLedgerStorage ledgerStorage, EntryLogger entryLogger, StatsLogger statsLogger) throws IOException Create a garbage collector thread.- Parameters:
conf- Server Configuration Object.- Throws:
IOException
-
GarbageCollectorThread
public GarbageCollectorThread(ServerConfiguration conf, LedgerManager ledgerManager, LedgerDirsManager ledgerDirsManager, CompactableLedgerStorage ledgerStorage, EntryLogger entryLogger, StatsLogger statsLogger, ScheduledExecutorService gcExecutor) throws IOException Create a garbage collector thread.- Parameters:
conf- Server Configuration Object.- Throws:
IOException
-
-
Method Details
-
newExecutor
-
enableForceGC
public void enableForceGC() -
enableForceGC
public void enableForceGC(boolean forceMajor, boolean forceMinor) -
disableForceGC
public void disableForceGC() -
triggerGC
-
triggerGC
Future<?> triggerGC() -
isInForceGC
public boolean isInForceGC() -
isMajorGcSuspend
public boolean isMajorGcSuspend() -
isMinorGcSuspend
public boolean isMinorGcSuspend() -
suspendMajorGC
public void suspendMajorGC() -
resumeMajorGC
public void resumeMajorGC() -
suspendMinorGC
public void suspendMinorGC() -
resumeMinorGC
public void resumeMinorGC() -
start
public void start() -
getModInitialDelay
public long getModInitialDelay()when number of ledger's Dir are more than 1,the same of GarbageCollectorThread will do the same thing, Especially 1) deleting ledger, then SyncThread will be timed to do rocksDB compact 2) compact: entry, cost cpu. then get Mod initial Delay time to simply avoid GarbageCollectorThread working at the same time -
run
public void run() -
runWithFlags
public void runWithFlags(boolean force, boolean suspendMajor, boolean suspendMinor) -
doCompactEntryLogs
void doCompactEntryLogs(double threshold, long maxTimeMillis) throws BookieException.EntryLogMetadataMapException Compact entry logs if necessary.Compaction will be executed from low unused space to high unused space. Those entry log files whose remaining size percentage is higher than threshold would not be compacted.
-
calculateUsageIndex
int calculateUsageIndex(int numBuckets, double usage) Calculate the index for the batch based on the usage between 0 and 1.- Parameters:
numBuckets- Number of reporting buckets.usage- 0.0 - 1.0 value representing the usage of the entry log.- Returns:
- index based on the number of buckets The last bucket will have the 1.0 if added.
-
shutdown
Shutdown the garbage collector thread.- Throws:
InterruptedException- if there is an exception stopping gc thread.
-
removeEntryLog
protected boolean removeEntryLog(long entryLogId) throws BookieException.EntryLogMetadataMapException Remove entry log.- Parameters:
entryLogId- Entry Log File Id- Throws:
BookieException.EntryLogMetadataMapException
-
compactEntryLog
Compact an entry log.- Parameters:
entryLogMeta-
-
extractMetaFromEntryLogs
Method to read in all of the entry logs (those that we haven't done so yet), and find the set of ledger ID's that make up each entry log file. -
getLedgerStorage
CompactableLedgerStorage getLedgerStorage() -
getEntryLogMetaMap
EntryLogMetadataMap getEntryLogMetaMap() -
getGarbageCollectionStatus
-
isForceGCAllowWhenNoSpace
public boolean isForceGCAllowWhenNoSpace()
-