Skip to content

Commit

Permalink
Use ShardRouter instead of BTreeMap, which locks only the relevant sh…
Browse files Browse the repository at this point in the history
…ard instead of the whole map
  • Loading branch information
tomerfiliba committed Aug 21, 2024
1 parent 91e7835 commit a34750a
Show file tree
Hide file tree
Showing 10 changed files with 835 additions and 648 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "candystore"
version = "0.3.0"
version = "0.3.1"
edition = "2021"
license = "Apache-2.0"
keywords = ["key-value", "database", "persistent", "store", "rocksdb"]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ for res in db.iter_list("mylist") {

## Notes
* The file format is not yet stable
* Requires nightly (for `simd_itertools` and BTree cursors), uses very little `unsafe` (required due to `mmap`)
* Requires nightly (for `simd_itertools`), uses very little `unsafe` (required due to `mmap`)

## Roadmap
* Distributed protocol based on file locks (meant to run on a shared network folder)
Expand Down
21 changes: 9 additions & 12 deletions src/hashing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::anyhow;
use siphasher::sip128::{Hash128, SipHasher24};

use crate::{CandyError, Result};
use crate::Result;

#[derive(Debug, Clone, Copy)]
pub struct HashSeed([u8; 16]);
Expand All @@ -11,15 +10,13 @@ pub struct HashSeed([u8; 16]);
impl HashSeed {
pub const LEN: usize = size_of::<Self>();

pub fn new(bytes: [u8; Self::LEN]) -> Self {
Self(bytes)
}

/// Construct a HashSeed from the given byte buffer (must be 16 bytes in length)
pub fn new<B: AsRef<[u8]> + ?Sized>(key: &B) -> Result<Self> {
let key = key.as_ref();
if key.len() != Self::LEN {
return Err(anyhow!(CandyError::WrongHashSeedLength));
}
let mut bytes = [0u8; Self::LEN];
bytes.copy_from_slice(&key);
Ok(Self(bytes))
pub fn from_buf<B: AsRef<[u8]> + ?Sized>(key: &B) -> Result<Self> {
Ok(Self(key.as_ref().try_into()?))
}
}

Expand Down Expand Up @@ -97,9 +94,9 @@ impl PartedHash {
fn test_parted_hash() -> Result<()> {
use bytemuck::{bytes_of, from_bytes};

HashSeed::new("12341234123412341").expect_err("shouldn't work");
HashSeed::from_buf("12341234123412341").expect_err("shouldn't work");

let seed = HashSeed::new("aaaabbbbccccdddd")?;
let seed = HashSeed::from_buf("aaaabbbbccccdddd")?;

let h1 = PartedHash::new(&seed, b"hello world");
assert_eq!(h1.0, 13445180190757400308,);
Expand Down
Loading

0 comments on commit a34750a

Please sign in to comment.