Skip to content

Commit

Permalink
add memtable actor mode
Browse files Browse the repository at this point in the history
  • Loading branch information
devillove084 committed Oct 28, 2023
1 parent 3d4a276 commit a65b992
Show file tree
Hide file tree
Showing 56 changed files with 673 additions and 5,949 deletions.
396 changes: 246 additions & 150 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ members = [
"src/client",
"src/engine",
"src/runtime",
"src/interface",
"src/util/pro-macro",
]

Expand Down
7 changes: 6 additions & 1 deletion src/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ tokio-stream = { version = "0.1.9", features = ["net"] }
tempfile = "3.3.0"
derivative = "2.2.0"
tracing = "0.1.36"
libc = "0.2.132"
libc = "0.2.132"
clap = { version = "4.4.6", features = ["derive"] }

[[bin]]
name = "templatekv"
path = "src/cmd/templatekv.rs"
24 changes: 24 additions & 0 deletions src/client/src/cmd/templatekv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,27 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use clap::Parser;

/// Simple program to greet a person
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
/// Name of the person to greet
#[arg(short, long)]
name: String,

/// Number of times to greet
#[arg(short, long, default_value_t = 1)]
count: u8,
}

#[allow(dead_code)]
fn main() {
let args = Args::parse();

for _ in 0..args.count {
println!("Hello {}!", args.name)
}
}
14 changes: 11 additions & 3 deletions src/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
actix = { git = "https://github.com/devillove084/actix.git" }
async-trait = "0.1.56"
bytes = "0.5.6"
futures = "0.3.29"
crc32fast = "1.2.1"
crossbeam-channel = "0.4.0"
crossbeam-utils = "0.7.0"
fs2 = "0.4.3"
fxhash = "0.2.1"
log = "0.4.6"
log = "0.4.20"
num-derive = "0.3"
num-traits = "0.2"
quick-error = "1.2.3"
Expand All @@ -27,9 +28,16 @@ tokio = { version = "1.19.2", features = ["full"] }
crossbeam = "0.8.2"
bumpalo = "3.11.1"
bitflags = "1.3.2"
tonic = "0.8.0"
bytes = "1.5.0"
prost = "0.11.0"

[target.'cfg(not(target_env = "msvc"))'.dependencies]
tikv-jemallocator = "0.5"

[build-dependencies]
tonic-build = "0.8.0"
tonic-build = "0.8.0"

# [[bin]]
# name = "memtable"
# path = "src/mem/handler.rs"
2 changes: 1 addition & 1 deletion src/engine/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
// limitations under the License.

fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::configure().compile(&["proto/node.proto", "proto/manifest.proto"], &["proto"])?;
tonic_build::configure().protoc_arg("--experimental_allow_proto3_optional").compile(&["proto/memtable.proto"], &["proto"])?;
Ok(())
}
53 changes: 53 additions & 0 deletions src/engine/proto/memtable.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2022 The template Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";
package memtable;

service MemtableService {
rpc ListKV (ListKVRequest) returns (ListKVResponse);
rpc UpdateKV (UpdateKVRequest) returns (UpdateKVResponse);
}

message ListKVRequest {
string tenant = 1;
uint64 seq = 2;
string key = 3;
}

message ListKVResponse {
string value = 1;
}

enum ValueType {
NormalValue = 0;
Deletion = 1;
Unknown = 2;
}

message UpdateKVRequest {
string tenant = 1;
uint64 seq = 2;
ValueType value_type = 3;
string key = 4;
optional string value = 5;
}

message UpdateKVResponse {
string tenant = 1;
uint64 seq = 2;
ValueType value_type = 3;
bool ack = 4;
}

34 changes: 34 additions & 0 deletions src/engine/src/bin/mem.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2022 The template Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use actix::{Actor, System};
use engine::BytewiseComparator;
use engine::db::format::InternalKeyComparator;
use engine::mem::MemTable;
use engine::mem::handler::MemtableServiceHandler;
use engine::mem::memtable_actor::MemTableActor;

fn main() {
let system = System::new();
system.block_on(async {
let add = "[::1]:50051".to_string();
let icmp = InternalKeyComparator::new(BytewiseComparator::default());
let mem = MemTable::new(1 << 32, icmp);
let memtable_handler = MemtableServiceHandler::new_with_memtable(mem);
let memtable_actor = MemTableActor::new(memtable_handler, add);
memtable_actor.start();
futures::future::pending::<()>().await;
});
system.run().unwrap();
}
4 changes: 2 additions & 2 deletions src/engine/src/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,13 @@ impl<I: Iterator, F: DerivedIterFactory> Iterator for ConcatenateIterator<I, F>

fn next(&mut self) {
self.valid_or_panic();
self.derived.as_mut().map_or((), |di| di.next());
let _ = self.derived.as_mut().map_or((), |di| di.next());
self.skip_forward();
}

fn prev(&mut self) {
self.valid_or_panic();
self.derived.as_mut().map_or((), |di| di.prev());
let _ = self.derived.as_mut().map_or((), |di| di.prev());
self.skip_backward();
}

Expand Down
6 changes: 6 additions & 0 deletions src/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
#![feature(async_closure)]

#![allow(clippy::rc_buffer)]
#[macro_use]
Expand Down Expand Up @@ -48,6 +49,10 @@ pub mod storage_impl;
mod table_cache;
mod version;

pub mod memtable_service {
tonic::include_proto!("memtable");
}

pub use batch::WriteBatch;
pub use cache::Cache;
pub use compaction::ManualCompaction;
Expand All @@ -63,3 +68,4 @@ pub use util::{
comparator::{BytewiseComparator, Comparator},
varint::*,
};
pub use memtable_service::*;
Loading

0 comments on commit a65b992

Please sign in to comment.