Skip to content

Commit

Permalink
superblock: remove dependency on XxHash
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Wünsche committed Apr 12, 2024
1 parent 0b27542 commit 57bd6be
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions betree/src/database/superblock.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{errors::*, StorageInfo};
use super::{errors::*, Checksum as DbChecksum, StorageInfo};
use crate::{
buffer::{Buf, BufWrite},
checksum::{Builder, State, XxHash, XxHashBuilder},
checksum::{Builder, Checksum, State},
size::StaticSize,
storage_pool::{StoragePoolLayer, NUM_STORAGE_CLASSES},
vdev::{Block, BLOCK_SIZE},
Expand All @@ -21,8 +21,8 @@ pub struct Superblock<P> {
pub(crate) tiers: [StorageInfo; NUM_STORAGE_CLASSES],
}

fn checksum(b: &[u8]) -> XxHash {
let mut state = XxHashBuilder.build();
fn checksum(b: &[u8]) -> DbChecksum {
let mut state = DbChecksum::builder().build();
state.ingest(b);
state.finish()
}
Expand All @@ -34,7 +34,7 @@ impl<P: DeserializeOwned> Superblock<P> {
/// this sequence is explicitly not part of the stability guarantees),
/// or the contained checksum doesn't match the actual checksum of the superblock.
pub fn unpack(b: &[u8]) -> Result<Superblock<P>> {
let checksum_size = XxHash::static_size();
let checksum_size = DbChecksum::static_size();
let correct_checksum = checksum(&b[..b.len() - checksum_size]);
let actual_checksum = deserialize(&b[b.len() - checksum_size..])?;
if correct_checksum != actual_checksum {
Expand Down Expand Up @@ -100,7 +100,7 @@ impl<P: Serialize> Superblock<P> {
this.magic.copy_from_slice(MAGIC);
serialize_into(&mut data, &this)?;
}
let checksum_size = XxHash::static_size();
let checksum_size = DbChecksum::static_size();
data.seek(io::SeekFrom::End(-i64::from(checksum_size as u32)))?;
let checksum = checksum(&data.as_ref()[..BLOCK_SIZE - checksum_size]);
serialize_into(&mut data, &checksum)?;
Expand Down

0 comments on commit 57bd6be

Please sign in to comment.