Skip to content
This repository has been archived by the owner on Aug 4, 2024. It is now read-only.

Commit

Permalink
Fix ci & remove dead code (#51)
Browse files Browse the repository at this point in the history
* Fix ci & remove dead code

* Fix docker build
  • Loading branch information
lewiszlw authored Oct 12, 2023
1 parent 5d90041 commit 0dff115
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 154 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jobs:
profile: minimal
toolchain: nightly-2023-04-07
- uses: actions/checkout@v2
- name: Install Protoc
uses: arduino/setup-protoc@v2
- name: Build
uses: actions-rs/cargo@v1
with:
Expand All @@ -48,6 +50,8 @@ jobs:
profile: minimal
toolchain: nightly-2023-04-07
- uses: actions/checkout@v2
- name: Install Protoc
uses: arduino/setup-protoc@v2
- name: Test
uses: actions-rs/cargo@v1
with:
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ repository = "https://gitee.com/Kould/KipDB"
readme = "README.md"
keywords = ["async", "KV-Store", "Persistence"]
categories = ["development-tools", "database"]
default-run = "server"

[[bin]]
name = "cli"
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ FROM rust:1.62 as builder

ADD ./src ./builder/src
ADD ./Cargo.toml ./builder/Cargo.toml
ADD ./.cargo ./builder/.cargo
ADD ./build.rs ./builder/build.rs

RUN apt update && apt install -y protobuf-compiler

WORKDIR /builder

RUN rustup default nightly
Expand Down
4 changes: 3 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::compile_protos("src/proto/kipdb.proto")?;
tonic_build::configure()
.protoc_arg("--experimental_allow_proto3_optional")
.compile(&["src/proto/kipdb.proto"], &["src/proto"])?;
Ok(())
}
20 changes: 0 additions & 20 deletions examples/simple_crud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,5 @@ async fn main() -> Result<(), KernelError> {

kip_storage.flush().await?;

let join_cmd_1 = vec![
CommandData::set(b"moon".to_vec(), b"star".to_vec()),
// CommandData::remove(b"apple".to_vec()),
];
// TODO need refactor join
// println!(
// "Join 1: {:?} -> {:?}",
// join_cmd_1.clone(),
// kip_storage.join(join_cmd_1).await?
// );
let join_cmd_2 = vec![
CommandData::get(b"moon".to_vec()),
CommandData::get(b"apple".to_vec()),
];
// println!(
// "Join 2: {:?} -> {:?}",
// join_cmd_2.clone(),
// kip_storage.join(join_cmd_2).await?
// );

Ok(())
}
36 changes: 31 additions & 5 deletions src/bin/cli.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use clap::Parser;
use clap::{Parser, Subcommand};
use itertools::Itertools;
use kip_db::cmd::Command;
use kip_db::server::client::KipdbClient;
use kip_db::server::client::Result;
use kip_db::DEFAULT_PORT;
use serde::{Deserialize, Serialize};
use tracing::{error, info};

const DONE: &str = "Done!";

const UNKNOWN_COMMAND: &str = "Unknown Command!";

#[derive(Parser, Debug)]
#[clap(name = "KipDB-Cli", version, author, about = "Issue KipDB Commands")]
struct Cli {
Expand Down Expand Up @@ -95,7 +93,6 @@ async fn main() -> Result<()> {
client.flush().await?;
DONE.to_string()
}
_ => UNKNOWN_COMMAND.to_string(),
};

