Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: rename lookup to lookup_blocking #631

Open
wants to merge 1 commit into
base: rh-move-overflow
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions nomt/src/beatree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl Tree {
})
}

/// Lookup a key in the btree.
/// Lookup a key in the btree. This blocks the current thread.
pub fn lookup(&self, key: Key) -> Option<Vec<u8>> {
let shared = self.shared.read();

Expand All @@ -148,7 +148,7 @@ impl Tree {
}

// Finally, look up in the btree.
ops::lookup(
ops::lookup_blocking(
key,
&shared.bbn_index,
&shared.leaf_cache,
Expand Down Expand Up @@ -574,7 +574,11 @@ impl ReadTransaction {
};

match self.load_leaf_async(leaf_pn, io_handle, user_data) {
Ok(leaf) => Ok(ops::finish_lookup(key, &leaf.inner, &self.inner.leaf_store)),
Ok(leaf) => Ok(ops::finish_lookup_blocking(
key,
&leaf.inner,
&self.inner.leaf_store,
)),
Err(pending) => Err(AsyncLookup(key, pending)),
}
}
Expand Down Expand Up @@ -631,7 +635,7 @@ impl AsyncLookup {
/// Calling this with the wrong page will likely lead to panics or bugs in the future.
pub fn finish(self, page: FatPage) -> Option<Vec<u8>> {
let leaf = self.1.finish_inner(page);
ops::finish_lookup(self.0, &leaf, &self.1.read_tx.leaf_store)
ops::finish_lookup_blocking(self.0, &leaf, &self.1.read_tx.leaf_store)
}
}

Expand Down
16 changes: 10 additions & 6 deletions nomt/src/beatree/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,23 @@ pub fn partial_lookup(key: Key, bbn_index: &Index) -> Option<PageNumber> {
search_branch(&branch, key.clone()).map(|(_, leaf_pn)| leaf_pn)
}

/// Finish looking up a key in a leaf node.
pub fn finish_lookup(key: Key, leaf: &LeafNode, leaf_store: &StoreReader) -> Option<Vec<u8>> {
/// Finish looking up a key in a leaf node using blocking I/O.
pub fn finish_lookup_blocking(
key: Key,
leaf: &LeafNode,
leaf_store: &StoreReader,
) -> Option<Vec<u8>> {
leaf.get(&key).map(|(v, is_overflow)| {
if is_overflow {
overflow::read(v, leaf_store)
overflow::read_blocking(v, leaf_store)
} else {
v.to_vec()
}
})
}

/// Lookup a key in the btree.
pub fn lookup(
/// Lookup a key in the btree using blocking I/O.
pub fn lookup_blocking(
key: Key,
bbn_index: &Index,
leaf_cache: &LeafCache,
Expand All @@ -66,7 +70,7 @@ pub fn lookup(
}
};

Ok(finish_lookup(key, &leaf, leaf_store))
Ok(finish_lookup_blocking(key, &leaf, leaf_store))
}

/// Binary search a branch node for the child node containing the key. This returns the last child
Expand Down
12 changes: 7 additions & 5 deletions nomt/src/beatree/ops/overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ fn needed_pages(size: usize) -> usize {
(size + BODY_SIZE - 1) / BODY_SIZE
}

/// Read a large value from pages referenced by an overflow cell.
pub fn read(cell: &[u8], leaf_reader: &StoreReader) -> Vec<u8> {
/// Read a large value from pages referenced by an overflow cell using blocking I/O.
pub fn read_blocking(cell: &[u8], leaf_reader: &StoreReader) -> Vec<u8> {
let (value_size, _, cell_pages) = decode_cell(cell);
let total_pages = total_needed_pages(value_size);

Expand All @@ -182,7 +182,7 @@ pub fn read(cell: &[u8], leaf_reader: &StoreReader) -> Vec<u8> {

for i in 0..total_pages {
let page = leaf_reader.query(page_numbers[i]);
let (page_pns, bytes) = read_page(&page);
let (page_pns, bytes) = parse_page(&page);
page_numbers.extend(page_pns);
value.extend(bytes);
}
Expand All @@ -194,6 +194,8 @@ pub fn read(cell: &[u8], leaf_reader: &StoreReader) -> Vec<u8> {
}

/// Iterate all pages related to an overflow cell and push onto a free-list.
///
/// This only logically deletes the pages.
pub fn delete(cell: &[u8], leaf_reader: &StoreReader, freed: &mut Vec<PageNumber>) {
let (value_size, _, cell_pages) = decode_cell(cell);
let total_pages = total_needed_pages(value_size);
Expand All @@ -203,7 +205,7 @@ pub fn delete(cell: &[u8], leaf_reader: &StoreReader, freed: &mut Vec<PageNumber

for i in 0..total_pages {
let page = leaf_reader.query(freed[start + i]);
let (page_pns, bytes) = read_page(&page);
let (page_pns, bytes) = parse_page(&page);
freed.extend(page_pns);

// stop at the first page containing value data. no more pages will have more
Expand All @@ -216,7 +218,7 @@ pub fn delete(cell: &[u8], leaf_reader: &StoreReader, freed: &mut Vec<PageNumber
assert_eq!(freed.len() - start, total_pages);
}

fn read_page<'a>(page: &'a FatPage) -> (impl Iterator<Item = PageNumber> + 'a, &'a [u8]) {
fn parse_page<'a>(page: &'a FatPage) -> (impl Iterator<Item = PageNumber> + 'a, &'a [u8]) {
let n_pages = u16::from_le_bytes(page[0..2].try_into().unwrap()) as usize;
let n_bytes = u16::from_le_bytes(page[2..4].try_into().unwrap()) as usize;

Expand Down
Loading