Class GarbageCollectorThread

java.lang.Object
org.apache.bookkeeper.bookie.GarbageCollectorThread
All Implemented Interfaces:
Runnable

public class GarbageCollectorThread extends Object implements 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 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

      final EntryLogger entryLogger
    • compactor

    • ledgerStorage

      final CompactableLedgerStorage ledgerStorage
    • compacting

      final AtomicBoolean compacting
    • minorCompacting

      final AtomicBoolean minorCompacting
    • majorCompacting

      final AtomicBoolean majorCompacting
    • running

      volatile boolean running
    • forceGarbageCollection

      final AtomicBoolean forceGarbageCollection
    • suspendMajorCompaction

      final AtomicBoolean suspendMajorCompaction
    • suspendMinorCompaction

      final AtomicBoolean suspendMinorCompaction
    • garbageCollector

      final ScanAndCompareGarbageCollector garbageCollector
    • garbageCleaner

      final GarbageCollector.GarbageCleaner garbageCleaner
    • conf

      final ServerConfiguration conf
    • ledgerDirsManager

      final LedgerDirsManager ledgerDirsManager
    • throttler

  • Constructor Details

  • Method Details

    • newExecutor

      static ScheduledExecutorService newExecutor()
    • enableForceGC

      public void enableForceGC()
    • enableForceGC

      public void enableForceGC(boolean forceMajor, boolean forceMinor)
    • disableForceGC

      public void disableForceGC()
    • triggerGC

      Future<?> triggerGC(boolean force, boolean suspendMajor, boolean suspendMinor)
    • 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()
      Specified by:
      run in interface Runnable
    • 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.

      Throws:
      BookieException.EntryLogMetadataMapException
    • 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

      public void shutdown() throws InterruptedException
      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

      protected void compactEntryLog(EntryLogMetadata entryLogMeta)
      Compact an entry log.
      Parameters:
      entryLogMeta -
    • extractMetaFromEntryLogs

      protected void extractMetaFromEntryLogs() throws BookieException.EntryLogMetadataMapException
      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.
      Throws:
      BookieException.EntryLogMetadataMapException
    • getLedgerStorage

      CompactableLedgerStorage getLedgerStorage()
    • getEntryLogMetaMap

      EntryLogMetadataMap getEntryLogMetaMap()
    • getGarbageCollectionStatus

      public GarbageCollectionStatus getGarbageCollectionStatus()
    • isForceGCAllowWhenNoSpace

      public boolean isForceGCAllowWhenNoSpace()