Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,40 @@ members = [
]

[dependencies]
async-recursion = "0.3"
async-recursion = "1.2"
async-trait = "0.1"
derive-new = "0.5"
either = "1.6"
fail = "0.4"
derive-new = "0.7"
either = "1.19"
fail = "0.5"
futures = { version = "0.3" }
lazy_static = "1"
log = "0.4"
pin-project = "1"
prometheus = { version = "0.13", default-features = false }
prost = "0.13"
rand = "0.8"
prometheus = { version = "0.14", default-features = false }
prost = "0.14"
rand = "0.10"
regex = "1"
semver = "1.0"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1"
take_mut = "0.2.2"
thiserror = "1"
tokio = { version = "1.21", features = ["sync", "rt-multi-thread", "macros"] }
tonic = { version = "0.12", features = ["tls", "gzip"] }
thiserror = "2"
tokio = { version = "1.53", features = ["sync", "rt-multi-thread", "macros"] }
tonic = { version = "0.14", features = ["tls-ring", "gzip"] }
tonic-prost = "0.14"

[dev-dependencies]
clap = "2"
env_logger = "0.10"
fail = { version = "0.4", features = ["failpoints"] }
clap = { version = "4", features = ["cargo", "string"] }
env_logger = "0.11"
fail = { version = "0.5", features = ["failpoints"] }
proptest = "1"
proptest-derive = "0.5.1"
reqwest = { version = "0.11", features = ["json", "native-tls-vendored"] }
rstest = "0.18.2"
proptest-derive = "0.9.0"
reqwest = { version = "0.13", features = ["json", "native-tls-vendored"] }
rstest = "0.28.0"
serde_json = "1"
serial_test = "0.5.0"
tempfile = "=3.14.0"
serial_test = "3.5.0"
tempfile = "=3.27.0"
tokio = { version = "1", features = ["sync", "rt-multi-thread", "macros"] }

[[test]]
Expand Down
32 changes: 15 additions & 17 deletions examples/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
use std::path::PathBuf;

use clap::crate_version;
use clap::App;
use clap::Arg;
use clap::ArgAction;
use clap::Command;

