Class SegmentChainId.PrefetchJob

java.lang.Object
me.ahoo.cosid.segment.SegmentChainId.PrefetchJob
All Implemented Interfaces:
Runnable, AffinityJob
Enclosing class:
SegmentChainId

public class SegmentChainId.PrefetchJob extends Object implements AffinityJob
Background prefetch job for segment chain ID generation.

This job runs in the background to prefetch segments before they are needed, reducing latency during ID generation. It dynamically adjusts the prefetch distance based on demand patterns.

  • Constructor Details

    • PrefetchJob

      public PrefetchJob(IdSegmentChain tailChain)
      Create a new prefetch job for the specified tail chain.
      Parameters:
      tailChain - The tail of the segment chain
  • Method Details

    • getJobId

      public String getJobId()
      Get the job ID for this prefetch job.

      The job ID is used to identify this job in the prefetch worker system.

      Specified by:
      getJobId in interface AffinityJob
      Returns:
      The job ID
    • setHungerTime

      public void setHungerTime(long hungerTime)
      Set the hunger time for this job.

      This method is called when the system signals high demand, indicating that prefetching should be more aggressive.

      Specified by:
      setHungerTime in interface AffinityJob
      Parameters:
      hungerTime - The hunger time in seconds
    • getPrefetchWorker

      public PrefetchWorker getPrefetchWorker()
      Get the prefetch worker for this job.
      Specified by:
      getPrefetchWorker in interface AffinityJob
      Returns:
      The prefetch worker
    • setPrefetchWorker

      public void setPrefetchWorker(PrefetchWorker prefetchWorker)
      Set the prefetch worker for this job.

      This method is called by the prefetch worker executor when assigning a worker to this job.

      Specified by:
      setPrefetchWorker in interface AffinityJob
      Parameters:
      prefetchWorker - The prefetch worker
    • run

      public void run()
      Run the prefetch job.

      This method is called by the prefetch worker to execute the prefetching logic.

      Specified by:
      run in interface Runnable
    • prefetch

      public void prefetch()
      Perform the prefetching logic.

      This method implements the core prefetching algorithm, which:

      1. Determines current demand based on hunger signals
      2. Adjusts prefetch distance based on demand
      3. Identifies the available head of the chain
      4. Calculates the gap to the tail
      5. Prefetches segments if needed