Struct jasmine_db::ClockCache
source · [−]pub struct ClockCache { /* private fields */ }
Expand description
A cache for storing arbitrary length data, the cache size can grow and shrink with page granularity
There is only one major API: probe_entry()
, which either returns an empty entry or an entry that should be evicted (to accommodate the new value).
Remove/add segment can only be invoked by one thread at a time.
Implementations
sourceimpl ClockCache
impl ClockCache
pub fn new(initial_cache_size: usize, entry_size: usize) -> Self
sourcepub unsafe fn add_segment(&self, ptr: *mut u8)
pub unsafe fn add_segment(&self, ptr: *mut u8)
only one thread at any time should call this function
Safety
The ptr must be valid and at least SEGMENT_SIZE
(default 4096) bytes long.
The only safe and stable way to get a ptr is to call Segment::alloc()
.
sourcepub fn remove_segment(&self) -> Option<ObsoleteSegment<'static>>
pub fn remove_segment(&self) -> Option<ObsoleteSegment<'static>>
The caller need to iterate all the entries in the segment and evict them As long as the lock guard is held, not other thread can promote entry to this segment
Returns None when all segments in the cache are removed
sourcepub fn probe_entry(&self) -> Option<&EntryMeta>
pub fn probe_entry(&self) -> Option<&EntryMeta>
Returns whether we find a cached location. If yes, returns the cached location.
The caller need to check the reserved bit, if not set, this entry need to be evicted to the storage
Unless the reserved bit is set (the entry is empty), it is the caller’s responsibility to serialize the concurrent read/write.
There are two cases this function may return None:
- The cache is empty (due to
remove_segment
) - The all the entries are referenced within the probe_len (default to 16)
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for ClockCache
impl Send for ClockCache
impl Sync for ClockCache
impl Unpin for ClockCache
impl !UnwindSafe for ClockCache
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more