Skip to content

Commit

Permalink
sharded: move Key definition to lib.rs
Browse files Browse the repository at this point in the history
We're about to use this type in more public interfaces.

TESTED=existing tests.
  • Loading branch information
pkhuong committed Sep 6, 2021
1 parent 58b2cd9 commit e5dca69
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
23 changes: 22 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,26 @@ mod sharded;
mod trigger;

pub use plain::PlainCache;
pub use sharded::Key;
pub use sharded::ShardedCache;

/// Sharded cache keys consist of a filename and two hash values. The
/// two hashes should be computed by distinct functions of the key's
/// name, and each hash function must be identical for all processes
/// that access the same sharded cache directory.
#[derive(Clone, Copy, Debug)]
pub struct Key<'a> {
pub name: &'a str,
pub hash: u64,
pub secondary_hash: u64,
}

impl<'a> Key<'a> {
/// Returns a new `Key` for this `name`, `hash`, and `secondary_hash`.
pub fn new(name: &str, hash: u64, secondary_hash: u64) -> Key {
Key {
name,
hash,
secondary_hash,
}
}
}
22 changes: 1 addition & 21 deletions src/sharded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::sync::Arc;

use crate::cache_dir::CacheDir;
use crate::trigger::PeriodicTrigger;
use crate::Key;

/// We will aim to trigger maintenance at least `MAINTENANCE_SCALE`
/// times per total capacity inserts or updates, and at least once per
Expand All @@ -29,27 +30,6 @@ const RANDOM_MULTIPLIER: u64 = 0xf2efdf1111adba6f;

const SECONDARY_RANDOM_MULTIPLIER: u64 = 0xa55e1e02718a6a47;

/// Sharded cache keys consist of a filename and two hash values. The
/// two hashes should be computed by distinct functions of the key's
/// name, and each hash function must be identical for all processes
/// that access the same sharded cache directory.
#[derive(Clone, Copy, Debug)]
pub struct Key<'a> {
pub name: &'a str,
pub hash: u64,
pub secondary_hash: u64,
}

impl<'a> Key<'a> {
pub fn new(name: &str, hash: u64, secondary_hash: u64) -> Key {
Key {
name,
hash,
secondary_hash,
}
}
}

/// A sharded cache is a hash-sharded directory of cache
/// subdirectories. Each subdirectory is managed as an
/// independent second chance cache directory.
Expand Down

0 comments on commit e5dca69

Please sign in to comment.