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

Code cleanup #862

Merged
merged 3 commits into from
Sep 7, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Resolve TODO
  • Loading branch information
cberner committed Sep 7, 2024
commit 7f40fa1631d408f5f96186b57f706dc22d3f8cbc
15 changes: 8 additions & 7 deletions src/db.rs
Original file line number Diff line number Diff line change
@@ -518,7 +518,9 @@ impl Database {
FreedPageList::fixed_width(),
mem.clone(),
)?;
mem.mark_pages_allocated(freed_pages_iter, false)?;
for page in freed_pages_iter {
mem.mark_page_allocated(page?);
}
}

let freed_table: ReadOnlyTable<FreedTableKey, FreedPageList<'static>> = ReadOnlyTable::new(
@@ -530,11 +532,9 @@ impl Database {
)?;
for result in freed_table.range::<FreedTableKey>(..)? {
let (_, freed_page_list) = result?;
let mut freed_page_list_as_vec = vec![];
for i in 0..freed_page_list.value().len() {
freed_page_list_as_vec.push(Ok(freed_page_list.value().get(i)));
mem.mark_page_allocated(freed_page_list.value().get(i));
}
mem.mark_pages_allocated(freed_page_list_as_vec.into_iter(), false)?;
}

Ok(())
@@ -569,7 +569,9 @@ impl Database {
// Repair the allocator state
// All pages in the master table
let master_pages_iter = AllPageNumbersBtreeIter::new(root, None, None, mem.clone())?;
mem.mark_pages_allocated(master_pages_iter, false)?;
for page in master_pages_iter {
mem.mark_page_allocated(page?);
}

// Iterate over all other tables
let iter: BtreeRangeIter<&str, InternalTableDefinition> =
@@ -579,8 +581,7 @@ impl Database {
for entry in iter {
let definition = entry?.value();
definition.visit_all_pages(mem.clone(), |path| {
// TODO: simplify mark_pages_allocated()
mem.mark_pages_allocated([Ok(path.page_number())].into_iter(), false)?;
mem.mark_page_allocated(path.page_number());
Ok(())
})?;
}
23 changes: 4 additions & 19 deletions src/tree_store/page_store/page_manager.rs
Original file line number Diff line number Diff line change
@@ -356,26 +356,11 @@ impl TransactionalMemory {
Ok(())
}

pub(crate) fn mark_pages_allocated(
&self,
allocated_pages: impl Iterator<Item = Result<PageNumber>>,
allow_duplicates: bool,
) -> Result<()> {
pub(crate) fn mark_page_allocated(&self, page_number: PageNumber) {
let mut state = self.state.lock().unwrap();

for page_number in allocated_pages {
let page_number = page_number?;
let region_index = page_number.region;
let allocator = state.get_region_mut(region_index);
if allow_duplicates
&& allocator.is_allocated(page_number.page_index, page_number.page_order)
{
continue;
}
allocator.record_alloc(page_number.page_index, page_number.page_order);
}

Ok(())
let region_index = page_number.region;
let allocator = state.get_region_mut(region_index);
allocator.record_alloc(page_number.page_index, page_number.page_order);
}

fn write_header(&self, header: &DatabaseHeader, swap_primary: bool) -> Result {
Loading