info!("{line}");
Expand All @@ -110,3 +107,32 @@ fn encode(value: &String) -> Vec<u8> {
fn decode(value: Vec<u8>) -> String {
bincode::deserialize(value.as_slice()).unwrap()
}

#[derive(Serialize, Deserialize, Debug, Subcommand)]
#[non_exhaustive]
pub enum Command {
Set {
key: String,
value: String,
},
Remove {
key: String,
},
Get {
key: String,
},
Flush,

#[clap(about = "cli.exe batch-set [keys]... [values]...")]
BatchSet {
batch: Vec<String>,
},
BatchRemove {
keys: Vec<String>,
},
BatchGet {
keys: Vec<String>,
},
SizeOfDisk,
Len,
}
68 changes: 0 additions & 68 deletions src/cmd/mod.rs

This file was deleted.

55 changes: 0 additions & 55 deletions src/kernel/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use async_trait::async_trait;
use bytes::Bytes;
use fslock::LockFile;
use itertools::Itertools;
use serde::{Deserialize, Serialize};
use std::ffi::OsStr;
use std::path::Path;
Expand Down Expand Up @@ -44,11 +43,6 @@ pub trait Storage: Send + Sync + 'static + Sized {
/// 通过键删除键值对
async fn remove(&self, key: &[u8]) -> Result<()>;

/// 并行批量执行
/// TODO need refactor
// #[inline]
// async fn join(&self, vec_cmd: Vec<CommandData>) -> Result<Vec<Option<Vec<u8>>>> {}

async fn size_of_disk(&self) -> Result<u64>;

async fn len(&self) -> Result<usize>;
Expand All @@ -64,55 +58,6 @@ pub enum CommandData {
Get { key: Vec<u8> },
}

pub(crate) struct ByteUtils;

impl ByteUtils {
/// 从u8的slice中前四位获取数据的长度
pub(crate) fn from_4_bit_with_start(len_u8: &[u8]) -> usize {
usize::from(len_u8[3])
| usize::from(len_u8[2]) << 8
| usize::from(len_u8[1]) << 16
| usize::from(len_u8[0]) << 24
}

/// 返回字节数组Vec与对应的字节数组长度Vec
///
/// bytes必须使用'ByteUtils::tag_with_head'进行标记
pub(crate) fn sharding_tag_bytes(bytes: &[u8]) -> Vec<&[u8]> {
let mut vec_cmd_u8 = Vec::new();
let mut last_pos = 0;

if bytes.len() < 4 {
return vec_cmd_u8;
}

loop {
let pos = last_pos + 4;
if pos >= bytes.len() {
break;
}
let len_u8 = &bytes[last_pos..pos];
let len = Self::from_4_bit_with_start(len_u8);
if len < 1 || len > bytes.len() {
break;
}

last_pos += len + 4;
vec_cmd_u8.push(&bytes[pos..last_pos]);
}

vec_cmd_u8
}

/// 标记bytes以支持'ByteUtils::sharding_tag_bytes'方法
pub(crate) fn tag_with_head(mut bytes: Vec<u8>) -> Vec<u8> {
let i = bytes.len();
let mut vec_head = vec![(i >> 24) as u8, (i >> 16) as u8, (i >> 8) as u8, i as u8];
vec_head.append(&mut bytes);
vec_head
}
}

impl CommandData {
#[inline]
pub fn get_key(&self) -> &Vec<u8> {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![feature(cursor_remaining)]
#![feature(slice_pattern)]
#![feature(bound_map)]
pub mod cmd;

pub mod config;
pub mod error;
pub mod kernel;
Expand Down
4 changes: 1 addition & 3 deletions src/server/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ use crate::kernel::Storage;
use crate::proto::kipdb_rpc_server::{KipdbRpc, KipdbRpcServer};
use crate::proto::{
BatchGetReq, BatchGetResp, BatchRemoveReq, BatchRemoveResp, BatchSetReq, BatchSetResp, Empty,
FlushResp, GetReq, GetResp, Kv, LenResp, RemoveReq, RemoveResp, SetReq, SetResp,
SizeOfDiskResp,
FlushResp, GetReq, GetResp, LenResp, RemoveReq, RemoveResp, SetReq, SetResp, SizeOfDiskResp,
};
use bytes::Bytes;
use itertools::Itertools;
use std::sync::Arc;
use tonic::transport::Server;
use tonic::{Request, Response, Status};
Expand Down

0 comments on commit 0dff115

Please sign in to comment.