Package me.ahoo.cosid.segment
Class SegmentChainId.PrefetchJob
java.lang.Object
me.ahoo.cosid.segment.SegmentChainId.PrefetchJob
- All Implemented Interfaces:
Runnable,AffinityJob
- Enclosing class:
- SegmentChainId
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 Summary
ConstructorsConstructorDescriptionPrefetchJob(IdSegmentChain tailChain) Create a new prefetch job for the specified tail chain. -
Method Summary
Modifier and TypeMethodDescriptiongetJobId()Get the job ID for this prefetch job.Get the prefetch worker for this job.voidprefetch()Perform the prefetching logic.voidrun()Run the prefetch job.voidsetHungerTime(long hungerTime) Set the hunger time for this job.voidsetPrefetchWorker(PrefetchWorker prefetchWorker) Set the prefetch worker for this job.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface me.ahoo.cosid.segment.concurrent.AffinityJob
affinity, hungry
-
Constructor Details
-
PrefetchJob
Create a new prefetch job for the specified tail chain.- Parameters:
tailChain- The tail of the segment chain
-
-
Method Details
-
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:
getJobIdin interfaceAffinityJob- 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:
setHungerTimein interfaceAffinityJob- Parameters:
hungerTime- The hunger time in seconds
-
getPrefetchWorker
Get the prefetch worker for this job.- Specified by:
getPrefetchWorkerin interfaceAffinityJob- Returns:
- The prefetch worker
-
setPrefetchWorker
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:
setPrefetchWorkerin interfaceAffinityJob- 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.
-
prefetch
public void prefetch()Perform the prefetching logic.This method implements the core prefetching algorithm, which:
- Determines current demand based on hunger signals
- Adjusts prefetch distance based on demand
- Identifies the available head of the chain
- Calculates the gap to the tail
- Prefetches segments if needed
-