You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2023/05/08 04:23:58 UTC
[incubator-opendal] branch main updated: feat(services/memory): migrate service memory (#2229)
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 69a8e4ee feat(services/memory): migrate service memory (#2229)
69a8e4ee is described below
commit 69a8e4eed29ede82c64780347f6853f3e29f4071
Author: Chojan Shang <ps...@apache.org>
AuthorDate: Mon May 8 12:23:55 2023 +0800
feat(services/memory): migrate service memory (#2229)
* feat(services/memory): migrate service memory
Signed-off-by: Chojan Shang <ps...@apache.org>
* docs(typed_kv): update capabilities
Signed-off-by: Chojan Shang <ps...@apache.org>
---------
Signed-off-by: Chojan Shang <ps...@apache.org>
---
core/src/services/dashmap/backend.rs | 8 +++----
core/src/services/memory/backend.rs | 42 ++++++++++++++++--------------------
core/src/services/moka/backend.rs | 10 ++++-----
3 files changed, 26 insertions(+), 34 deletions(-)
diff --git a/core/src/services/dashmap/backend.rs b/core/src/services/dashmap/backend.rs
index 0411dde7..18a4694b 100644
--- a/core/src/services/dashmap/backend.rs
+++ b/core/src/services/dashmap/backend.rs
@@ -30,12 +30,10 @@ use crate::*;
///
/// This service can be used to:
///
-/// - [x] read
-/// - [x] write
-/// - [ ] ~~list~~
+/// - [x] get
+/// - [x] set
+/// - [x] delete
/// - [x] scan
-/// - [ ] ~~presign~~
-/// - [x] blocking
#[derive(Default)]
pub struct DashmapBuilder {
root: Option<String>,
diff --git a/core/src/services/memory/backend.rs b/core/src/services/memory/backend.rs
index 34c77350..c745e288 100644
--- a/core/src/services/memory/backend.rs
+++ b/core/src/services/memory/backend.rs
@@ -22,7 +22,7 @@ use std::sync::Arc;
use async_trait::async_trait;
use parking_lot::Mutex;
-use crate::raw::adapters::kv;
+use crate::raw::adapters::typed_kv;
use crate::*;
/// In memory service support. (BTreeMap Based)
@@ -31,12 +31,10 @@ use crate::*;
///
/// This service can be used to:
///
-/// - [x] read
-/// - [x] write
-/// - [ ] ~~list~~
+/// - [x] get
+/// - [x] set
+/// - [x] delete
/// - [x] scan
-/// - [ ] ~~presign~~
-/// - [x] blocking
#[derive(Default)]
pub struct MemoryBuilder {
root: Option<String>,
@@ -72,47 +70,45 @@ impl Builder for MemoryBuilder {
}
/// Backend is used to serve `Accessor` support in memory.
-pub type MemoryBackend = kv::Backend<Adapter>;
+pub type MemoryBackend = typed_kv::Backend<Adapter>;
#[derive(Debug, Clone)]
pub struct Adapter {
- inner: Arc<Mutex<BTreeMap<String, Vec<u8>>>>,
+ inner: Arc<Mutex<BTreeMap<String, typed_kv::Value>>>,
}
#[async_trait]
-impl kv::Adapter for Adapter {
- fn metadata(&self) -> kv::Metadata {
- kv::Metadata::new(
+impl typed_kv::Adapter for Adapter {
+ fn info(&self) -> typed_kv::Info {
+ typed_kv::Info::new(
Scheme::Memory,
&format!("{:?}", &self.inner as *const _),
- Capability {
- read: true,
- write: true,
- create_dir: true,
+ typed_kv::Capability {
+ get: true,
+ set: true,
+ delete: true,
scan: true,
-
- ..Default::default()
},
)
}
- async fn get(&self, path: &str) -> Result<Option<Vec<u8>>> {
+ async fn get(&self, path: &str) -> Result<Option<typed_kv::Value>> {
self.blocking_get(path)
}
- fn blocking_get(&self, path: &str) -> Result<Option<Vec<u8>>> {
+ fn blocking_get(&self, path: &str) -> Result<Option<typed_kv::Value>> {
match self.inner.lock().get(path) {
None => Ok(None),
- Some(bs) => Ok(Some(bs.to_vec())),
+ Some(bs) => Ok(Some(bs.to_owned())),
}
}
- async fn set(&self, path: &str, value: &[u8]) -> Result<()> {
+ async fn set(&self, path: &str, value: typed_kv::Value) -> Result<()> {
self.blocking_set(path, value)
}
- fn blocking_set(&self, path: &str, value: &[u8]) -> Result<()> {
- self.inner.lock().insert(path.to_string(), value.to_vec());
+ fn blocking_set(&self, path: &str, value: typed_kv::Value) -> Result<()> {
+ self.inner.lock().insert(path.to_string(), value);
Ok(())
}
diff --git a/core/src/services/moka/backend.rs b/core/src/services/moka/backend.rs
index ee40bc92..381d8e72 100644
--- a/core/src/services/moka/backend.rs
+++ b/core/src/services/moka/backend.rs
@@ -33,12 +33,10 @@ use crate::*;
///
/// This service can be used to:
///
-/// - [x] read
-/// - [x] write
-/// - [ ] ~~list~~
-/// - [ ] ~~scan~~
-/// - [ ] ~~presign~~
-/// - [x] blocking
+/// - [x] get
+/// - [x] set
+/// - [x] delete
+/// - [ ] ~~ scan ~~
#[derive(Default, Debug)]
pub struct MokaBuilder {
/// Name for this cache instance.