This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
The following commit(s) were added to refs/heads/main by this push:
new 7f3023240a refactor(services/rocksdb): Impl parse_error instead of
From<Error> (#3903)
7f3023240a is described below
commit 7f3023240a31411db7c8908698854e7efb13d4c0
Author: Suyan <[email protected]>
AuthorDate: Wed Jan 3 17:53:47 2024 +0800
refactor(services/rocksdb): Impl parse_error instead of From<Error> (#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]>
---
core/src/services/rocksdb/backend.rs | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/core/src/services/rocksdb/backend.rs
b/core/src/services/rocksdb/backend.rs
index b60d4350d5..d4fec8b24e 100644
--- a/core/src/services/rocksdb/backend.rs
+++ b/core/src/services/rocksdb/backend.rs
@@ -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<()> {
@@ -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<()> {
@@ -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>> {
@@ -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) {
@@ -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)
}