mstar.engine.resources.kv.prefix_index#
The prefix index: which cached page holds which key, and which to drop first.
Inserting makes the index a page’s second owner, so evicting releases that one reference and the page reaches the free list only once no live request holds it too. Leaves are ordered by a clock that ticks on every insert and every matching lookup. A hit re-stamps a page without pushing it again, so a leaf keeps one heap entry however often it is read, and an entry that surfaces under an older stamp is pushed back under the page’s own.
Every caller holds the manager’s lock, so none of this takes one of its own.
Classes
|
- class mstar.engine.resources.kv.prefix_index.PrefixIndex(arena)[source]#
Bases:
object- Parameters:
arena (PageArena)
- assert_evictable()[source]#
Check that evict, run on a copy of the index and the owner counts, frees every page in the evictable set.
- Return type:
None
- evict(n, spare=None)[source]#
Drop the oldest leaves the index alone holds, until
nare free. Whenspareaccepts a leaf’s key, that leaf is dropped only once no other leaf is left.A leaf a request or a lease also holds is passed over and put back: dropping it would free nothing and lose an entry that is still good. Returns the keys of the pages that reached the free list.
- evictable()[source]#
Return the live set of pages evict could free. Callers read it and don’t keep it.
A page only the index holds is out of reach while a page below it is held, since eviction takes leaves only.
- insert(key, page, parent=None)[source]#
Name
pagebykeyunderparent; the first writer wins. When the arena reports to this index and the index alone holdsparent,pageis filed with no parent. Filed underparent, a heldpagewould keep evict from freeingparent, which the pool counts as evictable.
- insert_run(keys, pages, parent)[source]#
Name
pagesbykeys, each under the one before and the first underparent. A key already indexed keeps its page, and the next key goes under that page. Returns how many pages were inserted.
Called when
pagegains or loses its one owner besides the index.