Bedrock.DataPlane.Materializer.Olivine.Index.Tree (bedrock v0.5.2)
View SourceTree operations for the Olivine storage driver.
Structure
The tree is a gb_trees structure with:
- Key: Page's
last_key(rightmost key in page) - Value:
page_id(no first_key needed) - Ordering: Sorted by
last_keyfor efficient range queries - Coverage: Pages cover the entire keyspace with no gaps
Key Operations
page_for_key/2: Find page containing a specific keyadd_page_to_tree/2: Add page to tree structureremove_page_from_tree/2: Remove page from tree structure
No Gaps Design
Every point in the keyspace belongs to exactly one page:
- Page 0 starts at
<<>>(empty binary) - Each page ends at its
last_key - Next page implicitly starts after previous page's
last_key - Final page extends to
<<0xFF, 0xFF>>(infinity marker)
Summary
Functions
Updates the interval tree by adding a new page range.
Builds a page tree from a page map by adding each page to an empty tree.
Finds the page that contains a specific key. With no gaps, every key maps to exactly one page. Uses gb_trees iterator for efficiency.
Updates the interval tree by removing a page range.
Updates a page's position in the tree by removing the old range and adding the new range. Only updates if the last_key actually changed for efficiency.
Types
@type page() :: Bedrock.DataPlane.Materializer.Olivine.Index.Page.t()
@type page_id() :: Bedrock.DataPlane.Materializer.Olivine.Index.Page.id()
@type t() :: :gb_trees.tree()
Functions
Updates the interval tree by adding a new page range.
Empty pages are only added to the tree if they are page 0 (the leftmost page), which is always present and covers the beginning of the keyspace.
Builds a page tree from a page map by adding each page to an empty tree.
@spec page_for_key(t(), Bedrock.key()) :: page_id()
Finds the page that contains a specific key. With no gaps, every key maps to exactly one page. Uses gb_trees iterator for efficiency.
Tree structure: key = last_key, value = page_id
When a key is beyond all pages in the tree, returns page 0 (which acts as the catch-all page extending to infinity).
Updates the interval tree by removing a page range.
Empty pages are only removed from the tree if they are page 0.
Updates a page's position in the tree by removing the old range and adding the new range. Only updates if the last_key actually changed for efficiency.