Commit 6ca94641 by tglman

fixed size calculation for content, now consider header

parent 9a16be60
Pipeline #19157929 passed with stage
......@@ -299,7 +299,7 @@ impl PersyImpl {
pub fn insert_record(&self, tx: &mut Transaction, segment: &str, rec: &Vec<u8>) -> PRes<RecRef> {
let (in_tx, segment_id) = self.check_segment_tx(tx, &segment.into())?;
let len = rec.len();
let allocation_exp = exp_from_size((len + 8) as u64);
let allocation_exp = exp_from_content_size(len as u64);
let ref allocator = self.allocator;
let ref address = self.address;
let ref journal = self.journal;
......@@ -407,7 +407,7 @@ impl PersyImpl {
let ref journal = self.journal;
if let Some(old) = self.read_ref(tx, &segment.into(), rec_ref)? {
let len = rec.len();
let allocation_exp = exp_from_size((len + 8) as u64);
let allocation_exp = exp_from_content_size(len as u64);
let page = allocator.allocate(allocation_exp)?;
tx.add_update(journal, old.2, &rec_ref, page, old.0, old.1)?;
{
......@@ -466,11 +466,13 @@ impl PersyImpl {
}
fn exp_from_size(size: u64) -> u8 {
fn exp_from_content_size(size: u64) -> u8 {
// content + size + page_header
let final_size = size + 8 + 2;
// Should be there a better way, so far is ok.
let mut res: u8 = 1;
loop {
if size < (1 << res) {
if final_size < (1 << res) {
return res;
}
res += 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment