Skip to content

Commit

Permalink
refactor(services/rocksdb): Impl parse_error instead of From<Error> (#…
Browse files Browse the repository at this point in the history
…3903)

* refactor(services/rocksdb): Impl parse_error instead of From<Error>

Signed-off-by: suyanhanx <[email protected]>

* make clippy happy

Signed-off-by: suyanhanx <[email protected]>

---------

Signed-off-by: suyanhanx <[email protected]>
  • Loading branch information
suyanhanx authored Jan 3, 2024
1 parent 43ad925 commit 7f30232
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions core/src/services/rocksdb/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl kv::Adapter for Adapter {
}

fn blocking_get(&self, path: &str) -> Result<Option<Vec<u8>>> {
Ok(self.db.get(path)?)
self.db.get(path).map_err(parse_rocksdb_error)
}

async fn set(&self, path: &str, value: &[u8]) -> Result<()> {
Expand All @@ -149,7 +149,7 @@ impl kv::Adapter for Adapter {
}

fn blocking_set(&self, path: &str, value: &[u8]) -> Result<()> {
Ok(self.db.put(path, value)?)
self.db.put(path, value).map_err(parse_rocksdb_error)
}

async fn delete(&self, path: &str) -> Result<()> {
Expand All @@ -162,7 +162,7 @@ impl kv::Adapter for Adapter {
}

fn blocking_delete(&self, path: &str) -> Result<()> {
Ok(self.db.delete(path)?)
self.db.delete(path).map_err(parse_rocksdb_error)
}

async fn scan(&self, path: &str) -> Result<Vec<String>> {
Expand All @@ -180,7 +180,7 @@ impl kv::Adapter for Adapter {
let mut res = Vec::default();

for key in it {
let key = key?;
let key = key.map_err(parse_rocksdb_error)?;
let key = String::from_utf8_lossy(&key);
// FIXME: it's must a bug that rocksdb returns key that not start with path.
if !key.starts_with(path) {
Expand All @@ -197,8 +197,6 @@ impl kv::Adapter for Adapter {
}
}

impl From<rocksdb::Error> for Error {
fn from(e: rocksdb::Error) -> Self {
Error::new(ErrorKind::Unexpected, "got rocksdb error").set_source(e)
}
fn parse_rocksdb_error(e: rocksdb::Error) -> Error {
Error::new(ErrorKind::Unexpected, "got rocksdb error").set_source(e)
}

0 comments on commit 7f30232

Please sign in to comment.