[Issue #1293] implement visibility checkpoint cache on worker node #1295
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pixels Visibility Checkpoint Mechanism
The Checkpoint mechanism in Pixels is a critical design for handling long-running transactions (LRTs) and optimizing Garbage Collection (GC) in the Retina service. It ensures that LRTs can maintain a consistent view of the data without preventing the system from reclaiming memory occupied by old visibility bitmaps.
1. Core Objectives
2. Implementation Mechanism
The implementation is primarily located in
RetinaResourceManager.javaand interacts with Trino throughPixelsOffloadDetector.java.A. Lifecycle of a Long-Running Query Checkpoint
Detection (
PixelsOffloadDetector.java):A background thread in Trino monitors active transactions. If
currentTime - startTime > threshold, it triggers an offload:Persistence (
RetinaResourceManager.java):When
registerOffload(timestamp)is called, Retina performs the following:RGVisibilityobjects in memory.BlockingQueueandcheckpointExecutorto write the bitmaps to a file in a producer-consumer pattern.RetinaUtilsgenerates a unique name:offload_<hostname>_<timestamp>.bin.pixels.retina.checkpoint.dir(typically on shared storage).Routing & Loading (
RetinaServerImpl.java&VisibilityCheckpointCache.java):queryVisibility, Retina checksoffloadedCheckpoints. If a path exists, it returns the path instead of the bitmaps.PixelsReaderreceives the path and delegates toVisibilityCheckpointCache, which downloads and parses the.binfile into a local Caffeine cache.Cleanup:
When the query commits or rolls back, Trino calls
unregisterOffload(timestamp). Retina decrements arefCountand deletes the physical file once the count reaches zero.B. System State Checkpoint (GC Checkpoint)
In addition to LRT offloading, Retina periodically runs GC:
runGC()runs everyretina.gc.intervalseconds.createCheckpoint(timestamp, CheckpointType.GC).recoverCheckpoints()scans the directory, finds the latestgc_*.binfile, and populatesrgVisibilityMap, effectively restoring the system state to the last GC point.3. Data Format (.bin File)
The checkpoint file is a flat binary format optimized for sequential reading:
totalRgsintfileIdlongrgIdintrecordNumintbitmapLenintbitmaplong[]4. Key Components Summary
PixelsOffloadDetectorRetinaResourceManagerRGVisibilityVisibilityCheckpointCacheRetinaUtils5. Distributed Consistency