This repository has been archived by the owner on Aug 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
93 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use crate::kernel::Storage; | ||
use crate::KernelError; | ||
use async_trait::async_trait; | ||
use bytes::Bytes; | ||
use core::slice::SlicePattern; | ||
use std::path::PathBuf; | ||
|
||
#[derive(Debug)] | ||
pub struct RocksdbStorage { | ||
data_base: rocksdb::DB, | ||
} | ||
|
||
#[async_trait] | ||
impl Storage for RocksdbStorage { | ||
#[inline] | ||
fn name() -> &'static str | ||
where | ||
Self: Sized, | ||
{ | ||
"Rocksdb" | ||
} | ||
|
||
#[inline] | ||
async fn open(path: impl Into<PathBuf> + Send) -> crate::kernel::KernelResult<Self> { | ||
let db = rocksdb::DB::open_default(path.into())?; | ||
|
||
Ok(RocksdbStorage { data_base: db }) | ||
} | ||
|
||
#[inline] | ||
async fn flush(&self) -> crate::kernel::KernelResult<()> { | ||
let _ignore = self.data_base.flush()?; | ||
Ok(()) | ||
} | ||
|
||
#[inline] | ||
async fn set(&self, key: Bytes, value: Bytes) -> crate::kernel::KernelResult<()> { | ||
let _ignore = self.data_base.put(key.as_slice(), value.to_vec())?; | ||
Ok(()) | ||
} | ||
|
||
#[inline] | ||
async fn get(&self, key: &[u8]) -> crate::kernel::KernelResult<Option<Bytes>> { | ||
match self.data_base.get(key)? { | ||
None => Ok(None), | ||
Some(i_vec) => Ok(Some(Bytes::from(i_vec.to_vec()))), | ||
} | ||
} | ||
|
||
#[inline] | ||
async fn remove(&self, key: &[u8]) -> crate::kernel::KernelResult<()> { | ||
match self.data_base.delete(key) { | ||
Ok(_) => Ok(()), | ||
Err(e) => Err(KernelError::RocksdbErr(e)), | ||
} | ||
} | ||
|
||
#[inline] | ||
async fn size_of_disk(&self) -> crate::kernel::KernelResult<u64> { | ||
unimplemented!("Rocksdb does not support size_of_disk()") | ||
} | ||
|
||
#[inline] | ||
async fn len(&self) -> crate::kernel::KernelResult<usize> { | ||
unimplemented!("Rocksdb does not support len()") | ||
} | ||
|
||
#[inline] | ||
async fn is_empty(&self) -> bool { | ||
unimplemented!("Rocksdb does not support is_empty()") | ||
} | ||
} |