Skip to content

Commit

Permalink
storage: move cas db from util into storage
Browse files Browse the repository at this point in the history
Move cas db from util into storage.

Signed-off-by: Jiang Liu <[email protected]>
  • Loading branch information
jiangliu committed Nov 29, 2023
1 parent 02aeafb commit 272f568
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 36 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.

1 change: 1 addition & 0 deletions storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ libc = "0.2"
log = "0.4.8"
nix = "0.24"
reqwest = { version = "0.11.14", features = ["blocking", "json"], optional = true }
rusqlite = { version = "0.30", features = ["bundled"] }
serde = { version = "1.0.110", features = ["serde_derive", "rc"] }
serde_json = "1.0.53"
sha1 = { version = "0.10.5", optional = true }
Expand Down
38 changes: 5 additions & 33 deletions utils/src/cas.rs → storage/src/cache/dedup/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,13 @@
//
// SPDX-License-Identifier: Apache-2.0

use std::fmt::{self, Display, Formatter};
use std::io::Error;
#![allow(unused)]

use std::path::Path;

use rusqlite::{Connection, DropBehavior, OptionalExtension, Transaction};

/// Error codes related to local cas.
#[derive(Debug)]
pub enum CasError {
Io(Error),
Db(rusqlite::Error),
}

impl Display for CasError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}

impl std::error::Error for CasError {}

impl From<rusqlite::Error> for CasError {
fn from(e: rusqlite::Error) -> Self {
CasError::Db(e)
}
}

impl From<Error> for CasError {
fn from(e: Error) -> Self {
CasError::Io(e)
}
}

/// Specialized `Result` for local cas.
type Result<T> = std::result::Result<T, CasError>;
use super::Result;

pub struct CasDb {
conn: Connection,
Expand Down Expand Up @@ -206,7 +178,7 @@ impl CasDb {
let tran = self.begin_transaction()?;
for chunk in chunks {
match Self::get_blob_id_with_tx(&tran, &chunk.2) {
Err(e) => return Err(e.into()),
Err(e) => return Err(e),
Ok(id) => {
if let Err(e) = tran.execute(sql, (&chunk.0, &chunk.1, id)) {
return Err(e.into());
Expand All @@ -224,7 +196,7 @@ impl CasDb {

let tran = self.begin_transaction()?;
match Self::get_blob_id_with_tx(&tran, blob_id) {
Err(e) => return Err(e.into()),
Err(e) => return Err(e),
Ok(id) => {
if let Err(e) = tran.execute(sql, (chunk_id, chunk_offset, id)) {
return Err(e.into());
Expand Down
38 changes: 38 additions & 0 deletions storage/src/cache/dedup/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (C) 2022-2023 Alibaba Cloud. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0

use std::fmt::{self, Display, Formatter};
use std::io::Error;

mod db;

/// Error codes related to local cas.
#[derive(Debug)]
pub enum CasError {
Io(Error),
Db(rusqlite::Error),
}

impl Display for CasError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}

impl std::error::Error for CasError {}

impl From<rusqlite::Error> for CasError {
fn from(e: rusqlite::Error) -> Self {
CasError::Db(e)
}
}

impl From<Error> for CasError {
fn from(e: Error) -> Self {
CasError::Io(e)
}
}

/// Specialized `Result` for local cas.
type Result<T> = std::result::Result<T, CasError>;
1 change: 1 addition & 0 deletions storage/src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use crate::utils::{alloc_buf, check_digest};
use crate::{StorageResult, RAFS_MAX_CHUNK_SIZE};

mod cachedfile;
mod dedup;
mod dummycache;
mod filecache;
#[cfg(target_os = "linux")]
Expand Down
1 change: 0 additions & 1 deletion utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ libc = "0.2"
log = "0.4"
lz4-sys = "1.9.4"
lz4 = "1.24.0"
rusqlite = { version = "0.30", features = ["bundled"] }
openssl = { version = "0.10.48", features = ["vendored"], optional = true }
serde = { version = ">=1.0.27", features = ["serde_derive", "rc"] }
serde_json = ">=1.0.9"
Expand Down
1 change: 0 additions & 1 deletion utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub use self::reader::*;
pub use self::types::*;

pub mod async_helper;
pub mod cas;
pub mod compact;
pub mod compress;
#[cfg(feature = "encryption")]
Expand Down

0 comments on commit 272f568

Please sign in to comment.