pub struct CommandArgs {
pub pd: Vec<String>,
Expand All @@ -14,58 +15,55 @@ pub struct CommandArgs {
}

pub fn parse_args(app_name: &str) -> CommandArgs {
let matches = App::new(app_name)
let matches = Command::new(app_name.to_owned())
.version(crate_version!())
.author("The TiKV Project Authors")
.arg(
Arg::with_name("pd")
Arg::new("pd")
.long("pd")
.aliases(&["pd-endpoint", "pd-endpoints"])
.aliases(["pd-endpoint", "pd-endpoints"])
.value_name("PD_URL")
.help("Sets PD endpoints")
.long_help("Sets PD endpoints. Uses `,` to separate multiple PDs")
.takes_value(true)
.multiple(true)
.value_delimiter(",")
.action(ArgAction::Append)
.num_args(1..)
.value_delimiter(',')
.required(false)
.default_value("localhost:2379"),
)
// A cyclic dependency between CA, cert and key is made
// to ensure that no security options are missing.
.arg(
Arg::with_name("ca")
Arg::new("ca")
.long("ca")
.value_name("CA_PATH")
.help("Sets the CA")
.long_help("Sets the CA. Must be used with --cert and --key")
.takes_value(true)
.requires("cert"),
)
.arg(
Arg::with_name("cert")
Arg::new("cert")
.long("cert")
.value_name("CERT_PATH")
.help("Sets the certificate")
.long_help("Sets the certificate. Must be used with --ca and --key")
.takes_value(true)
.requires("key"),
)
.arg(
Arg::with_name("key")
Arg::new("key")
.long("key")
.alias("private-key")
.value_name("KEY_PATH")
.help("Sets the private key")
.long_help("Sets the private key. Must be used with --ca and --cert")
.takes_value(true)
.requires("ca"),
)
.get_matches();

CommandArgs {
pd: matches.values_of("pd").unwrap().map(String::from).collect(),
ca: matches.value_of("ca").map(PathBuf::from),
cert: matches.value_of("cert").map(PathBuf::from),
key: matches.value_of("key").map(PathBuf::from),
pd: matches.get_many::<String>("pd").unwrap().cloned().collect(),
ca: matches.get_one::<String>("ca").map(PathBuf::from),
cert: matches.get_one::<String>("cert").map(PathBuf::from),
key: matches.get_one::<String>("key").map(PathBuf::from),
}
}
5 changes: 2 additions & 3 deletions proto-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ edition = "2021"

[dependencies]
glob = "0.3"
tonic-build = { version = "0.10", features = ["cleanup-markdown"] }
# Keep this compatible with rust-toolchain 1.84.1.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the MSRV is 1.93.0, no need to be kept.

tempfile = "=3.14.0"
tonic-prost-build = "0.14"
tempfile = "=3.27.0"
6 changes: 3 additions & 3 deletions proto-build/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Copyright 2023 TiKV Project Authors. Licensed under Apache-2.0.

fn main() {
tonic_build::configure()
tonic_prost_build::configure()
.emit_rerun_if_changed(false)
.build_server(false)
.include_file("mod.rs")
.out_dir("src/generated")
.compile(
.compile_protos(
&glob::glob("proto/*.proto")
.unwrap()
.collect::<Result<Vec<_>, _>>()
.unwrap(),
&["proto/include", "proto"],
&["proto/include".into(), "proto".into()],
)
.unwrap();
}
16 changes: 8 additions & 8 deletions src/backoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use std::time::Duration;

use rand::thread_rng;
use rand::Rng;
use rand::rng;
use rand::RngExt;

pub const DEFAULT_REGION_BACKOFF: Backoff = Backoff::no_jitter_backoff(2, 500, 10);
pub const DEFAULT_STORE_BACKOFF: Backoff = Backoff::no_jitter_backoff(2, 1000, 10);
Expand Down Expand Up @@ -44,8 +44,8 @@ impl Backoff {
BackoffKind::FullJitter => {
let delay_ms = self.max_delay_ms.min(self.current_delay_ms);

let mut rng = thread_rng();
let delay_ms: u64 = rng.gen_range(0..delay_ms);
let mut rng = rng();
let delay_ms: u64 = rng.random_range(0..delay_ms);
self.current_delay_ms <<= 1;

Some(Duration::from_millis(delay_ms))
Expand All @@ -54,16 +54,16 @@ impl Backoff {
let delay_ms = self.max_delay_ms.min(self.current_delay_ms);
let half_delay_ms = delay_ms >> 1;

let mut rng = thread_rng();
let delay_ms: u64 = rng.gen_range(0..half_delay_ms) + half_delay_ms;
let mut rng = rng();
let delay_ms: u64 = rng.random_range(0..half_delay_ms) + half_delay_ms;
self.current_delay_ms <<= 1;

Some(Duration::from_millis(delay_ms))
}
BackoffKind::DecorrelatedJitter => {
let mut rng = thread_rng();
let mut rng = rng();
let delay_ms: u64 = rng
.gen_range(0..self.current_delay_ms * 3 - self.base_delay_ms)
.random_range(0..self.current_delay_ms * 3 - self.base_delay_ms)
+ self.base_delay_ms;

let delay_ms = delay_ms.min(self.max_delay_ms);
Expand Down
44 changes: 22 additions & 22 deletions src/generated/autoid.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// This file is @generated by prost-build.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct AutoIdRequest {
#[prost(int64, tag = "1")]
pub db_id: i64,
Expand All @@ -17,8 +16,7 @@ pub struct AutoIdRequest {
#[prost(uint32, tag = "7")]
pub keyspace_id: u32,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct AutoIdResponse {
#[prost(int64, tag = "1")]
pub min: i64,
Expand All @@ -27,8 +25,7 @@ pub struct AutoIdResponse {
#[prost(bytes = "vec", tag = "3")]
pub errmsg: ::prost::alloc::vec::Vec<u8>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct RebaseRequest {
#[prost(int64, tag = "1")]
pub db_id: i64,
Expand All @@ -41,15 +38,20 @@ pub struct RebaseRequest {
#[prost(bool, tag = "5")]
pub force: bool,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct RebaseResponse {
#[prost(bytes = "vec", tag = "1")]
pub errmsg: ::prost::alloc::vec::Vec<u8>,
}
/// Generated client implementations.
pub mod auto_id_alloc_client {
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
#![allow(
unused_variables,
dead_code,
missing_docs,
clippy::wildcard_imports,
clippy::let_unit_value,
)]
use tonic::codegen::*;
use tonic::codegen::http::Uri;
#[derive(Debug, Clone)]
Expand All @@ -69,10 +71,10 @@ pub mod auto_id_alloc_client {
}
impl<T> AutoIdAllocClient<T>
where
T: tonic::client::GrpcService<tonic::body::BoxBody>,
T: tonic::client::GrpcService<tonic::body::Body>,
T::Error: Into<StdError>,
T::ResponseBody: Body<Data = Bytes> + Send + 'static,
<T::ResponseBody as Body>::Error: Into<StdError> + Send,
T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
<T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
{
pub fn new(inner: T) -> Self {
let inner = tonic::client::Grpc::new(inner);
Expand All @@ -90,14 +92,14 @@ pub mod auto_id_alloc_client {
F: tonic::service::Interceptor,
T::ResponseBody: Default,
T: tonic::codegen::Service<
http::Request<tonic::body::BoxBody>,
http::Request<tonic::body::Body>,
Response = http::Response<
<T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
<T as tonic::client::GrpcService<tonic::body::Body>>::ResponseBody,
>,
>,
<T as tonic::codegen::Service<
http::Request<tonic::body::BoxBody>,
>>::Error: Into<StdError> + Send + Sync,
http::Request<tonic::body::Body>,
>>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
{
AutoIdAllocClient::new(InterceptedService::new(inner, interceptor))
}
Expand Down Expand Up @@ -140,12 +142,11 @@ pub mod auto_id_alloc_client {
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
tonic::Status::unknown(
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/autoid.AutoIDAlloc/AllocAutoID",
);
Expand All @@ -162,12 +163,11 @@ pub mod auto_id_alloc_client {
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
tonic::Status::unknown(
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/autoid.AutoIDAlloc/Rebase",
);
Expand Down
Loading
Loading