Skip to content

Commit

Permalink
Fix to broken slot allocation logic. Only one slot was getting alloca…
Browse files Browse the repository at this point in the history
…ted per page. (facepalm)
  • Loading branch information
rdaum committed Dec 30, 2023
1 parent 8fcbbf0 commit 9c82e0a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions crates/db/src/tuplebox/slots/slotbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,13 @@ impl Allocator {
.binary_search_by(|(free_space, _)| free_space.cmp(&bytes));

let pid = match found {
// Exact match, highly unlikely, but possible.
Ok(entry_num) => {
let entry = self.used_pages.get_mut(entry_num).unwrap();
entry.0 -= bytes;
let entry = self.used_pages.remove(entry_num);
entry.1
}
Err(_) => {
// Out of room, need to allocate a new page.
Err(position) if position == self.used_pages.len() => {
// If we didn't find a page with enough space, then we need to allocate a new page.
if self.next_page >= self.max_pages {
return Err(SlotBoxError::BoxFull(bytes, 0));
Expand All @@ -224,6 +225,13 @@ impl Allocator {
self.used_pages.push((empty_size - bytes, pid));
pid
}
// Found a page we can split up.
Err(entry_num) => {
let entry = self.used_pages.get_mut(entry_num).unwrap();
assert!(entry.0 >= bytes);
entry.0 -= bytes;
entry.1
}
};

self.used_pages.sort_by(|a, b| a.0.cmp(&b.0));
Expand Down

0 comments on commit 9c82e0a

Please sign in to comment.