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 d31ff742e fix(services/rocksdb): Make sure return key starts with
input path (#2828)
d31ff742e is described below
commit d31ff742e4b8e3af45ce93b7d5120f7170e69a4a
Author: Xuanwo <[email protected]>
AuthorDate: Wed Aug 9 15:45:12 2023 +0800
fix(services/rocksdb): Make sure return key starts with input path (#2828)
Signed-off-by: Xuanwo <[email protected]>
---
core/src/services/rocksdb/backend.rs | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/core/src/services/rocksdb/backend.rs
b/core/src/services/rocksdb/backend.rs
index 9eaeb748a..e47c622b6 100644
--- a/core/src/services/rocksdb/backend.rs
+++ b/core/src/services/rocksdb/backend.rs
@@ -145,16 +145,19 @@ impl kv::Adapter for Adapter {
self.blocking_scan(path)
}
+ /// TODO: we only need key here.
fn blocking_scan(&self, path: &str) -> Result<Vec<String>> {
- let it = self.db.prefix_iterator(path).map(|r| r.map(|(k, _v)| k));
+ let it = self.db.prefix_iterator(path).map(|r| r.map(|(k, _)| k));
let mut res = Vec::default();
- for i in it {
- let bs = i?.to_vec();
- res.push(String::from_utf8(bs).map_err(|err| {
- Error::new(ErrorKind::Unexpected, "store key is not valid
utf-8 string")
- .set_source(err)
- })?);
+ for key in it {
+ let key = key?;
+ 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) {
+ continue;
+ }
+ res.push(key.to_string());
}
Ok(res)