Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(services/rocksdb): Add scan support #2827

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions core/src/services/rocksdb/backend.rs
Expand Up @@ -110,6 +110,8 @@ impl kv::Adapter for Adapter {
Capability {
read: true,
write: true,
list: true,
blocking: true,
..Default::default()
},
)
Expand Down Expand Up @@ -138,6 +140,25 @@ impl kv::Adapter for Adapter {
fn blocking_delete(&self, path: &str) -> Result<()> {
Ok(self.db.delete(path)?)
}

async fn scan(&self, path: &str) -> Result<Vec<String>> {
self.blocking_scan(path)
}

fn blocking_scan(&self, path: &str) -> Result<Vec<String>> {
let it = self.db.prefix_iterator(path).map(|r| r.map(|(k, _v)| 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)
})?);
}

Ok(res)
}
}

impl From<rocksdb::Error> for Error {
Expand Down