Skip to content

Commit

Permalink
feat: file cache skeleton (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCroxx authored Jun 1, 2022
1 parent 4bc46a1 commit 3e6018c
Show file tree
Hide file tree
Showing 5 changed files with 401 additions and 9 deletions.
40 changes: 40 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ aws-sdk-s3 = "0.8"
aws-smithy-http = "0.38"
aws-smithy-types = "0.38"
aws-types = { version = "0.8", features = ["hardcoded-credentials"] }
bitvec = "1"
bytes = "1"
bytesize = "1.1.0"
clap = { version = "3.1.6", features = ["derive"] }
Expand All @@ -27,7 +28,7 @@ lazy_static = "1.4.0"
libc = "0.2"
lz4 = "1.23.1"
moka = { version = "0.7", features = ["future"] }
nix = { version = "0.24.1", features = ["fs", "aio"] }
nix = { version = "0.24.1", features = ["fs", "aio", "uio"] }
parking_lot = "0.12"
prometheus = "0.13.0"
rand = "0.8.5"
Expand Down
13 changes: 13 additions & 0 deletions storage/src/file_cache/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ impl<const ALIGN: usize, const SMOOTH: usize, const DEFAULT: usize>
self.write_at(src, self.len)
}

pub fn reserve(&mut self, capacity: usize) {
if capacity > self.capacity {
self.grow_at(capacity);
}
}

pub fn resize(&mut self, len: usize) {
if len > self.capacity {
self.grow_at(len);
}
self.len = len;
}

pub fn slice(&self, range: impl RangeBounds<usize>) -> &[u8] {
let (start, end) = self.bounds(range);
let slice = unsafe { std::slice::from_raw_parts(self.ptr.add(start), end - start) };
Expand Down
4 changes: 4 additions & 0 deletions storage/src/file_cache/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ pub enum Error {
NixError(#[from] nix::errno::Errno),
#[error("join error: {0}")]
JoinError(#[from] tokio::task::JoinError),
#[error("magic not match")]
MagicNotMatch,
#[error("invalid version")]
InvalidVersion(u32),
}

pub type Result<T> = core::result::Result<T, Error>;
Loading

0 comments on commit 3e6018c

Please sign in to comment.