diff --git a/.github/config/tikv.toml b/.github/config/tikv.toml new file mode 100644 index 0000000..d87268c --- /dev/null +++ b/.github/config/tikv.toml @@ -0,0 +1,3 @@ +[storage] +enable-ttl = true +api-version = 2 \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2bbfb10..b74f17f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,7 +41,7 @@ jobs: target/ key: cargo-${{ hashFiles('**/Cargo.lock') }} restore-keys: | - cargo- + cargo- - name: Run format env: RUSTFLAGS: -Dwarnings @@ -69,14 +69,21 @@ jobs: working-directory: ./ run: | cargo check - - name: Setup tikv instance + - name: Setup TiKV instance run: | curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh - /home/runner/.tiup/bin/tiup playground nightly --mode tikv-slim --without-monitor & + ~/.tiup/bin/tiup install playground tikv:nightly pd:nightly + ~/.tiup/bin/tiup playground nightly --mode tikv-slim \ + --without-monitor --kv 3 --kv.config .github/config/tikv.toml & + while :; do + echo "waiting cluster to be ready" + [[ "$(curl -I http://127.0.0.1:2379/pd/api/v1/regions 2>/dev/null | head -n 1 | cut -d$' ' -f2)" -ne "405" ]] || break + sleep 1 + done - name: Setup tikv-service run: | cargo build -r - ./target/release/tikv-service-server --config="config.toml" & + ./target/release/tikv-service-server --config=config.toml & - name: Setup test tool env uses: actions/setup-python@v3 with: diff --git a/.gitignore b/.gitignore index 53eaa21..f1e0d7b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ /target **/*.rs.bk +/.idea +**/__pycache__ +**/*.log diff --git a/Cargo.lock b/Cargo.lock index a6a0b3c..5525469 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1533,6 +1533,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "paste" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c520e05135d6e763148b6426a837e239041653ba7becd2e538c076c738025fc" + [[package]] name = "peeking_take_while" version = "0.1.2" @@ -2376,7 +2382,7 @@ dependencies = [ [[package]] name = "tikv-client" version = "0.1.0" -source = "git+https://github.com/yongman/client-rust.git?rev=6675112143896419d233394b5e02612f50a72a3d#6675112143896419d233394b5e02612f50a72a3d" +source = "git+https://github.com/iosmanthus/client-rust.git?branch=api-v2#0e76e1089a63d3a864b55fd945bc83c3a97a4139" dependencies = [ "async-recursion", "async-trait", @@ -2388,6 +2394,7 @@ dependencies = [ "grpcio", "lazy_static", "log", + "paste", "prometheus 0.12.0", "rand 0.8.5", "regex", @@ -2407,7 +2414,7 @@ dependencies = [ [[package]] name = "tikv-client-common" version = "0.1.0" -source = "git+https://github.com/yongman/client-rust.git?rev=6675112143896419d233394b5e02612f50a72a3d#6675112143896419d233394b5e02612f50a72a3d" +source = "git+https://github.com/iosmanthus/client-rust.git?branch=api-v2#0e76e1089a63d3a864b55fd945bc83c3a97a4139" dependencies = [ "futures 0.3.21", "grpcio", @@ -2423,7 +2430,7 @@ dependencies = [ [[package]] name = "tikv-client-pd" version = "0.1.0" -source = "git+https://github.com/yongman/client-rust.git?rev=6675112143896419d233394b5e02612f50a72a3d#6675112143896419d233394b5e02612f50a72a3d" +source = "git+https://github.com/iosmanthus/client-rust.git?branch=api-v2#0e76e1089a63d3a864b55fd945bc83c3a97a4139" dependencies = [ "async-trait", "futures 0.3.21", @@ -2436,7 +2443,7 @@ dependencies = [ [[package]] name = "tikv-client-proto" version = "0.1.0" -source = "git+https://github.com/yongman/client-rust.git?rev=6675112143896419d233394b5e02612f50a72a3d#6675112143896419d233394b5e02612f50a72a3d" +source = "git+https://github.com/iosmanthus/client-rust.git?branch=api-v2#0e76e1089a63d3a864b55fd945bc83c3a97a4139" dependencies = [ "futures 0.3.21", "grpcio", @@ -2450,7 +2457,7 @@ dependencies = [ [[package]] name = "tikv-client-store" version = "0.1.0" -source = "git+https://github.com/yongman/client-rust.git?rev=6675112143896419d233394b5e02612f50a72a3d#6675112143896419d233394b5e02612f50a72a3d" +source = "git+https://github.com/iosmanthus/client-rust.git?branch=api-v2#0e76e1089a63d3a864b55fd945bc83c3a97a4139" dependencies = [ "async-trait", "derive-new", diff --git a/Cargo.toml b/Cargo.toml index 4ea319a..e599f92 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,25 +20,36 @@ atoi = "0.3.2" bytes = "1" crc = "2.0" structopt = "0.3.14" -slog = { version = "2.3", features = ["max_level_trace", "release_max_level_debug"] } +slog = { version = "2.3", features = [ + "max_level_trace", + "release_max_level_debug", +] } slog-term = { version = "2.4" } tokio = { version = "1", features = ["full"] } tokio-stream = "0.1" tokio-util = { version = "0.7.1", features = ["rt"] } -tikv-client = { git = "https://github.com/yongman/client-rust.git", rev = "6675112143896419d233394b5e02612f50a72a3d" } +tikv-client = { git = "https://github.com/iosmanthus/client-rust.git", branch = "api-v2" } lazy_static = "1.4.0" thiserror = "1" -prometheus = { version = "0.13.0", features = ["process"]} +prometheus = { version = "0.13.0", features = ["process"] } pprof = { version = "0.9", features = ["flamegraph", "protobuf-codec"] } hyper = { version = "0.14.17", features = ["full"] } async-std = { version = "1.11.0", features = ["unstable"] } -async-tls = { version = "0.11.0", features = ["server"], default-features = false } +async-tls = { version = "0.11.0", features = [ + "server", +], default-features = false } rustls = "0.19.0" -rand = {version = "0.8.5", features = ["small_rng"] } +rand = { version = "0.8.5", features = ["small_rng"] } toml = { version = "0.5.8" } serde = { version = "1.0", features = ["derive"] } futures = { version = "0.3", default-features = false } -mlua = { version = "0.7.4", features = ["lua51", "async", "vendored", "macros", "send"]} +mlua = { version = "0.7.4", features = [ + "lua51", + "async", + "vendored", + "macros", + "send", +] } sha1 = "0.10.0" hex = "0.4.3" diff --git a/rust-toolchain b/rust-toolchain index 91951fd..b91c1b1 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.61.0 +nightly-2022-05-01 diff --git a/src/cmd/cmdtype.rs b/src/cmd/cmdtype.rs index 22d4c6c..b27ceea 100644 --- a/src/cmd/cmdtype.rs +++ b/src/cmd/cmdtype.rs @@ -1,12 +1,12 @@ use std::sync::Arc; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use crate::tikv::errors::AsyncResult; use crate::tikv::string::StringCommandCtx; use crate::utils::resp_invalid_arguments; use crate::{Connection, Frame, Parse}; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; use crate::config::is_use_txn_api; diff --git a/src/cmd/del.rs b/src/cmd/del.rs index 2c5fc38..4920019 100644 --- a/src/cmd/del.rs +++ b/src/cmd/del.rs @@ -2,12 +2,12 @@ use std::sync::Arc; use crate::config::is_use_txn_api; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use crate::tikv::errors::{AsyncResult, REDIS_NOT_SUPPORTED_ERR}; use crate::tikv::string::StringCommandCtx; use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame, Parse}; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; use super::Invalid; diff --git a/src/cmd/exists.rs b/src/cmd/exists.rs index e86e1d0..90d73f0 100644 --- a/src/cmd/exists.rs +++ b/src/cmd/exists.rs @@ -1,11 +1,11 @@ use std::sync::Arc; use crate::config::is_use_txn_api; +use crate::tikv::client::Transaction; use crate::tikv::errors::AsyncResult; use crate::tikv::string::StringCommandCtx; use crate::utils::resp_invalid_arguments; use crate::{Connection, Frame, Parse}; -use tikv_client::Transaction; use tokio::sync::Mutex; use crate::cmd::Invalid; diff --git a/src/cmd/expire.rs b/src/cmd/expire.rs index 09c191c..7ac8a7a 100644 --- a/src/cmd/expire.rs +++ b/src/cmd/expire.rs @@ -3,12 +3,12 @@ use std::sync::Arc; use crate::cmd::Invalid; use crate::config::is_use_txn_api; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use crate::tikv::errors::{AsyncResult, REDIS_NOT_SUPPORTED_ERR}; use crate::tikv::string::StringCommandCtx; use crate::utils::{resp_err, resp_invalid_arguments, timestamp_from_ttl}; use crate::{Connection, Frame, Parse}; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/get.rs b/src/cmd/get.rs index 8835324..ab0b694 100644 --- a/src/cmd/get.rs +++ b/src/cmd/get.rs @@ -1,12 +1,12 @@ use std::sync::Arc; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use crate::tikv::errors::AsyncResult; use crate::tikv::string::StringCommandCtx; use crate::utils::resp_invalid_arguments; use crate::{Connection, Frame, Parse}; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; use crate::config::is_use_txn_api; diff --git a/src/cmd/hdel.rs b/src/cmd/hdel.rs index a7b4208..41d5198 100644 --- a/src/cmd/hdel.rs +++ b/src/cmd/hdel.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/hexists.rs b/src/cmd/hexists.rs index e674241..3ff497a 100644 --- a/src/cmd/hexists.rs +++ b/src/cmd/hexists.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/hget.rs b/src/cmd/hget.rs index a66aa04..7b672a2 100644 --- a/src/cmd/hget.rs +++ b/src/cmd/hget.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/hgetall.rs b/src/cmd/hgetall.rs index 30022bf..b4161ee 100644 --- a/src/cmd/hgetall.rs +++ b/src/cmd/hgetall.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/hincrby.rs b/src/cmd/hincrby.rs index 552d5ac..1c38ef3 100644 --- a/src/cmd/hincrby.rs +++ b/src/cmd/hincrby.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/hkeys.rs b/src/cmd/hkeys.rs index ed6dca2..e2fae83 100644 --- a/src/cmd/hkeys.rs +++ b/src/cmd/hkeys.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/hlen.rs b/src/cmd/hlen.rs index 0c2b2a4..eb0d3a5 100644 --- a/src/cmd/hlen.rs +++ b/src/cmd/hlen.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/hmget.rs b/src/cmd/hmget.rs index c720f40..b480a1c 100644 --- a/src/cmd/hmget.rs +++ b/src/cmd/hmget.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/hset.rs b/src/cmd/hset.rs index 113654f..399e72f 100644 --- a/src/cmd/hset.rs +++ b/src/cmd/hset.rs @@ -8,8 +8,9 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::{KvPair, Transaction}; +use tikv_client::KvPair; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/hstrlen.rs b/src/cmd/hstrlen.rs index be9aed3..8c02e79 100644 --- a/src/cmd/hstrlen.rs +++ b/src/cmd/hstrlen.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/hvals.rs b/src/cmd/hvals.rs index 76febf9..2f383a1 100644 --- a/src/cmd/hvals.rs +++ b/src/cmd/hvals.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/incrdecr.rs b/src/cmd/incrdecr.rs index 5108f96..5fe6547 100644 --- a/src/cmd/incrdecr.rs +++ b/src/cmd/incrdecr.rs @@ -8,8 +8,8 @@ use crate::{Connection, Frame, Parse}; use crate::cmd::Invalid; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/lindex.rs b/src/cmd/lindex.rs index 47888d4..6258605 100644 --- a/src/cmd/lindex.rs +++ b/src/cmd/lindex.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/linsert.rs b/src/cmd/linsert.rs index cf36eeb..e1c410b 100644 --- a/src/cmd/linsert.rs +++ b/src/cmd/linsert.rs @@ -8,9 +8,9 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use bytes::Bytes; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; use super::Invalid; diff --git a/src/cmd/llen.rs b/src/cmd/llen.rs index de81aae..9b5db45 100644 --- a/src/cmd/llen.rs +++ b/src/cmd/llen.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/lrange.rs b/src/cmd/lrange.rs index 8dd3104..0d889d6 100644 --- a/src/cmd/lrange.rs +++ b/src/cmd/lrange.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/lrem.rs b/src/cmd/lrem.rs index a70799a..9692256 100644 --- a/src/cmd/lrem.rs +++ b/src/cmd/lrem.rs @@ -8,9 +8,9 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use bytes::Bytes; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; use super::Invalid; diff --git a/src/cmd/lset.rs b/src/cmd/lset.rs index 3090eff..718656f 100644 --- a/src/cmd/lset.rs +++ b/src/cmd/lset.rs @@ -8,9 +8,9 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use bytes::Bytes; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/ltrim.rs b/src/cmd/ltrim.rs index 76a4537..efb57b8 100644 --- a/src/cmd/ltrim.rs +++ b/src/cmd/ltrim.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/mget.rs b/src/cmd/mget.rs index 5fde8c7..36c0537 100644 --- a/src/cmd/mget.rs +++ b/src/cmd/mget.rs @@ -3,12 +3,12 @@ use std::sync::Arc; use crate::cmd::Invalid; use crate::config::is_use_txn_api; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use crate::tikv::errors::AsyncResult; use crate::tikv::string::StringCommandCtx; use crate::utils::resp_invalid_arguments; use crate::{Connection, Frame, Parse}; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; /// Get the value of key. diff --git a/src/cmd/mset.rs b/src/cmd/mset.rs index 59cc7bf..567483c 100644 --- a/src/cmd/mset.rs +++ b/src/cmd/mset.rs @@ -6,11 +6,12 @@ use crate::tikv::string::StringCommandCtx; use crate::tikv::KEY_ENCODER; use crate::utils::resp_invalid_arguments; use crate::{Connection, Frame, Parse}; -use tikv_client::{KvPair, Transaction}; +use tikv_client::KvPair; use tokio::sync::Mutex; use crate::cmd::Invalid; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use bytes::Bytes; use slog::debug; diff --git a/src/cmd/persist.rs b/src/cmd/persist.rs index 3907db9..ce100a7 100644 --- a/src/cmd/persist.rs +++ b/src/cmd/persist.rs @@ -3,12 +3,12 @@ use std::sync::Arc; use crate::cmd::Invalid; use crate::config::is_use_txn_api; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use crate::tikv::errors::{AsyncResult, REDIS_NOT_SUPPORTED_ERR}; use crate::tikv::string::StringCommandCtx; use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame, Parse}; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/pop.rs b/src/cmd/pop.rs index 404551d..59c7cc9 100644 --- a/src/cmd/pop.rs +++ b/src/cmd/pop.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/push.rs b/src/cmd/push.rs index 6bf53f2..e1d8061 100644 --- a/src/cmd/push.rs +++ b/src/cmd/push.rs @@ -8,9 +8,9 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use bytes::Bytes; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/sadd.rs b/src/cmd/sadd.rs index 157ab1f..2932d84 100644 --- a/src/cmd/sadd.rs +++ b/src/cmd/sadd.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/scard.rs b/src/cmd/scard.rs index 50fdbed..cd36dc3 100644 --- a/src/cmd/scard.rs +++ b/src/cmd/scard.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/set.rs b/src/cmd/set.rs index ec74a8c..612cad1 100644 --- a/src/cmd/set.rs +++ b/src/cmd/set.rs @@ -6,10 +6,10 @@ use crate::utils::{resp_invalid_arguments, timestamp_from_ttl}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use bytes::Bytes; use slog::debug; use std::sync::Arc; -use tikv_client::Transaction; use tokio::sync::Mutex; use super::Invalid; diff --git a/src/cmd/setex.rs b/src/cmd/setex.rs index 31e26ad..a39ffc5 100644 --- a/src/cmd/setex.rs +++ b/src/cmd/setex.rs @@ -7,9 +7,9 @@ use crate::utils::{resp_err, resp_invalid_arguments, timestamp_from_ttl}; use crate::{is_use_txn_api, Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use bytes::Bytes; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/setnx.rs b/src/cmd/setnx.rs index 4728203..333f5b9 100644 --- a/src/cmd/setnx.rs +++ b/src/cmd/setnx.rs @@ -8,9 +8,9 @@ use crate::utils::resp_invalid_arguments; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use bytes::Bytes; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; /// Set `key` to hold the string `value`. diff --git a/src/cmd/sismember.rs b/src/cmd/sismember.rs index 44910b6..d2b3c2c 100644 --- a/src/cmd/sismember.rs +++ b/src/cmd/sismember.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/smembers.rs b/src/cmd/smembers.rs index 99273c8..e1dd0ec 100644 --- a/src/cmd/smembers.rs +++ b/src/cmd/smembers.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/smismember.rs b/src/cmd/smismember.rs index ee1da82..a29e0c5 100644 --- a/src/cmd/smismember.rs +++ b/src/cmd/smismember.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/spop.rs b/src/cmd/spop.rs index a9b81a8..1718b93 100644 --- a/src/cmd/spop.rs +++ b/src/cmd/spop.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/srandmember.rs b/src/cmd/srandmember.rs index 8ed8886..11c3280 100644 --- a/src/cmd/srandmember.rs +++ b/src/cmd/srandmember.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/srem.rs b/src/cmd/srem.rs index c737f3b..2fb4ca2 100644 --- a/src/cmd/srem.rs +++ b/src/cmd/srem.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/strlen.rs b/src/cmd/strlen.rs index 1cac645..a2723b4 100644 --- a/src/cmd/strlen.rs +++ b/src/cmd/strlen.rs @@ -6,11 +6,11 @@ use crate::tikv::string::StringCommandCtx; use crate::utils::resp_invalid_arguments; use crate::{Connection, Frame, Parse}; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; use crate::cmd::Invalid; use crate::config::is_use_txn_api; +use crate::tikv::client::Transaction; #[derive(Debug)] pub struct Strlen { diff --git a/src/cmd/ttl.rs b/src/cmd/ttl.rs index 182eb87..1255310 100644 --- a/src/cmd/ttl.rs +++ b/src/cmd/ttl.rs @@ -3,12 +3,12 @@ use std::sync::Arc; use crate::cmd::Invalid; use crate::config::is_use_txn_api; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use crate::tikv::errors::{AsyncResult, REDIS_NOT_SUPPORTED_ERR}; use crate::tikv::string::StringCommandCtx; use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame, Parse}; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/zadd.rs b/src/cmd/zadd.rs index 4eda969..475a251 100644 --- a/src/cmd/zadd.rs +++ b/src/cmd/zadd.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/zcard.rs b/src/cmd/zcard.rs index 3c974b9..b7a4218 100644 --- a/src/cmd/zcard.rs +++ b/src/cmd/zcard.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/zcount.rs b/src/cmd/zcount.rs index bcb56fc..7b0f561 100644 --- a/src/cmd/zcount.rs +++ b/src/cmd/zcount.rs @@ -8,9 +8,9 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use bytes::{Buf, Bytes}; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/zincrby.rs b/src/cmd/zincrby.rs index 8356435..e37f7ff 100644 --- a/src/cmd/zincrby.rs +++ b/src/cmd/zincrby.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/zpop.rs b/src/cmd/zpop.rs index 36a4dc9..c86ec4b 100644 --- a/src/cmd/zpop.rs +++ b/src/cmd/zpop.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/zrange.rs b/src/cmd/zrange.rs index 859b34f..f66e8ff 100644 --- a/src/cmd/zrange.rs +++ b/src/cmd/zrange.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/zrangebyscore.rs b/src/cmd/zrangebyscore.rs index 7de8e9d..dd4e92f 100644 --- a/src/cmd/zrangebyscore.rs +++ b/src/cmd/zrangebyscore.rs @@ -8,9 +8,9 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use bytes::{Buf, Bytes}; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/zrank.rs b/src/cmd/zrank.rs index 16050b8..77c9de3 100644 --- a/src/cmd/zrank.rs +++ b/src/cmd/zrank.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/zrem.rs b/src/cmd/zrem.rs index f950896..347a1d3 100644 --- a/src/cmd/zrem.rs +++ b/src/cmd/zrem.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/zremrangebyscore.rs b/src/cmd/zremrangebyscore.rs index d0a6c5a..5dcd24a 100644 --- a/src/cmd/zremrangebyscore.rs +++ b/src/cmd/zremrangebyscore.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/zrevrange.rs b/src/cmd/zrevrange.rs index 9ae4c0d..796dc93 100644 --- a/src/cmd/zrevrange.rs +++ b/src/cmd/zrevrange.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/cmd/zscore.rs b/src/cmd/zscore.rs index c342f26..91c3490 100644 --- a/src/cmd/zscore.rs +++ b/src/cmd/zscore.rs @@ -8,8 +8,8 @@ use crate::utils::{resp_err, resp_invalid_arguments}; use crate::{Connection, Frame}; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::debug; -use tikv_client::Transaction; use tokio::sync::Mutex; #[derive(Debug)] diff --git a/src/tikv/client.rs b/src/tikv/client.rs index ea0967e..91f297c 100644 --- a/src/tikv/client.rs +++ b/src/tikv/client.rs @@ -4,9 +4,8 @@ use tokio::sync::Mutex; use tikv_client::Error::StringError; use tikv_client::{ - Backoff, BoundRange, ColumnFamily, Error, Key, KvPair, RawClient, Result as TiKVResult, - RetryOptions, Snapshot, Timestamp, TimestampExt, Transaction, TransactionClient, - TransactionOptions, Value, + raw, transaction, Backoff, BoundRange, ColumnFamily, Error, Key, KvPair, Result as TiKVResult, + RetryOptions, Timestamp, TimestampExt, TransactionOptions, Value, }; use crate::config::LOGGER; @@ -39,6 +38,14 @@ pub struct TxnClientWrapper<'a> { retries: u32, } +pub type Snapshot = tikv_client::Snapshot; + +pub type Transaction = tikv_client::Transaction; + +pub type TransactionClient = transaction::Client; + +pub type RawClient = raw::Client; + impl TxnClientWrapper<'static> { pub fn new(c: &'static TransactionClient) -> Self { TxnClientWrapper { diff --git a/src/tikv/hash.rs b/src/tikv/hash.rs index 8f39ae0..fb0eacb 100644 --- a/src/tikv/hash.rs +++ b/src/tikv/hash.rs @@ -16,10 +16,11 @@ use crate::{ use futures::future::FutureExt; use slog::debug; use std::{convert::TryInto, ops::Range, sync::Arc}; -use tikv_client::{BoundRange, Key, KvPair, Transaction}; +use tikv_client::{BoundRange, Key, KvPair}; use tokio::sync::Mutex; use super::errors::*; +use crate::tikv::client::Transaction; use crate::utils::{resp_array, resp_bulk, resp_err, resp_int, resp_nil}; use crate::metrics::REMOVED_EXPIRED_KEY_COUNTER; diff --git a/src/tikv/list.rs b/src/tikv/list.rs index 5196617..9e9a15c 100644 --- a/src/tikv/list.rs +++ b/src/tikv/list.rs @@ -10,6 +10,7 @@ use crate::async_del_list_threshold_or_default; use crate::cmd_linsert_length_limit_or_default; use crate::cmd_lrem_length_limit_or_default; use crate::metrics::REMOVED_EXPIRED_KEY_COUNTER; +use crate::tikv::client::Transaction; use crate::utils::{resp_array, resp_bulk, resp_err, resp_int, resp_nil, resp_ok}; use crate::{utils::key_is_expired, Frame}; use bytes::Bytes; @@ -17,7 +18,7 @@ use core::ops::RangeFrom; use futures::future::FutureExt; use std::convert::TryInto; use std::sync::Arc; -use tikv_client::{BoundRange, Key, Transaction}; +use tikv_client::{BoundRange, Key}; use tokio::sync::Mutex; const INIT_INDEX: u64 = 1 << 32; diff --git a/src/tikv/lua.rs b/src/tikv/lua.rs index 0c2a1ee..47f9aff 100644 --- a/src/tikv/lua.rs +++ b/src/tikv/lua.rs @@ -4,10 +4,10 @@ use super::errors::AsyncResult; use crate::db::Db; use crate::utils::{lua_resp_to_redis_resp, redis_resp_to_lua_resp, resp_err, sha1hex}; use crate::{utils::resp_invalid_arguments, Command, Frame}; -use tikv_client::Transaction; use tokio::sync::Mutex; use crate::config::LOGGER; +use crate::tikv::client::Transaction; use slog::{debug, error}; use crate::tikv::errors::{REDIS_LUA_CONTEXT_IS_NOT_INITIALIZED_ERR, REDIS_NO_MATCHING_SCRIPT_ERR}; diff --git a/src/tikv/mod.rs b/src/tikv/mod.rs index fe5238a..aa55c6b 100644 --- a/src/tikv/mod.rs +++ b/src/tikv/mod.rs @@ -4,9 +4,10 @@ use std::fs::File; use std::io::Write; use std::sync::{Arc, RwLock}; use std::time::Duration; +use tikv_client::{raw, transaction}; use tokio::sync::Mutex; -use tikv_client::{RawClient, Transaction, TransactionClient}; +use crate::tikv::client::{RawClient, Transaction, TransactionClient}; use crate::config::LOGGER; use crate::tikv::encoding::KeyEncoder; @@ -126,8 +127,13 @@ pub async fn do_async_txn_connect(addrs: Vec) -> AsyncResult<()> { backend_key_file_or_default(), ); } - let client = - TransactionClient::new_with_config(addrs.clone(), config, Some(LOGGER.clone())).await?; + let client = TransactionClient::new_with_config( + addrs.clone(), + config, + transaction::ApiV2::default(), + Some(LOGGER.clone()), + ) + .await?; unsafe { TIKV_TXN_CLIENT.replace(client); } @@ -147,7 +153,13 @@ pub async fn do_async_raw_connect(addrs: Vec) -> AsyncResult<()> { backend_key_file_or_default(), ); } - let client = RawClient::new_with_config(addrs.clone(), config, Some(LOGGER.clone())).await?; + let client = RawClient::new_with_config( + addrs.clone(), + config, + raw::ApiV2::default(), + Some(LOGGER.clone()), + ) + .await?; unsafe { TIKV_RAW_CLIENT.replace(client); } diff --git a/src/tikv/set.rs b/src/tikv/set.rs index 9edd550..c9b0d0c 100644 --- a/src/tikv/set.rs +++ b/src/tikv/set.rs @@ -9,13 +9,13 @@ use super::{ }; use crate::async_del_set_threshold_or_default; use crate::async_expire_set_threshold_or_default; +use crate::tikv::client::Transaction; use crate::utils::{key_is_expired, resp_array, resp_bulk, resp_err, resp_int, resp_nil}; use crate::Frame; use ::futures::future::FutureExt; use rand::prelude::SliceRandom; use std::convert::TryInto; use std::sync::Arc; -use tikv_client::Transaction; use tokio::sync::Mutex; use rand::{rngs::SmallRng, Rng, SeedableRng}; diff --git a/src/tikv/string.rs b/src/tikv/string.rs index 0a71016..857ab6c 100644 --- a/src/tikv/string.rs +++ b/src/tikv/string.rs @@ -12,7 +12,7 @@ use ::futures::future::FutureExt; use std::collections::HashMap; use std::str; use std::sync::Arc; -use tikv_client::{Key, KvPair, Transaction, Value}; +use tikv_client::{Key, KvPair, Value}; use tokio::sync::Mutex; use super::errors::*; @@ -24,6 +24,7 @@ use crate::utils::{ use bytes::Bytes; use crate::metrics::REMOVED_EXPIRED_KEY_COUNTER; +use crate::tikv::client::Transaction; #[derive(Clone)] pub struct StringCommandCtx { diff --git a/src/tikv/zset.rs b/src/tikv/zset.rs index 751165a..174b1cb 100644 --- a/src/tikv/zset.rs +++ b/src/tikv/zset.rs @@ -14,10 +14,11 @@ use crate::Frame; use ::futures::future::FutureExt; use std::convert::TryInto; use std::sync::Arc; -use tikv_client::{BoundRange, Transaction}; +use tikv_client::BoundRange; use tokio::sync::Mutex; use crate::metrics::REMOVED_EXPIRED_KEY_COUNTER; +use crate::tikv::client::Transaction; #[derive(Clone)] pub struct ZsetCommandCtx {