Skip to content

Commit

Permalink
feat: impl kv backend for raft engine (#2280)
Browse files Browse the repository at this point in the history
* feat: kv backend on raft-engine

* feat: raft-engine kvbackend

* fix: toml

* fix: some review comments

* chore: optimize delete

* fix: lift lock in batch_delete
  • Loading branch information
v0y4g3r authored and waynexia committed Sep 12, 2023
1 parent ccb0a90 commit 9cc016f
Show file tree
Hide file tree
Showing 7 changed files with 587 additions and 14 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 7 additions & 13 deletions src/common/meta/src/kv_backend/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,8 @@ impl<T: ErrorExt + Send + Sync> TxnService for MemoryKvBackend<T> {

let do_txn = |txn_op| match txn_op {
TxnOp::Put(key, value) => {
let prev_value = kvs.insert(key.clone(), value);
let prev_kv = prev_value.map(|value| KeyValue { key, value });
TxnOpResponse::ResponsePut(PutResponse { prev_kv })
kvs.insert(key.clone(), value);
TxnOpResponse::ResponsePut(PutResponse { prev_kv: None })
}

TxnOp::Get(key) => {
Expand All @@ -337,16 +336,11 @@ impl<T: ErrorExt + Send + Sync> TxnService for MemoryKvBackend<T> {

TxnOp::Delete(key) => {
let prev_value = kvs.remove(&key);
let deleted = prev_value.as_ref().map(|x| x.len()).unwrap_or(0) as i64;

let prev_kvs = prev_value
.into_iter()
.map(|value| KeyValue {
key: key.clone(),
value,
})
.collect();
TxnOpResponse::ResponseDelete(DeleteRangeResponse { deleted, prev_kvs })
let deleted = if prev_value.is_some() { 1 } else { 0 };
TxnOpResponse::ResponseDelete(DeleteRangeResponse {
deleted,
prev_kvs: vec![],
})
}
};

Expand Down
1 change: 1 addition & 0 deletions src/log-store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ byteorder = "1.4"
bytes = "1.1"
common-base = { workspace = true }
common-error = { workspace = true }
common-meta = { workspace = true }
common-runtime = { workspace = true }
common-telemetry = { workspace = true }
futures-util.workspace = true
Expand Down
2 changes: 2 additions & 0 deletions src/log-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#![feature(let_chains)]

mod config;
pub mod error;
mod noop;
Expand Down
1 change: 1 addition & 0 deletions src/log-store/src/raft_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use store_api::logstore::namespace::Namespace;
use crate::error::Error;
use crate::raft_engine::protos::logstore::{EntryImpl, NamespaceImpl};

mod backend;
pub mod log_store;

pub mod protos {
Expand Down
Loading

0 comments on commit 9cc016f

Please sign in to comment.