Files
ldm0 0099465abc feat(parkable-image): add managed encoded image parking
Adopt completed image buffers, protect readers with snapshots, and park encoded bytes into one disk extent with a reusable backup. Keep resident and parked registries separate, expose owner-driven deadlines and force parking, and synchronize notifications with a short-lock waiting flag. Include lifecycle, concurrency, scheduling, and failure regressions with documentation and runnable examples.
2026-09-21 16:47:19 +08:00

31 lines
1.1 KiB
Rust

//! Show that snapshots pin synthetic image bytes, but cloned image handles do not.
//!
//! Run with `cargo run -p moli-parkable-image --example reader_leases`.
use moli_disk_pool::DiskPool;
use moli_parkable_image::{ParkableImageManager, ParkableImagePolicy};
fn main() -> std::io::Result<()> {
let manager =
ParkableImageManager::new(Some(DiskPool::new(None)?), ParkableImagePolicy::default());
let image = manager.from_frozen_bytes(vec![7; 4096]);
let other_handle = image.clone();
assert!(image.shares_storage_with(&other_handle));
let first = image.snapshot()?;
let second = first.clone();
manager.force_park_images();
assert_eq!(manager.diagnostics().parked_count, 0);
drop(first);
manager.force_park_images();
assert_eq!(manager.diagnostics().parked_count, 0); // One reader remains.
drop(second);
manager.force_park_images();
assert_eq!(manager.diagnostics().parked_count, 1);
assert_eq!(other_handle.retained_memory_bytes(), 0);
println!("Released both snapshot leases and parked the image with another handle still alive.");
Ok(())
}