From 560fb322b17504a408a0cb83dd77d4255554c2eb Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 16:18:11 +0800 Subject: [PATCH 01/30] z --- Cargo.lock | 1 + src/meta/binaries/Cargo.toml | 1 + src/meta/binaries/metactl/admin.rs | 98 ++++ src/meta/binaries/metactl/export_from_disk.rs | 14 +- src/meta/binaries/metactl/export_from_grpc.rs | 16 +- src/meta/binaries/metactl/import.rs | 59 ++- src/meta/binaries/metactl/main.rs | 417 ++++++++++++------ src/meta/binaries/metactl/upgrade.rs | 8 +- 8 files changed, 419 insertions(+), 195 deletions(-) create mode 100644 src/meta/binaries/metactl/admin.rs diff --git a/Cargo.lock b/Cargo.lock index 4315d8733b5b..f9eb63f3606d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5104,6 +5104,7 @@ dependencies = [ "futures", "log", "rand 0.8.5", + "reqwest 0.12.4", "serde", "serde_json", "tokio", diff --git a/src/meta/binaries/Cargo.toml b/src/meta/binaries/Cargo.toml index b078d32c291f..571f9782f4ee 100644 --- a/src/meta/binaries/Cargo.toml +++ b/src/meta/binaries/Cargo.toml @@ -48,6 +48,7 @@ serde = { workspace = true } serde_json = { workspace = true } tokio = { workspace = true } tokio-stream = { workspace = true } +reqwest = { workspace = true } url = "2.3.1" [[bin]] diff --git a/src/meta/binaries/metactl/admin.rs b/src/meta/binaries/metactl/admin.rs new file mode 100644 index 000000000000..0e12c0e0fca2 --- /dev/null +++ b/src/meta/binaries/metactl/admin.rs @@ -0,0 +1,98 @@ +// Copyright 2021 Datafuse Labs +// +// 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 reqwest::Client; +use serde::Deserialize; + +pub struct MetaAdminClient { + client: Client, + endpoint: String, +} + +impl MetaAdminClient { + pub fn new(addr: &str) -> Self { + let client = Client::new(); + MetaAdminClient { + client, + endpoint: format!("http://{}", addr), + } + } + + pub async fn status(&self) -> anyhow::Result { + let resp = self + .client + .get(format!("{}/v1/cluster/status", self.endpoint)) + .send() + .await?; + if resp.status().is_success() { + let result = resp.json::().await?; + Ok(result) + } else { + let data = resp.bytes().await?; + let msg = String::from_utf8_lossy(&data); + Err(anyhow::anyhow!( + "status code: {}, msg: {}", + resp.status(), + msg + )) + } + } + + pub async fn transfer_leader( + &self, + target: Option, + ) -> anyhow::Result { + let resp = match target { + Some(to) => { + self.client + .get(format!( + "{}/v1/ctrl/trigger_transfer_leader?to={}", + self.endpoint, to + )) + .send() + .await? + } + None => { + self.client + .get(format!("{}/v1/ctrl/trigger_transfer_leader", self.endpoint)) + .send() + .await? + } + }; + if resp.status().is_success() { + let result = resp.json::().await?; + Ok(result) + } else { + let data = resp.bytes().await?; + let msg = String::from_utf8_lossy(&data); + Err(anyhow::anyhow!( + "status code: {}, msg: {}", + resp.status(), + msg + )) + } + } +} + +#[derive(Deserialize, Debug)] +pub struct AdminStatusResponse { + pub name: String, +} + +#[derive(Deserialize, Debug)] +pub struct AdminTransferLeaderResponse { + from: u64, + to: u64, + voter_ids: Vec, +} diff --git a/src/meta/binaries/metactl/export_from_disk.rs b/src/meta/binaries/metactl/export_from_disk.rs index cfb954f798f6..c8a7b9e4450e 100644 --- a/src/meta/binaries/metactl/export_from_disk.rs +++ b/src/meta/binaries/metactl/export_from_disk.rs @@ -21,7 +21,7 @@ use databend_meta::store::StoreInner; use futures::TryStreamExt; use crate::upgrade; -use crate::Config; +use crate::ExportArgs; /// Print the entire sled db. /// @@ -29,22 +29,22 @@ use crate::Config; /// `[sled_tree_name, {key_space: {key, value}}]` /// E.g.: /// `["state_machine/0",{"GenericKV":{"key":"wow","value":{"seq":3,"meta":null,"data":[119,111,119]}}}` -pub async fn export_from_dir(config: &Config) -> anyhow::Result<()> { - upgrade::upgrade(config).await?; +pub async fn export_from_dir(args: &ExportArgs) -> anyhow::Result<()> { + upgrade::upgrade(args).await?; eprintln!(); eprintln!("Export:"); - let raft_config: RaftConfig = config.clone().into(); + let raft_config: RaftConfig = args.clone().into(); let sto_inn = StoreInner::open_create(&raft_config, Some(()), None).await?; let mut lines = Arc::new(sto_inn).export(); eprintln!(" From: {}", raft_config.raft_dir); - let file: Option = if !config.db.is_empty() { - eprintln!(" To: File: {}", config.db); - Some((File::create(&config.db))?) + let file: Option = if !args.db.is_empty() { + eprintln!(" To: File: {}", args.db); + Some((File::create(&args.db))?) } else { eprintln!(" To: "); None diff --git a/src/meta/binaries/metactl/export_from_grpc.rs b/src/meta/binaries/metactl/export_from_grpc.rs index 82c2b7d3fa60..77c60ea69d2a 100644 --- a/src/meta/binaries/metactl/export_from_grpc.rs +++ b/src/meta/binaries/metactl/export_from_grpc.rs @@ -25,22 +25,22 @@ use databend_common_meta_types::protobuf; use tokio::net::TcpSocket; use tokio_stream::StreamExt; -use crate::Config; +use crate::ExportArgs; /// Dump metasrv data, raft-log, state machine etc in json to stdout. -pub async fn export_from_running_node(config: &Config) -> Result<(), anyhow::Error> { +pub async fn export_from_running_node(addr: &str, args: &ExportArgs) -> Result<(), anyhow::Error> { eprintln!(); eprintln!("Export:"); - eprintln!(" From: online meta-service: {}", config.grpc_api_address); - eprintln!(" Export To: {}", config.db); - eprintln!(" Export Chunk Size: {:?}", config.export_chunk_size); + eprintln!(" From: online meta-service: {}", addr); + eprintln!(" Export To: {}", args.db); + eprintln!(" Export Chunk Size: {:?}", args.export_chunk_size); - let grpc_api_addr = get_available_socket_addr(&config.grpc_api_address).await?; + let grpc_api_addr = get_available_socket_addr(addr).await?; export_from_grpc( grpc_api_addr.to_string().as_str(), - config.db.clone(), - config.export_chunk_size, + args.db.clone(), + args.export_chunk_size, ) .await?; Ok(()) diff --git a/src/meta/binaries/metactl/import.rs b/src/meta/binaries/metactl/import.rs index 9297c3568847..6f3178ee73de 100644 --- a/src/meta/binaries/metactl/import.rs +++ b/src/meta/binaries/metactl/import.rs @@ -55,38 +55,38 @@ use url::Url; use crate::reading; use crate::upgrade; -use crate::Config; +use crate::ImportArgs; -pub async fn import_data(config: &Config) -> anyhow::Result<()> { - let raft_dir = config.raft_dir.clone().unwrap_or_default(); +pub async fn import_data(args: &ImportArgs) -> anyhow::Result<()> { + let raft_dir = args.raft_dir.clone().unwrap_or_default(); eprintln!(); eprintln!("Import:"); eprintln!(" Into Meta Dir: '{}'", raft_dir); - eprintln!(" Initialize Cluster with Id: {}, cluster: {{", config.id); - for peer in config.initial_cluster.clone() { + eprintln!(" Initialize Cluster with Id: {}, cluster: {{", args.id); + for peer in args.initial_cluster.clone() { eprintln!(" Peer: {}", peer); } eprintln!(" }}"); - let nodes = build_nodes(config.initial_cluster.clone(), config.id)?; + let nodes = build_nodes(args.initial_cluster.clone(), args.id)?; init_sled_db(raft_dir.clone(), 64 * 1024 * 1024 * 1024); - clear(config)?; - let max_log_id = import_from_stdin_or_file(config).await?; + clear(args)?; + let max_log_id = import_from_stdin_or_file(args).await?; - if config.initial_cluster.is_empty() { + if args.initial_cluster.is_empty() { return Ok(()); } - init_new_cluster(config, nodes, max_log_id, config.id).await?; + init_new_cluster(args, nodes, max_log_id).await?; Ok(()) } /// Import from lines of exported data and Return the max log id that is found. async fn import_lines( - config: &Config, + raft_config: RaftConfig, lines: Lines, ) -> anyhow::Result> { #[allow(clippy::useless_conversion)] @@ -106,8 +106,8 @@ async fn import_lines( please use an older version databend-metactl to import from V001" )); } - DataVersion::V002 => import_v002(config, it).await?, - DataVersion::V003 => import_v003(config, it).await?, + DataVersion::V002 => import_v002(raft_config, it).await?, + DataVersion::V003 => import_v003(raft_config, it).await?, }; Ok(max_log_id) @@ -119,11 +119,11 @@ async fn import_lines( /// /// It write logs and related entries to sled trees, and state_machine entries to a snapshot. async fn import_v002( - config: &Config, + raft_config: RaftConfig, lines: impl IntoIterator>, ) -> anyhow::Result> { // v002 and v003 share the same exported data format. - import_v003(config, lines).await + import_v003(raft_config, lines).await } /// Import serialized lines for `DataVersion::V003` @@ -132,11 +132,9 @@ async fn import_v002( /// /// It write logs and related entries to sled trees, and state_machine entries to a snapshot. async fn import_v003( - config: &Config, + raft_config: RaftConfig, lines: impl IntoIterator>, ) -> anyhow::Result> { - let raft_config: RaftConfig = config.clone().into(); - let db = get_sled_db(); let mut n = 0; @@ -221,24 +219,26 @@ async fn import_v003( /// Insert them into sled db and flush. /// /// Finally upgrade the data in raft_dir to the latest version. -async fn import_from_stdin_or_file(config: &Config) -> anyhow::Result> { - let restore = config.db.clone(); +async fn import_from_stdin_or_file(args: &ImportArgs) -> anyhow::Result> { + let restore = args.db.clone(); + let raft_config: RaftConfig = args.clone().into(); let max_log_id = if restore.is_empty() { eprintln!(" From: "); let lines = io::stdin().lines(); - import_lines(config, lines).await? + import_lines(raft_config, lines).await? } else { - eprintln!(" From: {}", config.db); + eprintln!(" From: {}", args.db); let file = File::open(restore)?; let reader = BufReader::new(file); let lines = reader.lines(); - import_lines(config, lines).await? + import_lines(raft_config, lines).await? }; - upgrade::upgrade(config).await?; + let raft_config: RaftConfig = args.clone().into(); + upgrade::upgrade(&raft_config).await?; Ok(max_log_id) } @@ -298,16 +298,15 @@ fn build_nodes(initial_cluster: Vec, id: u64) -> anyhow::Result, max_log_id: Option, - id: u64, ) -> anyhow::Result<()> { eprintln!(); eprintln!("Initialize Cluster with: {:?}", nodes); let db = get_sled_db(); - let raft_config: RaftConfig = config.clone().into(); + let raft_config: RaftConfig = args.clone().into(); let mut sto = RaftStore::open_create(&raft_config, Some(()), None).await?; @@ -375,13 +374,13 @@ async fn init_new_cluster( // Reset node id let raft_state = RaftState::open_create(&db, &raft_config, Some(()), None).await?; - raft_state.set_node_id(id).await?; + raft_state.set_node_id(args.id).await?; Ok(()) } /// Clear all sled data and on-disk snapshot. -fn clear(config: &Config) -> anyhow::Result<()> { +fn clear(args: &ImportArgs) -> anyhow::Result<()> { eprintln!(); eprintln!("Clear All Sled Trees Before Import:"); let db = get_sled_db(); @@ -394,7 +393,7 @@ fn clear(config: &Config) -> anyhow::Result<()> { eprintln!(" Cleared sled tree: {}", name); } - let df_meta_path = format!("{}/df_meta", config.raft_dir.clone().unwrap_or_default()); + let df_meta_path = format!("{}/df_meta", args.raft_dir.clone().unwrap_or_default()); if Path::new(&df_meta_path).exists() { remove_dir_all(&df_meta_path)?; } diff --git a/src/meta/binaries/metactl/main.rs b/src/meta/binaries/metactl/main.rs index dce759632d3d..71572462bdfd 100644 --- a/src/meta/binaries/metactl/main.rs +++ b/src/meta/binaries/metactl/main.rs @@ -16,6 +16,7 @@ mod export_from_grpc; +pub mod admin; pub mod export_from_disk; pub mod import; pub(crate) mod reading; @@ -23,6 +24,9 @@ pub mod upgrade; use std::collections::BTreeMap; +use admin::MetaAdminClient; +use clap::Args; +use clap::CommandFactory; use clap::Parser; use databend_common_base::base::tokio; use databend_common_meta_client::MetaGrpcClient; @@ -37,52 +41,125 @@ use databend_meta::version::METASRV_COMMIT_VERSION; use serde::Deserialize; use serde::Serialize; -// TODO(xuanwo) -// -// We should make metactl config keeps backward compatibility too. -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Parser)] -#[clap(about, version = &**METASRV_COMMIT_VERSION, author)] -pub struct Config { - /// Run a command - #[clap(long, default_value = "")] - pub cmd: String, - +#[derive(Debug, PartialEq, Args)] +struct GlobalArgs { #[clap(long, default_value = "INFO")] pub log_level: String, - #[clap(long)] - pub status: bool, + #[clap( + long, + env = "METASRV_GRPC_API_ADDRESS", + default_value = "127.0.0.1:9191" + )] + pub grpc_api_address: String, + #[clap( + long, + env = "METASRV_ADMIN_API_ADDRESS", + default_value = "127.0.0.1:28002" + )] + pub admin_api_address: String, + + #[deprecated] #[clap(long)] pub import: bool, + #[deprecated] #[clap(long)] pub export: bool, + /// The dir to store persisted meta state, including raft logs, state machine etc. + #[deprecated] + #[clap(long)] + #[serde(alias = "kvsrv_raft_dir")] + pub raft_dir: Option, + /// The N.O. json strings in a export stream item. /// /// Set this to a smaller value if you get gRPC message body too large error. /// This requires meta-service >= 1.2.315; For older version, this argument is ignored. /// /// By default it is 32. + #[deprecated] #[clap(long)] pub export_chunk_size: Option, - #[clap( - long, - env = "METASRV_GRPC_API_ADDRESS", - default_value = "127.0.0.1:9191" - )] - pub grpc_api_address: String, + /// When export raft data, this is the name of the save db file. + /// If `db` is empty, output the exported data as json to stdout instead. + /// When import raft data, this is the name of the restored db file. + /// If `db` is empty, the restored data is from stdin instead. + #[deprecated] + #[clap(long, default_value = "")] + pub db: String, + + /// initial_cluster format: node_id=endpoint,grpc_api_addr + #[deprecated] + #[clap(long)] + pub initial_cluster: Vec, + + /// The node id. Used in these cases: + /// + /// 1. when this server is not initialized, e.g. --boot or --single for the first time. + /// 2. --initial_cluster with new cluster node id. + /// + /// Otherwise this argument is ignored. + #[deprecated] + #[clap(long, default_value = "0")] + #[serde(alias = "kvsrv_id")] + pub id: u64, +} +#[derive(Debug, Args)] +struct ExportArgs { /// The dir to store persisted meta state, including raft logs, state machine etc. #[clap(long)] #[serde(alias = "kvsrv_raft_dir")] pub raft_dir: Option, - /// When export raft data, this is the name of the save db file. + /// The N.O. json strings in a export stream item. + /// + /// Set this to a smaller value if you get gRPC message body too large error. + /// This requires meta-service >= 1.2.315; For older version, this argument is ignored. + /// + /// By default it is 32. + #[clap(long)] + pub chunk_size: Option, + + /// The name of the save db file. /// If `db` is empty, output the exported data as json to stdout instead. - /// When import raft data, this is the name of the restored db file. + #[clap(long, default_value = "")] + pub db: String, + + /// The node id. Used in these cases: + /// + /// 1. when this server is not initialized, e.g. --boot or --single for the first time. + /// 2. --initial_cluster with new cluster node id. + /// + /// Otherwise this argument is ignored. + #[clap(long, default_value = "0")] + #[serde(alias = "kvsrv_id")] + pub id: u64, +} + +impl From for RaftConfig { + #[allow(clippy::field_reassign_with_default)] + fn from(value: ExportArgs) -> Self { + let mut c = Self::default(); + + c.raft_dir = value.raft_dir.unwrap_or_default(); + c.id = value.id; + c + } +} + +#[derive(Debug, Args)] +struct ImportArgs { + /// The dir to store persisted meta state, including raft logs, state machine etc. + #[clap(long)] + #[serde(alias = "kvsrv_raft_dir")] + pub raft_dir: Option, + + /// The name of the restored db file. /// If `db` is empty, the restored data is from stdin instead. #[clap(long, default_value = "")] pub db: String, @@ -102,9 +179,9 @@ pub struct Config { pub id: u64, } -impl From for RaftConfig { +impl From for RaftConfig { #[allow(clippy::field_reassign_with_default)] - fn from(value: Config) -> Self { + fn from(value: ImportArgs) -> Self { let mut c = Self::default(); c.raft_dir = value.raft_dir.unwrap_or_default(); @@ -113,6 +190,140 @@ impl From for RaftConfig { } } +#[derive(Debug, Args)] +struct TransferLeaderArgs { + #[clap(long)] + pub to: Option, +} + +#[derive(Debug, Parser)] +#[clap(name = "databend-metactl", about, version = &**METASRV_COMMIT_VERSION, author)] +pub struct App { + #[clap(long, default_value = "")] + pub command: Option, + + #[clap(flatten)] + pub globals: GlobalArgs, +} + +impl App { + pub fn print_help(&self) -> anyhow::Result<()> { + let mut cmd = Self::command(); + cmd.print_help()?; + Ok(()) + } + + pub async fn show_status(&self) -> anyhow::Result<()> { + let addr = self.globals.grpc_api_address; + + let client = + MetaGrpcClient::try_create(vec![addr.to_string()], "root", "xxx", None, None, None)?; + + let res = client.get_cluster_status().await?; + println!("BinaryVersion: {}", res.binary_version); + println!("DataVersion: {}", res.data_version); + println!("DBSize: {}", res.db_size); + println!("KeyNumber: {}", res.key_num); + println!("Node: id={} raft={}", res.id, res.endpoint); + println!("State: {}", res.state); + if let Some(leader) = res.leader { + println!("Leader: {}", leader); + } + println!("CurrentTerm: {}", res.current_term); + println!("LastSeq: {:?}", res.last_seq); + println!("LastLogIndex: {}", res.last_log_index); + println!("LastApplied: {}", res.last_applied); + if let Some(last_log_id) = res.snapshot_last_log_id { + println!("SnapshotLastLogID: {}", last_log_id); + } + if let Some(purged) = res.purged { + println!("Purged: {}", purged); + } + if !res.replication.is_empty() { + println!("Replication:"); + for (k, v) in res.replication { + if v != res.last_applied { + println!(" - [{}] {} *", k, v); + } else { + println!(" - [{}] {}", k, v); + } + } + } + if !res.voters.is_empty() { + println!("Voters:"); + for v in res.voters { + println!(" - {}", v); + } + } + if !res.non_voters.is_empty() { + println!("NonVoters:"); + for v in res.non_voters { + println!(" - {}", v); + } + } + Ok(()) + } + + async fn bench_client_num_conn(&self) -> anyhow::Result<()> { + let addr = self.globals.grpc_api_address; + println!( + "loop: connect to metasrv {}, get_kv('foo'), do not drop the connection", + addr + ); + let mut clients = vec![]; + let mut i = 0; + loop { + i += 1; + let client = MetaGrpcClient::try_create( + vec![addr.to_string()], + "root", + "xxx", + None, + None, + None, + )?; + let res = client.get_kv("foo").await; + println!("{}-th: get_kv(foo): {:?}", i, res); + clients.push(client); + } + } + + async fn transfer_leader(&self, args: &TransferLeaderArgs) -> anyhow::Result<()> { + let addr = self.globals.grpc_api_address; + let client = MetaAdminClient::new(&addr); + client.transfer_leader(args.to).await?; + Ok(()) + } + + async fn export(&self, args: &ExportArgs) -> anyhow::Result<()> { + match args.raft_dir { + None => { + export_from_grpc::export_from_running_node(&self.globals.grpc_api_address, args) + .await?; + } + Some(ref dir) => { + init_sled_db(dir.clone(), 64 * 1024 * 1024 * 1024); + export_from_disk::export_from_dir(args).await?; + } + } + Ok(()) + } + + async fn import(&self, args: &ImportArgs) -> anyhow::Result<()> { + import::import_data(&args).await?; + Ok(()) + } +} + +#[derive(Debug, Subcommand)] +enum Command { + Status, + Export(ExportArgs), + Import(ImportArgs), + TransferLeader(TransferLeaderArgs), + BenchClientNumConn, +} + /// Usage: /// - To dump a sled db: `$0 --raft-dir ./_your_meta_dir/`: /// ``` @@ -124,7 +335,7 @@ impl From for RaftConfig { /// ``` #[tokio::main] async fn main() -> anyhow::Result<()> { - let config = Config::parse(); + let app = App::parse(); let log_config = LogConfig { file: FileConfig { @@ -137,136 +348,54 @@ async fn main() -> anyhow::Result<()> { }, ..Default::default() }; - let _guards = init_logging("metactl", &log_config, BTreeMap::new()); - if config.status { - return show_status(&config).await; - } - - eprintln!(); - eprintln!("╔╦╗╔═╗╔╦╗╔═╗ ╔═╗╔╦╗╦ "); - eprintln!("║║║║╣ ║ ╠═╣───║ ║ ║ "); - eprintln!("╩ ╩╚═╝ ╩ ╩ ╩ ╚═╝ ╩ ╩═╝ Databend"); - eprintln!(); - eprintln!("Version: {}", METASRV_COMMIT_VERSION.as_str()); - eprintln!("Working DataVersion: {:?}", DATA_VERSION); - eprintln!(); - eprintln!("Id: {}", config.id); - eprintln!("Log:"); - eprintln!(" File: {}", log_config.file); - eprintln!(" Stderr: {}", log_config.stderr); - - if !config.cmd.is_empty() { - return match config.cmd.as_str() { - "bench-client-conn-num" => { - bench_client_num_conn(&config).await?; - Ok(()) + match &args.command { + Some(cmd) => match cmd { + Command::Status => { + app.show_status().await?; + } + Command::BenchClientNumConn => { + app.bench_client_num_conn().await?; + } + Command::TransferLeader(args) => { + app.transfer_leader(args).await?; + } + Command::Export(args) => { + app.export(args).await?; + } + Command::Import(args) => { + app.import(args).await?; } - _ => { - eprintln!("valid commands are"); - eprintln!(" --cmd bench-client-conn-num"); - eprintln!(" Keep create new connections to metasrv."); - eprintln!(" Requires --grpc-api-address."); - - Err(anyhow::anyhow!("unknown cmd: {}", config.cmd)) + app.print_help()?; + } + }, + // for backward compatibility + None => { + if app.globals.export { + let args = ExportArgs { + raft_dir: app.globals.raft_dir.clone(), + db: app.globals.db.clone(), + id: app.globals.id, + chunk_size: app.globals.export_chunk_size, + }; + app.export(&args).await?; } - }; - } - - if config.export { - return export_data(&config).await; - } - - if config.import { - return import::import_data(&config).await; - } - - Err(anyhow::anyhow!("Nothing to do")) -} - -async fn bench_client_num_conn(conf: &Config) -> anyhow::Result<()> { - let addr = &conf.grpc_api_address; - - println!( - "loop: connect to metasrv {}, get_kv('foo'), do not drop the connection", - addr - ); - - let mut clients = vec![]; - let mut i = 0; - - loop { - i += 1; - let client = - MetaGrpcClient::try_create(vec![addr.to_string()], "root", "xxx", None, None, None)?; - - let res = client.get_kv("foo").await; - println!("{}-th: get_kv(foo): {:?}", i, res); - - clients.push(client); - } -} -async fn show_status(conf: &Config) -> anyhow::Result<()> { - let addr = &conf.grpc_api_address; - - let client = - MetaGrpcClient::try_create(vec![addr.to_string()], "root", "xxx", None, None, None)?; - - let res = client.get_cluster_status().await?; - println!("BinaryVersion: {}", res.binary_version); - println!("DataVersion: {}", res.data_version); - println!("DBSize: {}", res.db_size); - println!("KeyNumber: {}", res.key_num); - println!("Node: id={} raft={}", res.id, res.endpoint); - println!("State: {}", res.state); - if let Some(leader) = res.leader { - println!("Leader: {}", leader); - } - println!("CurrentTerm: {}", res.current_term); - println!("LastSeq: {:?}", res.last_seq); - println!("LastLogIndex: {}", res.last_log_index); - println!("LastApplied: {}", res.last_applied); - if let Some(last_log_id) = res.snapshot_last_log_id { - println!("SnapshotLastLogID: {}", last_log_id); - } - if let Some(purged) = res.purged { - println!("Purged: {}", purged); - } - if !res.replication.is_empty() { - println!("Replication:"); - for (k, v) in res.replication { - if v != res.last_applied { - println!(" - [{}] {} *", k, v); - } else { - println!(" - [{}] {}", k, v); + if app.globals.import { + let args = ImportArgs { + raft_dir: app.globals.raft_dir.clone(), + db: app.globals.db.clone(), + id: app.globals.id, + initial_cluster: app.globals.initial_cluster.clone(), + }; + app.import(&args).await?; } - } - } - if !res.voters.is_empty() { - println!("Voters:"); - for v in res.voters { - println!(" - {}", v); - } - } - if !res.non_voters.is_empty() { - println!("NonVoters:"); - for v in res.non_voters { - println!(" - {}", v); - } - } - Ok(()) -} -pub async fn export_data(config: &Config) -> anyhow::Result<()> { - match config.raft_dir { - None => export_from_grpc::export_from_running_node(config).await?, - Some(ref dir) => { - init_sled_db(dir.clone(), 64 * 1024 * 1024 * 1024); - export_from_disk::export_from_dir(config).await?; + app.print_help()?; } } + Ok(()) } diff --git a/src/meta/binaries/metactl/upgrade.rs b/src/meta/binaries/metactl/upgrade.rs index adca1faae505..18678b9a9c48 100644 --- a/src/meta/binaries/metactl/upgrade.rs +++ b/src/meta/binaries/metactl/upgrade.rs @@ -16,15 +16,11 @@ use databend_common_meta_raft_store::config::RaftConfig; use databend_common_meta_raft_store::ondisk::OnDisk; use databend_common_meta_sled_store::get_sled_db; -use crate::Config; - /// Upgrade the data in raft_dir to the latest version. -pub async fn upgrade(config: &Config) -> anyhow::Result<()> { - let raft_config: RaftConfig = config.clone().into(); - +pub async fn upgrade(raft_config: &RaftConfig) -> anyhow::Result<()> { let db = get_sled_db(); - let mut on_disk = OnDisk::open(&db, &raft_config).await?; + let mut on_disk = OnDisk::open(&db, raft_config).await?; on_disk.log_stderr(true); on_disk.upgrade().await?; From cade2bb8cf74e3b3d3f3b37f4d2c0d2871dbee7f Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 16:25:40 +0800 Subject: [PATCH 02/30] z --- src/meta/binaries/metactl/admin.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/meta/binaries/metactl/admin.rs b/src/meta/binaries/metactl/admin.rs index 0e12c0e0fca2..70092951a351 100644 --- a/src/meta/binaries/metactl/admin.rs +++ b/src/meta/binaries/metactl/admin.rs @@ -35,17 +35,14 @@ impl MetaAdminClient { .get(format!("{}/v1/cluster/status", self.endpoint)) .send() .await?; - if resp.status().is_success() { + let status = resp.status(); + if status.is_success() { let result = resp.json::().await?; Ok(result) } else { let data = resp.bytes().await?; let msg = String::from_utf8_lossy(&data); - Err(anyhow::anyhow!( - "status code: {}, msg: {}", - resp.status(), - msg - )) + Err(anyhow::anyhow!("status code: {}, msg: {}", status, msg)) } } From 51c0763f4ef67ae3deefa662e7e2f7a31c2885b6 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 16:26:35 +0800 Subject: [PATCH 03/30] z --- src/meta/binaries/metactl/main.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/meta/binaries/metactl/main.rs b/src/meta/binaries/metactl/main.rs index 71572462bdfd..1c403fb07b8d 100644 --- a/src/meta/binaries/metactl/main.rs +++ b/src/meta/binaries/metactl/main.rs @@ -68,42 +68,42 @@ struct GlobalArgs { #[clap(long)] pub export: bool, + /// DEPRECATED /// The dir to store persisted meta state, including raft logs, state machine etc. - #[deprecated] #[clap(long)] #[serde(alias = "kvsrv_raft_dir")] pub raft_dir: Option, + /// DEPRECATED /// The N.O. json strings in a export stream item. /// /// Set this to a smaller value if you get gRPC message body too large error. /// This requires meta-service >= 1.2.315; For older version, this argument is ignored. /// /// By default it is 32. - #[deprecated] #[clap(long)] pub export_chunk_size: Option, + /// DEPRECATED /// When export raft data, this is the name of the save db file. /// If `db` is empty, output the exported data as json to stdout instead. /// When import raft data, this is the name of the restored db file. /// If `db` is empty, the restored data is from stdin instead. - #[deprecated] #[clap(long, default_value = "")] pub db: String, + /// DEPRECATED /// initial_cluster format: node_id=endpoint,grpc_api_addr - #[deprecated] #[clap(long)] pub initial_cluster: Vec, + /// DEPRECATED /// The node id. Used in these cases: /// /// 1. when this server is not initialized, e.g. --boot or --single for the first time. /// 2. --initial_cluster with new cluster node id. /// /// Otherwise this argument is ignored. - #[deprecated] #[clap(long, default_value = "0")] #[serde(alias = "kvsrv_id")] pub id: u64, From 077f303ad3d24c0b56eeb4fe90b8212945b8bf15 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 16:27:40 +0800 Subject: [PATCH 04/30] z --- src/meta/binaries/metactl/main.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/meta/binaries/metactl/main.rs b/src/meta/binaries/metactl/main.rs index 1c403fb07b8d..a359dfb8af59 100644 --- a/src/meta/binaries/metactl/main.rs +++ b/src/meta/binaries/metactl/main.rs @@ -109,7 +109,7 @@ struct GlobalArgs { pub id: u64, } -#[derive(Debug, Args)] +#[derive(Debug, Clone, Args)] struct ExportArgs { /// The dir to store persisted meta state, including raft logs, state machine etc. #[clap(long)] @@ -152,7 +152,7 @@ impl From for RaftConfig { } } -#[derive(Debug, Args)] +#[derive(Debug, Clone, Args)] struct ImportArgs { /// The dir to store persisted meta state, including raft logs, state machine etc. #[clap(long)] @@ -190,7 +190,7 @@ impl From for RaftConfig { } } -#[derive(Debug, Args)] +#[derive(Debug, Clone, Args)] struct TransferLeaderArgs { #[clap(long)] pub to: Option, @@ -315,7 +315,7 @@ impl App { } } -#[derive(Debug, Subcommand)] +#[derive(Debug, Clone, Subcommand)] enum Command { Status, Export(ExportArgs), From 995208ee7de81a447906fdeab110ca5da1d25334 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 16:30:14 +0800 Subject: [PATCH 05/30] z --- src/meta/binaries/metactl/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/meta/binaries/metactl/main.rs b/src/meta/binaries/metactl/main.rs index a359dfb8af59..133cffe00245 100644 --- a/src/meta/binaries/metactl/main.rs +++ b/src/meta/binaries/metactl/main.rs @@ -60,11 +60,11 @@ struct GlobalArgs { )] pub admin_api_address: String, - #[deprecated] + /// DEPRECATED #[clap(long)] pub import: bool, - #[deprecated] + /// DEPRECATED #[clap(long)] pub export: bool, From 0e2b7031413a81f1733200cfc55f16abc4b1a571 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 16:31:13 +0800 Subject: [PATCH 06/30] z --- src/meta/binaries/metactl/main.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/meta/binaries/metactl/main.rs b/src/meta/binaries/metactl/main.rs index 133cffe00245..3c5e3f148355 100644 --- a/src/meta/binaries/metactl/main.rs +++ b/src/meta/binaries/metactl/main.rs @@ -298,8 +298,11 @@ impl App { async fn export(&self, args: &ExportArgs) -> anyhow::Result<()> { match args.raft_dir { None => { - export_from_grpc::export_from_running_node(&self.globals.grpc_api_address, args) - .await?; + export_from_grpc::export_from_running_node( + self.globals.grpc_api_address.as_str(), + args, + ) + .await?; } Some(ref dir) => { init_sled_db(dir.clone(), 64 * 1024 * 1024 * 1024); @@ -310,7 +313,7 @@ impl App { } async fn import(&self, args: &ImportArgs) -> anyhow::Result<()> { - import::import_data(&args).await?; + import::import_data(args).await?; Ok(()) } } From 20f61f87a881b09c90001303a6310b79835212e6 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 16:34:56 +0800 Subject: [PATCH 07/30] z --- src/meta/binaries/metactl/admin.rs | 9 +++---- src/meta/binaries/metactl/export_from_grpc.rs | 4 +-- src/meta/binaries/metactl/main.rs | 25 ++++++------------- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/meta/binaries/metactl/admin.rs b/src/meta/binaries/metactl/admin.rs index 70092951a351..35e1c6014297 100644 --- a/src/meta/binaries/metactl/admin.rs +++ b/src/meta/binaries/metactl/admin.rs @@ -67,17 +67,14 @@ impl MetaAdminClient { .await? } }; - if resp.status().is_success() { + let status = resp.status(); + if status.is_success() { let result = resp.json::().await?; Ok(result) } else { let data = resp.bytes().await?; let msg = String::from_utf8_lossy(&data); - Err(anyhow::anyhow!( - "status code: {}, msg: {}", - resp.status(), - msg - )) + Err(anyhow::anyhow!("status code: {}, msg: {}", status, msg)) } } } diff --git a/src/meta/binaries/metactl/export_from_grpc.rs b/src/meta/binaries/metactl/export_from_grpc.rs index 77c60ea69d2a..0ae6c5e3e77f 100644 --- a/src/meta/binaries/metactl/export_from_grpc.rs +++ b/src/meta/binaries/metactl/export_from_grpc.rs @@ -33,14 +33,14 @@ pub async fn export_from_running_node(addr: &str, args: &ExportArgs) -> Result<( eprintln!("Export:"); eprintln!(" From: online meta-service: {}", addr); eprintln!(" Export To: {}", args.db); - eprintln!(" Export Chunk Size: {:?}", args.export_chunk_size); + eprintln!(" Export Chunk Size: {:?}", args.chunk_size); let grpc_api_addr = get_available_socket_addr(addr).await?; export_from_grpc( grpc_api_addr.to_string().as_str(), args.db.clone(), - args.export_chunk_size, + args.chunk_size, ) .await?; Ok(()) diff --git a/src/meta/binaries/metactl/main.rs b/src/meta/binaries/metactl/main.rs index 3c5e3f148355..ad005fa37f73 100644 --- a/src/meta/binaries/metactl/main.rs +++ b/src/meta/binaries/metactl/main.rs @@ -214,10 +214,9 @@ impl App { } pub async fn show_status(&self) -> anyhow::Result<()> { - let addr = self.globals.grpc_api_address; + let addr = self.globals.grpc_api_address.clone(); - let client = - MetaGrpcClient::try_create(vec![addr.to_string()], "root", "xxx", None, None, None)?; + let client = MetaGrpcClient::try_create(vec![addr], "root", "xxx", None, None, None)?; let res = client.get_cluster_status().await?; println!("BinaryVersion: {}", res.binary_version); @@ -265,7 +264,7 @@ impl App { } async fn bench_client_num_conn(&self) -> anyhow::Result<()> { - let addr = self.globals.grpc_api_address; + let addr = self.globals.grpc_api_address.clone(); println!( "loop: connect to metasrv {}, get_kv('foo'), do not drop the connection", addr @@ -274,14 +273,7 @@ impl App { let mut i = 0; loop { i += 1; - let client = MetaGrpcClient::try_create( - vec![addr.to_string()], - "root", - "xxx", - None, - None, - None, - )?; + let client = MetaGrpcClient::try_create(vec![addr], "root", "xxx", None, None, None)?; let res = client.get_kv("foo").await; println!("{}-th: get_kv(foo): {:?}", i, res); clients.push(client); @@ -289,8 +281,7 @@ impl App { } async fn transfer_leader(&self, args: &TransferLeaderArgs) -> anyhow::Result<()> { - let addr = self.globals.grpc_api_address; - let client = MetaAdminClient::new(&addr); + let client = MetaAdminClient::new(self.globals.admin_api_address.as_str()); client.transfer_leader(args.to).await?; Ok(()) } @@ -362,13 +353,13 @@ async fn main() -> anyhow::Result<()> { app.bench_client_num_conn().await?; } Command::TransferLeader(args) => { - app.transfer_leader(args).await?; + app.transfer_leader(&args).await?; } Command::Export(args) => { - app.export(args).await?; + app.export(&args).await?; } Command::Import(args) => { - app.import(args).await?; + app.import(&args).await?; } _ => { app.print_help()?; From 33ee570b1c2c2ba3298219c1125dfe54177f22db Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 16:35:25 +0800 Subject: [PATCH 08/30] z --- src/meta/binaries/metactl/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/meta/binaries/metactl/main.rs b/src/meta/binaries/metactl/main.rs index ad005fa37f73..c6bdcc9ecc86 100644 --- a/src/meta/binaries/metactl/main.rs +++ b/src/meta/binaries/metactl/main.rs @@ -215,7 +215,6 @@ impl App { pub async fn show_status(&self) -> anyhow::Result<()> { let addr = self.globals.grpc_api_address.clone(); - let client = MetaGrpcClient::try_create(vec![addr], "root", "xxx", None, None, None)?; let res = client.get_cluster_status().await?; From 076106e9cbd286d9060e25aed349a23be489785d Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 16:38:26 +0800 Subject: [PATCH 09/30] z --- src/meta/binaries/metactl/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/meta/binaries/metactl/main.rs b/src/meta/binaries/metactl/main.rs index c6bdcc9ecc86..d82c6c23adc1 100644 --- a/src/meta/binaries/metactl/main.rs +++ b/src/meta/binaries/metactl/main.rs @@ -28,6 +28,7 @@ use admin::MetaAdminClient; use clap::Args; use clap::CommandFactory; use clap::Parser; +use clap::Subcommand; use databend_common_base::base::tokio; use databend_common_meta_client::MetaGrpcClient; use databend_common_meta_kvapi::kvapi::KVApi; @@ -343,7 +344,7 @@ async fn main() -> anyhow::Result<()> { }; let _guards = init_logging("metactl", &log_config, BTreeMap::new()); - match &args.command { + match app.command { Some(cmd) => match cmd { Command::Status => { app.show_status().await?; From ef491f0d22f7b05e8230a4c595dee785a13c5d58 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 16:41:34 +0800 Subject: [PATCH 10/30] z --- src/meta/binaries/metactl/export_from_disk.rs | 5 ++--- src/meta/binaries/metactl/main.rs | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/meta/binaries/metactl/export_from_disk.rs b/src/meta/binaries/metactl/export_from_disk.rs index c8a7b9e4450e..1215e3a78a17 100644 --- a/src/meta/binaries/metactl/export_from_disk.rs +++ b/src/meta/binaries/metactl/export_from_disk.rs @@ -30,13 +30,12 @@ use crate::ExportArgs; /// E.g.: /// `["state_machine/0",{"GenericKV":{"key":"wow","value":{"seq":3,"meta":null,"data":[119,111,119]}}}` pub async fn export_from_dir(args: &ExportArgs) -> anyhow::Result<()> { - upgrade::upgrade(args).await?; + let raft_config: RaftConfig = args.clone().into(); + upgrade::upgrade(&raft_config).await?; eprintln!(); eprintln!("Export:"); - let raft_config: RaftConfig = args.clone().into(); - let sto_inn = StoreInner::open_create(&raft_config, Some(()), None).await?; let mut lines = Arc::new(sto_inn).export(); diff --git a/src/meta/binaries/metactl/main.rs b/src/meta/binaries/metactl/main.rs index d82c6c23adc1..2c30982e2d52 100644 --- a/src/meta/binaries/metactl/main.rs +++ b/src/meta/binaries/metactl/main.rs @@ -273,7 +273,8 @@ impl App { let mut i = 0; loop { i += 1; - let client = MetaGrpcClient::try_create(vec![addr], "root", "xxx", None, None, None)?; + let client = + MetaGrpcClient::try_create(vec![addr.clone()], "root", "xxx", None, None, None)?; let res = client.get_kv("foo").await; println!("{}-th: get_kv(foo): {:?}", i, res); clients.push(client); From 7d56c6905291cf17e13bac185ffbc5b815fe14fd Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 16:43:16 +0800 Subject: [PATCH 11/30] z --- src/meta/binaries/metactl/main.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/meta/binaries/metactl/main.rs b/src/meta/binaries/metactl/main.rs index 2c30982e2d52..56652b7d57b7 100644 --- a/src/meta/binaries/metactl/main.rs +++ b/src/meta/binaries/metactl/main.rs @@ -42,7 +42,7 @@ use databend_meta::version::METASRV_COMMIT_VERSION; use serde::Deserialize; use serde::Serialize; -#[derive(Debug, PartialEq, Args)] +#[derive(Debug, Clone, Deserialize, Args)] struct GlobalArgs { #[clap(long, default_value = "INFO")] pub log_level: String, @@ -110,7 +110,7 @@ struct GlobalArgs { pub id: u64, } -#[derive(Debug, Clone, Args)] +#[derive(Debug, Clone, Deserialize, Args)] struct ExportArgs { /// The dir to store persisted meta state, including raft logs, state machine etc. #[clap(long)] @@ -153,7 +153,7 @@ impl From for RaftConfig { } } -#[derive(Debug, Clone, Args)] +#[derive(Debug, Clone, Deserialize, Args)] struct ImportArgs { /// The dir to store persisted meta state, including raft logs, state machine etc. #[clap(long)] @@ -191,13 +191,13 @@ impl From for RaftConfig { } } -#[derive(Debug, Clone, Args)] +#[derive(Debug, Clone, Deserialize, Args)] struct TransferLeaderArgs { #[clap(long)] pub to: Option, } -#[derive(Debug, Parser)] +#[derive(Debug, Deserialize, Parser)] #[clap(name = "databend-metactl", about, version = &**METASRV_COMMIT_VERSION, author)] pub struct App { #[clap(long, default_value = "")] @@ -335,7 +335,7 @@ async fn main() -> anyhow::Result<()> { let log_config = LogConfig { file: FileConfig { on: true, - level: config.log_level.clone(), + level: app.globals.log_level.clone(), dir: ".databend/logs".to_string(), format: "text".to_string(), limit: 48, From 072de968e7ec30a71f8957e9360ea05e4356a312 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 16:45:04 +0800 Subject: [PATCH 12/30] z --- src/meta/binaries/metactl/main.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/meta/binaries/metactl/main.rs b/src/meta/binaries/metactl/main.rs index 56652b7d57b7..20b0ea1886ec 100644 --- a/src/meta/binaries/metactl/main.rs +++ b/src/meta/binaries/metactl/main.rs @@ -310,7 +310,7 @@ impl App { } } -#[derive(Debug, Clone, Subcommand)] +#[derive(Debug, Clone, Deserialize, Subcommand)] enum Command { Status, Export(ExportArgs), @@ -346,7 +346,7 @@ async fn main() -> anyhow::Result<()> { let _guards = init_logging("metactl", &log_config, BTreeMap::new()); match app.command { - Some(cmd) => match cmd { + Some(ref cmd) => match cmd { Command::Status => { app.show_status().await?; } @@ -362,9 +362,6 @@ async fn main() -> anyhow::Result<()> { Command::Import(args) => { app.import(&args).await?; } - _ => { - app.print_help()?; - } }, // for backward compatibility None => { From 704cbe549205ca3dcf49946e51e7c2d058e7aacb Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 16:50:00 +0800 Subject: [PATCH 13/30] z --- src/meta/binaries/metactl/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/meta/binaries/metactl/main.rs b/src/meta/binaries/metactl/main.rs index 20b0ea1886ec..138bcb06d8d2 100644 --- a/src/meta/binaries/metactl/main.rs +++ b/src/meta/binaries/metactl/main.rs @@ -200,8 +200,8 @@ struct TransferLeaderArgs { #[derive(Debug, Deserialize, Parser)] #[clap(name = "databend-metactl", about, version = &**METASRV_COMMIT_VERSION, author)] pub struct App { - #[clap(long, default_value = "")] - pub command: Option, + #[clap(subcommand)] + pub command: Option, #[clap(flatten)] pub globals: GlobalArgs, @@ -311,7 +311,7 @@ impl App { } #[derive(Debug, Clone, Deserialize, Subcommand)] -enum Command { +enum CtlCommand { Status, Export(ExportArgs), Import(ImportArgs), From 6f8f18afe8571b98f051297655a9ea5d53314727 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 16:51:59 +0800 Subject: [PATCH 14/30] z --- src/meta/binaries/metactl/main.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/meta/binaries/metactl/main.rs b/src/meta/binaries/metactl/main.rs index 138bcb06d8d2..0afed6a169f2 100644 --- a/src/meta/binaries/metactl/main.rs +++ b/src/meta/binaries/metactl/main.rs @@ -347,19 +347,19 @@ async fn main() -> anyhow::Result<()> { match app.command { Some(ref cmd) => match cmd { - Command::Status => { + CtlCommand::Status => { app.show_status().await?; } - Command::BenchClientNumConn => { + CtlCommand::BenchClientNumConn => { app.bench_client_num_conn().await?; } - Command::TransferLeader(args) => { + CtlCommand::TransferLeader(args) => { app.transfer_leader(&args).await?; } - Command::Export(args) => { + CtlCommand::Export(args) => { app.export(&args).await?; } - Command::Import(args) => { + CtlCommand::Import(args) => { app.import(&args).await?; } }, From 6d549afcbca34366ed90eed9687da3ba0fd66d57 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 16:52:32 +0800 Subject: [PATCH 15/30] z --- src/meta/binaries/metactl/main.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/meta/binaries/metactl/main.rs b/src/meta/binaries/metactl/main.rs index 0afed6a169f2..2680acf50f72 100644 --- a/src/meta/binaries/metactl/main.rs +++ b/src/meta/binaries/metactl/main.rs @@ -33,14 +33,12 @@ use databend_common_base::base::tokio; use databend_common_meta_client::MetaGrpcClient; use databend_common_meta_kvapi::kvapi::KVApi; use databend_common_meta_raft_store::config::RaftConfig; -use databend_common_meta_raft_store::ondisk::DATA_VERSION; use databend_common_meta_sled_store::init_sled_db; use databend_common_tracing::init_logging; use databend_common_tracing::Config as LogConfig; use databend_common_tracing::FileConfig; use databend_meta::version::METASRV_COMMIT_VERSION; use serde::Deserialize; -use serde::Serialize; #[derive(Debug, Clone, Deserialize, Args)] struct GlobalArgs { From 48e22d54bdb48f7856ff53f874e01920aaad47c0 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 16:54:33 +0800 Subject: [PATCH 16/30] z --- src/meta/binaries/metactl/main.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/meta/binaries/metactl/main.rs b/src/meta/binaries/metactl/main.rs index 2680acf50f72..3048a697d317 100644 --- a/src/meta/binaries/metactl/main.rs +++ b/src/meta/binaries/metactl/main.rs @@ -41,7 +41,7 @@ use databend_meta::version::METASRV_COMMIT_VERSION; use serde::Deserialize; #[derive(Debug, Clone, Deserialize, Args)] -struct GlobalArgs { +pub struct GlobalArgs { #[clap(long, default_value = "INFO")] pub log_level: String, @@ -109,7 +109,7 @@ struct GlobalArgs { } #[derive(Debug, Clone, Deserialize, Args)] -struct ExportArgs { +pub struct ExportArgs { /// The dir to store persisted meta state, including raft logs, state machine etc. #[clap(long)] #[serde(alias = "kvsrv_raft_dir")] @@ -152,7 +152,7 @@ impl From for RaftConfig { } #[derive(Debug, Clone, Deserialize, Args)] -struct ImportArgs { +pub struct ImportArgs { /// The dir to store persisted meta state, including raft logs, state machine etc. #[clap(long)] #[serde(alias = "kvsrv_raft_dir")] @@ -190,7 +190,7 @@ impl From for RaftConfig { } #[derive(Debug, Clone, Deserialize, Args)] -struct TransferLeaderArgs { +pub struct TransferLeaderArgs { #[clap(long)] pub to: Option, } @@ -206,13 +206,13 @@ pub struct App { } impl App { - pub fn print_help(&self) -> anyhow::Result<()> { + fn print_help(&self) -> anyhow::Result<()> { let mut cmd = Self::command(); cmd.print_help()?; Ok(()) } - pub async fn show_status(&self) -> anyhow::Result<()> { + async fn show_status(&self) -> anyhow::Result<()> { let addr = self.globals.grpc_api_address.clone(); let client = MetaGrpcClient::try_create(vec![addr], "root", "xxx", None, None, None)?; From 0b68e93fcbf3cf535f8ef83bb5f06bcde15e941e Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 16:58:40 +0800 Subject: [PATCH 17/30] z --- src/meta/binaries/metactl/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/meta/binaries/metactl/main.rs b/src/meta/binaries/metactl/main.rs index 3048a697d317..ba654e43ea02 100644 --- a/src/meta/binaries/metactl/main.rs +++ b/src/meta/binaries/metactl/main.rs @@ -197,12 +197,12 @@ pub struct TransferLeaderArgs { #[derive(Debug, Deserialize, Parser)] #[clap(name = "databend-metactl", about, version = &**METASRV_COMMIT_VERSION, author)] -pub struct App { +struct App { #[clap(subcommand)] - pub command: Option, + command: Option, #[clap(flatten)] - pub globals: GlobalArgs, + globals: GlobalArgs, } impl App { From 6be3668cbc053c3b67c5b2038b43c1d87a12efd1 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 17:10:45 +0800 Subject: [PATCH 18/30] z --- src/meta/binaries/metactl/export_from_grpc.rs | 4 +- src/meta/binaries/metactl/main.rs | 55 +++++++++++-------- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/src/meta/binaries/metactl/export_from_grpc.rs b/src/meta/binaries/metactl/export_from_grpc.rs index 0ae6c5e3e77f..d982d8ffb008 100644 --- a/src/meta/binaries/metactl/export_from_grpc.rs +++ b/src/meta/binaries/metactl/export_from_grpc.rs @@ -28,7 +28,7 @@ use tokio_stream::StreamExt; use crate::ExportArgs; /// Dump metasrv data, raft-log, state machine etc in json to stdout. -pub async fn export_from_running_node(addr: &str, args: &ExportArgs) -> Result<(), anyhow::Error> { +pub async fn export_from_running_node(args: &ExportArgs) -> Result<(), anyhow::Error> { eprintln!(); eprintln!("Export:"); eprintln!(" From: online meta-service: {}", addr); @@ -38,7 +38,7 @@ pub async fn export_from_running_node(addr: &str, args: &ExportArgs) -> Result<( let grpc_api_addr = get_available_socket_addr(addr).await?; export_from_grpc( - grpc_api_addr.to_string().as_str(), + args.grpc_api_addr.as_str(), args.db.clone(), args.chunk_size, ) diff --git a/src/meta/binaries/metactl/main.rs b/src/meta/binaries/metactl/main.rs index ba654e43ea02..85a18c6c1666 100644 --- a/src/meta/binaries/metactl/main.rs +++ b/src/meta/binaries/metactl/main.rs @@ -45,6 +45,7 @@ pub struct GlobalArgs { #[clap(long, default_value = "INFO")] pub log_level: String, + /// DEPRECATED #[clap( long, env = "METASRV_GRPC_API_ADDRESS", @@ -52,13 +53,6 @@ pub struct GlobalArgs { )] pub grpc_api_address: String, - #[clap( - long, - env = "METASRV_ADMIN_API_ADDRESS", - default_value = "127.0.0.1:28002" - )] - pub admin_api_address: String, - /// DEPRECATED #[clap(long)] pub import: bool, @@ -108,8 +102,17 @@ pub struct GlobalArgs { pub id: u64, } +#[derive(Debug, Clone, Deserialize, Args)] +pub struct StatusArgs { + #[clap(long, default_value = "127.0.0.1:9191")] + pub grpc_api_address: String, +} + #[derive(Debug, Clone, Deserialize, Args)] pub struct ExportArgs { + #[clap(long, default_value = "127.0.0.1:9191")] + pub grpc_api_address: String, + /// The dir to store persisted meta state, including raft logs, state machine etc. #[clap(long)] #[serde(alias = "kvsrv_raft_dir")] @@ -193,6 +196,15 @@ impl From for RaftConfig { pub struct TransferLeaderArgs { #[clap(long)] pub to: Option, + + #[clap(long, default_value = "127.0.0.1:28002")] + pub admin_api_address: String, +} + +#[derive(Debug, Clone, Deserialize, Args)] +pub struct BenchArgs { + #[clap(long, default_value = "127.0.0.1:9191")] + pub grpc_api_address: String, } #[derive(Debug, Deserialize, Parser)] @@ -212,8 +224,8 @@ impl App { Ok(()) } - async fn show_status(&self) -> anyhow::Result<()> { - let addr = self.globals.grpc_api_address.clone(); + async fn show_status(&self, args: &StatusArgs) -> anyhow::Result<()> { + let addr = args.grpc_api_address.clone(); let client = MetaGrpcClient::try_create(vec![addr], "root", "xxx", None, None, None)?; let res = client.get_cluster_status().await?; @@ -261,8 +273,8 @@ impl App { Ok(()) } - async fn bench_client_num_conn(&self) -> anyhow::Result<()> { - let addr = self.globals.grpc_api_address.clone(); + async fn bench_client_num_conn(&self, args: &BenchArgs) -> anyhow::Result<()> { + let addr = args.grpc_api_address.clone(); println!( "loop: connect to metasrv {}, get_kv('foo'), do not drop the connection", addr @@ -280,7 +292,7 @@ impl App { } async fn transfer_leader(&self, args: &TransferLeaderArgs) -> anyhow::Result<()> { - let client = MetaAdminClient::new(self.globals.admin_api_address.as_str()); + let client = MetaAdminClient::new(args.admin_api_address.as_str()); client.transfer_leader(args.to).await?; Ok(()) } @@ -288,11 +300,7 @@ impl App { async fn export(&self, args: &ExportArgs) -> anyhow::Result<()> { match args.raft_dir { None => { - export_from_grpc::export_from_running_node( - self.globals.grpc_api_address.as_str(), - args, - ) - .await?; + export_from_grpc::export_from_running_node(args).await?; } Some(ref dir) => { init_sled_db(dir.clone(), 64 * 1024 * 1024 * 1024); @@ -310,11 +318,11 @@ impl App { #[derive(Debug, Clone, Deserialize, Subcommand)] enum CtlCommand { - Status, + Status(StatusArgs), Export(ExportArgs), Import(ImportArgs), TransferLeader(TransferLeaderArgs), - BenchClientNumConn, + BenchClientNumConn(BenchArgs), } /// Usage: @@ -345,11 +353,11 @@ async fn main() -> anyhow::Result<()> { match app.command { Some(ref cmd) => match cmd { - CtlCommand::Status => { - app.show_status().await?; + CtlCommand::Status(args) => { + app.show_status(&args).await?; } - CtlCommand::BenchClientNumConn => { - app.bench_client_num_conn().await?; + CtlCommand::BenchClientNumConn(args) => { + app.bench_client_num_conn(&args).await?; } CtlCommand::TransferLeader(args) => { app.transfer_leader(&args).await?; @@ -365,6 +373,7 @@ async fn main() -> anyhow::Result<()> { None => { if app.globals.export { let args = ExportArgs { + grpc_api_address: app.globals.grpc_api_address.clone(), raft_dir: app.globals.raft_dir.clone(), db: app.globals.db.clone(), id: app.globals.id, From 217401767ad1075a3c7bf871b918962997d8c2e9 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 17:11:35 +0800 Subject: [PATCH 19/30] z --- src/meta/binaries/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/meta/binaries/Cargo.toml b/src/meta/binaries/Cargo.toml index 571f9782f4ee..d201d2032092 100644 --- a/src/meta/binaries/Cargo.toml +++ b/src/meta/binaries/Cargo.toml @@ -44,11 +44,11 @@ fastrace = { workspace = true } futures = { workspace = true } log = { workspace = true } rand = { workspace = true } +reqwest = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } tokio = { workspace = true } tokio-stream = { workspace = true } -reqwest = { workspace = true } url = "2.3.1" [[bin]] From c806a5453a1ba5cdd0fa46007b6a51f86f5abbd3 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 17:13:55 +0800 Subject: [PATCH 20/30] z --- src/meta/binaries/metactl/export_from_grpc.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/meta/binaries/metactl/export_from_grpc.rs b/src/meta/binaries/metactl/export_from_grpc.rs index d982d8ffb008..c05b31aa7399 100644 --- a/src/meta/binaries/metactl/export_from_grpc.rs +++ b/src/meta/binaries/metactl/export_from_grpc.rs @@ -31,14 +31,14 @@ use crate::ExportArgs; pub async fn export_from_running_node(args: &ExportArgs) -> Result<(), anyhow::Error> { eprintln!(); eprintln!("Export:"); - eprintln!(" From: online meta-service: {}", addr); + eprintln!(" From: online meta-service: {}", args.grpc_api_address); eprintln!(" Export To: {}", args.db); eprintln!(" Export Chunk Size: {:?}", args.chunk_size); - let grpc_api_addr = get_available_socket_addr(addr).await?; + let grpc_api_addr = get_available_socket_addr(args.grpc_api_address.as_str()).await?; export_from_grpc( - args.grpc_api_addr.as_str(), + args.grpc_api_address.as_str(), args.db.clone(), args.chunk_size, ) From bac7e587d75f2d279f98167b8ea0bcb489c56352 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 17:15:59 +0800 Subject: [PATCH 21/30] z --- src/meta/binaries/metactl/export_from_grpc.rs | 8 ++------ src/meta/binaries/metactl/main.rs | 10 +++++----- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/meta/binaries/metactl/export_from_grpc.rs b/src/meta/binaries/metactl/export_from_grpc.rs index c05b31aa7399..abbed802d65f 100644 --- a/src/meta/binaries/metactl/export_from_grpc.rs +++ b/src/meta/binaries/metactl/export_from_grpc.rs @@ -36,13 +36,9 @@ pub async fn export_from_running_node(args: &ExportArgs) -> Result<(), anyhow::E eprintln!(" Export Chunk Size: {:?}", args.chunk_size); let grpc_api_addr = get_available_socket_addr(args.grpc_api_address.as_str()).await?; + let addr = grpc_api_addr.to_string(); - export_from_grpc( - args.grpc_api_address.as_str(), - args.db.clone(), - args.chunk_size, - ) - .await?; + export_from_grpc(addr.as_str(), args.db.clone(), args.chunk_size).await?; Ok(()) } diff --git a/src/meta/binaries/metactl/main.rs b/src/meta/binaries/metactl/main.rs index 85a18c6c1666..a42435037df9 100644 --- a/src/meta/binaries/metactl/main.rs +++ b/src/meta/binaries/metactl/main.rs @@ -354,19 +354,19 @@ async fn main() -> anyhow::Result<()> { match app.command { Some(ref cmd) => match cmd { CtlCommand::Status(args) => { - app.show_status(&args).await?; + app.show_status(args).await?; } CtlCommand::BenchClientNumConn(args) => { - app.bench_client_num_conn(&args).await?; + app.bench_client_num_conn(args).await?; } CtlCommand::TransferLeader(args) => { - app.transfer_leader(&args).await?; + app.transfer_leader(args).await?; } CtlCommand::Export(args) => { - app.export(&args).await?; + app.export(args).await?; } CtlCommand::Import(args) => { - app.import(&args).await?; + app.import(args).await?; } }, // for backward compatibility From b851f16754d22ed14bcd55c5058c286684017a9b Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 17:16:07 +0800 Subject: [PATCH 22/30] z --- src/meta/binaries/metactl/export_from_grpc.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/meta/binaries/metactl/export_from_grpc.rs b/src/meta/binaries/metactl/export_from_grpc.rs index abbed802d65f..8c497cc0ed3f 100644 --- a/src/meta/binaries/metactl/export_from_grpc.rs +++ b/src/meta/binaries/metactl/export_from_grpc.rs @@ -37,7 +37,6 @@ pub async fn export_from_running_node(args: &ExportArgs) -> Result<(), anyhow::E let grpc_api_addr = get_available_socket_addr(args.grpc_api_address.as_str()).await?; let addr = grpc_api_addr.to_string(); - export_from_grpc(addr.as_str(), args.db.clone(), args.chunk_size).await?; Ok(()) } From 2d289623c92ac9f5e5acec1663764ee9104a8110 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 17:20:18 +0800 Subject: [PATCH 23/30] z --- src/meta/binaries/metactl/admin.rs | 6 +++--- src/meta/binaries/metactl/main.rs | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/meta/binaries/metactl/admin.rs b/src/meta/binaries/metactl/admin.rs index 35e1c6014297..b5c53cb4c4ee 100644 --- a/src/meta/binaries/metactl/admin.rs +++ b/src/meta/binaries/metactl/admin.rs @@ -86,7 +86,7 @@ pub struct AdminStatusResponse { #[derive(Deserialize, Debug)] pub struct AdminTransferLeaderResponse { - from: u64, - to: u64, - voter_ids: Vec, + pub from: u64, + pub to: u64, + pub voter_ids: Vec, } diff --git a/src/meta/binaries/metactl/main.rs b/src/meta/binaries/metactl/main.rs index a42435037df9..770549128a2b 100644 --- a/src/meta/binaries/metactl/main.rs +++ b/src/meta/binaries/metactl/main.rs @@ -293,7 +293,12 @@ impl App { async fn transfer_leader(&self, args: &TransferLeaderArgs) -> anyhow::Result<()> { let client = MetaAdminClient::new(args.admin_api_address.as_str()); - client.transfer_leader(args.to).await?; + let result = client.transfer_leader(args.to).await?; + println!( + "triggered leader transfer from {} to {}.\n + voter list: {:?}", + result.from, result.to, result.voter_ids + ); Ok(()) } From bb68aaea0d43ba97140d27206341b1eac42347b3 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 17:27:24 +0800 Subject: [PATCH 24/30] z --- .../09_http_handler/09_0007_token.py | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/suites/1_stateful/09_http_handler/09_0007_token.py b/tests/suites/1_stateful/09_http_handler/09_0007_token.py index 5b7ccab59529..7921d4f2505b 100755 --- a/tests/suites/1_stateful/09_http_handler/09_0007_token.py +++ b/tests/suites/1_stateful/09_http_handler/09_0007_token.py @@ -43,7 +43,10 @@ def do_renew(_case_id, refresh_token, session_token): payload = {"session_token": session_token} response = requests.post( renew_url, - headers={"Content-Type": "application/json", "Authorization": f"Bearer {refresh_token}"}, + headers={ + "Content-Type": "application/json", + "Authorization": f"Bearer {refresh_token}", + }, json=payload, ) return response.json() @@ -54,15 +57,26 @@ def do_query(query, session_token): query_payload = {"sql": query, "pagination": {"wait_time_secs": 11}} response = requests.post( query_url, - headers={"Content-Type": "application/json", "Authorization": f"Bearer {session_token}"}, + headers={ + "Content-Type": "application/json", + "Authorization": f"Bearer {session_token}", + }, json=query_payload, ) return response.json() def fake_expired_token(): - expired_claim = {"exp": int(time.time()) - 10, "tenant": "", "user": "", "nonce": "", "sid": ""} - return "bend-v1-" + base64.b64encode(json.dumps(expired_claim).encode("utf-8")).decode("utf-8") + expired_claim = { + "exp": int(time.time()) - 10, + "tenant": "", + "user": "", + "nonce": "", + "sid": "", + } + return "bend-v1-" + base64.b64encode( + json.dumps(expired_claim).encode("utf-8") + ).decode("utf-8") def main(): From 8752df73018b9ba779b5cd03d54f852fb99444b8 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 17:55:02 +0800 Subject: [PATCH 25/30] z --- src/meta/binaries/metactl/main.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/meta/binaries/metactl/main.rs b/src/meta/binaries/metactl/main.rs index 770549128a2b..80556fe94ad4 100644 --- a/src/meta/binaries/metactl/main.rs +++ b/src/meta/binaries/metactl/main.rs @@ -45,7 +45,7 @@ pub struct GlobalArgs { #[clap(long, default_value = "INFO")] pub log_level: String, - /// DEPRECATED + /// DEPRECATED use subcommand instead. #[clap( long, env = "METASRV_GRPC_API_ADDRESS", @@ -53,7 +53,7 @@ pub struct GlobalArgs { )] pub grpc_api_address: String, - /// DEPRECATED + /// DEPRECATED use subcommand instead. #[clap(long)] pub import: bool, @@ -61,13 +61,15 @@ pub struct GlobalArgs { #[clap(long)] pub export: bool, - /// DEPRECATED + /// DEPRECATED use subcommand instead. + /// /// The dir to store persisted meta state, including raft logs, state machine etc. #[clap(long)] #[serde(alias = "kvsrv_raft_dir")] pub raft_dir: Option, - /// DEPRECATED + /// DEPRECATED use subcommand instead. + /// /// The N.O. json strings in a export stream item. /// /// Set this to a smaller value if you get gRPC message body too large error. @@ -77,7 +79,8 @@ pub struct GlobalArgs { #[clap(long)] pub export_chunk_size: Option, - /// DEPRECATED + /// DEPRECATED use subcommand instead. + /// /// When export raft data, this is the name of the save db file. /// If `db` is empty, output the exported data as json to stdout instead. /// When import raft data, this is the name of the restored db file. @@ -85,12 +88,14 @@ pub struct GlobalArgs { #[clap(long, default_value = "")] pub db: String, - /// DEPRECATED + /// DEPRECATED use subcommand instead. + /// /// initial_cluster format: node_id=endpoint,grpc_api_addr #[clap(long)] pub initial_cluster: Vec, - /// DEPRECATED + /// DEPRECATED use subcommand instead. + /// /// The node id. Used in these cases: /// /// 1. when this server is not initialized, e.g. --boot or --single for the first time. From 4a2d0e5bd67af1556f9087f34b9edebeb79d3a3f Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 17:59:26 +0800 Subject: [PATCH 26/30] z --- src/meta/binaries/metactl/main.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/meta/binaries/metactl/main.rs b/src/meta/binaries/metactl/main.rs index 80556fe94ad4..c9bf1a516f44 100644 --- a/src/meta/binaries/metactl/main.rs +++ b/src/meta/binaries/metactl/main.rs @@ -45,7 +45,7 @@ pub struct GlobalArgs { #[clap(long, default_value = "INFO")] pub log_level: String, - /// DEPRECATED use subcommand instead. + /// DEPRECATE: use subcommand instead. #[clap( long, env = "METASRV_GRPC_API_ADDRESS", @@ -53,7 +53,7 @@ pub struct GlobalArgs { )] pub grpc_api_address: String, - /// DEPRECATED use subcommand instead. + /// DEPRECATE: use subcommand instead. #[clap(long)] pub import: bool, @@ -61,14 +61,14 @@ pub struct GlobalArgs { #[clap(long)] pub export: bool, - /// DEPRECATED use subcommand instead. + /// DEPRECATE: use subcommand instead. /// /// The dir to store persisted meta state, including raft logs, state machine etc. #[clap(long)] #[serde(alias = "kvsrv_raft_dir")] pub raft_dir: Option, - /// DEPRECATED use subcommand instead. + /// DEPRECATE: use subcommand instead. /// /// The N.O. json strings in a export stream item. /// @@ -79,7 +79,7 @@ pub struct GlobalArgs { #[clap(long)] pub export_chunk_size: Option, - /// DEPRECATED use subcommand instead. + /// DEPRECATE: use subcommand instead. /// /// When export raft data, this is the name of the save db file. /// If `db` is empty, output the exported data as json to stdout instead. @@ -88,13 +88,13 @@ pub struct GlobalArgs { #[clap(long, default_value = "")] pub db: String, - /// DEPRECATED use subcommand instead. + /// DEPRECATE: use subcommand instead. /// /// initial_cluster format: node_id=endpoint,grpc_api_addr #[clap(long)] pub initial_cluster: Vec, - /// DEPRECATED use subcommand instead. + /// DEPRECATE: use subcommand instead. /// /// The node id. Used in these cases: /// From 775d87ba80ed7e82de4e0aadff477c4000e69021 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 18:03:02 +0800 Subject: [PATCH 27/30] z --- src/meta/binaries/metactl/main.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/meta/binaries/metactl/main.rs b/src/meta/binaries/metactl/main.rs index c9bf1a516f44..681313844e6a 100644 --- a/src/meta/binaries/metactl/main.rs +++ b/src/meta/binaries/metactl/main.rs @@ -390,9 +390,7 @@ async fn main() -> anyhow::Result<()> { chunk_size: app.globals.export_chunk_size, }; app.export(&args).await?; - } - - if app.globals.import { + } else if app.globals.import { let args = ImportArgs { raft_dir: app.globals.raft_dir.clone(), db: app.globals.db.clone(), @@ -400,9 +398,9 @@ async fn main() -> anyhow::Result<()> { initial_cluster: app.globals.initial_cluster.clone(), }; app.import(&args).await?; + } else { + app.print_help()?; } - - app.print_help()?; } } From 49aaa369de11a409769e257fb27b7f5f5d1b2280 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 18:57:25 +0800 Subject: [PATCH 28/30] z --- src/meta/binaries/metactl/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/meta/binaries/metactl/main.rs b/src/meta/binaries/metactl/main.rs index 681313844e6a..84eb44c70e76 100644 --- a/src/meta/binaries/metactl/main.rs +++ b/src/meta/binaries/metactl/main.rs @@ -300,8 +300,7 @@ impl App { let client = MetaAdminClient::new(args.admin_api_address.as_str()); let result = client.transfer_leader(args.to).await?; println!( - "triggered leader transfer from {} to {}.\n - voter list: {:?}", + "triggered leader transfer from {} to {}.\nvoter list: {:?}", result.from, result.to, result.voter_ids ); Ok(()) From 66d633c9e4da71d993a8f54399a9c09c6cadf9b2 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 18:58:03 +0800 Subject: [PATCH 29/30] z --- src/meta/binaries/metactl/main.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/meta/binaries/metactl/main.rs b/src/meta/binaries/metactl/main.rs index 84eb44c70e76..4d7b49f42b2e 100644 --- a/src/meta/binaries/metactl/main.rs +++ b/src/meta/binaries/metactl/main.rs @@ -300,9 +300,10 @@ impl App { let client = MetaAdminClient::new(args.admin_api_address.as_str()); let result = client.transfer_leader(args.to).await?; println!( - "triggered leader transfer from {} to {}.\nvoter list: {:?}", - result.from, result.to, result.voter_ids + "triggered leader transfer from {} to {}.", + result.from, result.to ); + println!("voter ids: {:?}", result.voter_ids); Ok(()) } From 23c2432de33abf4c7be17407bd9736d93656143d Mon Sep 17 00:00:00 2001 From: everpcpc Date: Thu, 15 Aug 2024 19:05:09 +0800 Subject: [PATCH 30/30] z --- src/meta/binaries/metactl/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/meta/binaries/metactl/main.rs b/src/meta/binaries/metactl/main.rs index 4d7b49f42b2e..8900ce45ecda 100644 --- a/src/meta/binaries/metactl/main.rs +++ b/src/meta/binaries/metactl/main.rs @@ -57,7 +57,7 @@ pub struct GlobalArgs { #[clap(long)] pub import: bool, - /// DEPRECATED + /// DEPRECATE: use subcommand instead. #[clap(long)] pub export: bool,