Skip to content

Commit 16de6da

Browse files
authored
chore: Split metactl into lib meta/control and bin metactl (#17496)
* chore: Split metactl into lib meta/control and bin metactl Signed-off-by: Xuanwo <[email protected]> * Format toml Signed-off-by: Xuanwo <[email protected]> * Fix copyright Signed-off-by: Xuanwo <[email protected]> * Fix typo Signed-off-by: Xuanwo <[email protected]> --------- Signed-off-by: Xuanwo <[email protected]>
1 parent 0b1d01a commit 16de6da

15 files changed

+318
-202
lines changed

Cargo.lock

+24-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ members = [
9393
"src/meta/app",
9494
"src/meta/binaries",
9595
"src/meta/client",
96+
"src/meta/control",
9697
"src/meta/embedded",
9798
"src/meta/kvapi",
9899
"src/meta/process",
@@ -138,6 +139,7 @@ databend-common-management = { path = "src/query/management" }
138139
databend-common-meta-api = { path = "src/meta/api" }
139140
databend-common-meta-app = { path = "src/meta/app" }
140141
databend-common-meta-client = { path = "src/meta/client" }
142+
databend-common-meta-control = { path = "src/meta/control" }
141143
databend-common-meta-embedded = { path = "src/meta/embedded" }
142144
databend-common-meta-kvapi = { path = "src/meta/kvapi" }
143145
databend-common-meta-process = { path = "src/meta/process" }

src/meta/binaries/Cargo.toml

+6-9
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,31 @@ io-uring = [
2222
]
2323

2424
[dependencies]
25-
anyerror = { workspace = true }
26-
anyhow = { workspace = true }
27-
chrono = { workspace = true }
28-
clap = { workspace = true }
2925
databend-common-base = { workspace = true }
3026
databend-common-exception = { workspace = true }
3127
databend-common-grpc = { workspace = true }
3228
databend-common-meta-api = { workspace = true }
3329
databend-common-meta-app = { workspace = true }
3430
databend-common-meta-client = { workspace = true }
31+
databend-common-meta-control = { workspace = true }
3532
databend-common-meta-kvapi = { workspace = true }
3633
databend-common-meta-raft-store = { workspace = true }
3734
databend-common-meta-sled-store = { workspace = true }
3835
databend-common-meta-store = { workspace = true }
3936
databend-common-meta-types = { workspace = true }
4037
databend-common-tracing = { workspace = true }
4138
databend-meta = { workspace = true }
39+
40+
anyerror = { workspace = true }
41+
anyhow = { workspace = true }
42+
chrono = { workspace = true }
43+
clap = { workspace = true }
4244
fastrace = { workspace = true }
43-
futures = { workspace = true }
4445
log = { workspace = true }
45-
raft-log = { workspace = true }
4646
rand = { workspace = true }
47-
reqwest = { workspace = true }
4847
serde = { workspace = true }
4948
serde_json = { workspace = true }
5049
tokio = { workspace = true }
51-
tokio-stream = { workspace = true }
52-
url = { workspace = true }
5350

5451
[[bin]]
5552
name = "databend-meta"

src/meta/binaries/metactl/main.rs

+10-185
Original file line numberDiff line numberDiff line change
@@ -14,205 +14,30 @@
1414

1515
#![allow(clippy::uninlined_format_args)]
1616

17-
mod export_from_grpc;
18-
19-
pub mod admin;
20-
pub mod export_from_disk;
21-
pub mod import;
22-
pub mod import_v004;
23-
pub(crate) mod reading;
24-
pub mod upgrade;
25-
2617
use std::collections::BTreeMap;
2718

28-
use admin::MetaAdminClient;
29-
use clap::Args;
3019
use clap::CommandFactory;
3120
use clap::Parser;
3221
use clap::Subcommand;
3322
use databend_common_base::base::tokio;
3423
use databend_common_meta_client::MetaGrpcClient;
24+
use databend_common_meta_control::admin::MetaAdminClient;
25+
use databend_common_meta_control::args::BenchArgs;
26+
use databend_common_meta_control::args::ExportArgs;
27+
use databend_common_meta_control::args::GlobalArgs;
28+
use databend_common_meta_control::args::ImportArgs;
29+
use databend_common_meta_control::args::StatusArgs;
30+
use databend_common_meta_control::args::TransferLeaderArgs;
31+
use databend_common_meta_control::export_from_disk;
32+
use databend_common_meta_control::export_from_grpc;
33+
use databend_common_meta_control::import;
3534
use databend_common_meta_kvapi::kvapi::KVApi;
36-
use databend_common_meta_raft_store::config::RaftConfig;
3735
use databend_common_tracing::init_logging;
3836
use databend_common_tracing::Config as LogConfig;
3937
use databend_common_tracing::FileConfig;
40-
use databend_common_tracing::CONFIG_DEFAULT_LOG_LEVEL;
4138
use databend_meta::version::METASRV_COMMIT_VERSION;
4239
use serde::Deserialize;
4340

44-
#[derive(Debug, Clone, Deserialize, Args)]
45-
pub struct GlobalArgs {
46-
#[clap(long, default_value = CONFIG_DEFAULT_LOG_LEVEL)]
47-
pub log_level: String,
48-
49-
/// DEPRECATE: use subcommand instead.
50-
#[clap(
51-
long,
52-
env = "METASRV_GRPC_API_ADDRESS",
53-
default_value = "127.0.0.1:9191"
54-
)]
55-
pub grpc_api_address: String,
56-
57-
/// DEPRECATE: use subcommand instead.
58-
#[clap(long)]
59-
pub import: bool,
60-
61-
/// DEPRECATE: use subcommand instead.
62-
#[clap(long)]
63-
pub export: bool,
64-
65-
/// DEPRECATE: use subcommand instead.
66-
///
67-
/// The dir to store persisted meta state, including raft logs, state machine etc.
68-
#[clap(long)]
69-
#[serde(alias = "kvsrv_raft_dir")]
70-
pub raft_dir: Option<String>,
71-
72-
/// DEPRECATE: use subcommand instead.
73-
///
74-
/// The N.O. json strings in a export stream item.
75-
///
76-
/// Set this to a smaller value if you get gRPC message body too large error.
77-
/// This requires meta-service >= 1.2.315; For older version, this argument is ignored.
78-
///
79-
/// By default it is 32.
80-
#[clap(long)]
81-
pub export_chunk_size: Option<u64>,
82-
83-
/// DEPRECATE: use subcommand instead.
84-
///
85-
/// When export raft data, this is the name of the save db file.
86-
/// If `db` is empty, output the exported data as json to stdout instead.
87-
/// When import raft data, this is the name of the restored db file.
88-
/// If `db` is empty, the restored data is from stdin instead.
89-
#[clap(long, default_value = "")]
90-
pub db: String,
91-
92-
/// DEPRECATE: use subcommand instead.
93-
///
94-
/// initial_cluster format: node_id=endpoint,grpc_api_addr
95-
#[clap(long)]
96-
pub initial_cluster: Vec<String>,
97-
98-
/// DEPRECATE: use subcommand instead.
99-
///
100-
/// The node id. Used in these cases:
101-
///
102-
/// 1. when this server is not initialized, e.g. --boot or --single for the first time.
103-
/// 2. --initial_cluster with new cluster node id.
104-
///
105-
/// Otherwise this argument is ignored.
106-
#[clap(long, default_value = "0")]
107-
#[serde(alias = "kvsrv_id")]
108-
pub id: u64,
109-
}
110-
111-
#[derive(Debug, Clone, Deserialize, Args)]
112-
pub struct StatusArgs {
113-
#[clap(long, default_value = "127.0.0.1:9191")]
114-
pub grpc_api_address: String,
115-
}
116-
117-
#[derive(Debug, Clone, Deserialize, Args)]
118-
pub struct ExportArgs {
119-
#[clap(long, default_value = "127.0.0.1:9191")]
120-
pub grpc_api_address: String,
121-
122-
/// The dir to store persisted meta state, including raft logs, state machine etc.
123-
#[clap(long)]
124-
#[serde(alias = "kvsrv_raft_dir")]
125-
pub raft_dir: Option<String>,
126-
127-
/// The N.O. json strings in a export stream item.
128-
///
129-
/// Set this to a smaller value if you get gRPC message body too large error.
130-
/// This requires meta-service >= 1.2.315; For older version, this argument is ignored.
131-
///
132-
/// By default it is 32.
133-
#[clap(long)]
134-
pub chunk_size: Option<u64>,
135-
136-
/// The name of the save db file.
137-
/// If `db` is empty, output the exported data as json to stdout instead.
138-
#[clap(long, default_value = "")]
139-
pub db: String,
140-
141-
/// The node id. Used in these cases:
142-
///
143-
/// 1. when this server is not initialized, e.g. --boot or --single for the first time.
144-
/// 2. --initial_cluster with new cluster node id.
145-
///
146-
/// Otherwise this argument is ignored.
147-
#[clap(long, default_value = "0")]
148-
#[serde(alias = "kvsrv_id")]
149-
pub id: u64,
150-
}
151-
152-
impl From<ExportArgs> for RaftConfig {
153-
#[allow(clippy::field_reassign_with_default)]
154-
fn from(value: ExportArgs) -> Self {
155-
let mut c = Self::default();
156-
157-
c.raft_dir = value.raft_dir.unwrap_or_default();
158-
c.id = value.id;
159-
c
160-
}
161-
}
162-
163-
#[derive(Debug, Clone, Deserialize, Args)]
164-
pub struct ImportArgs {
165-
/// The dir to store persisted meta state, including raft logs, state machine etc.
166-
#[clap(long)]
167-
#[serde(alias = "kvsrv_raft_dir")]
168-
pub raft_dir: Option<String>,
169-
170-
/// The name of the restored db file.
171-
/// If `db` is empty, the restored data is from stdin instead.
172-
#[clap(long, default_value = "")]
173-
pub db: String,
174-
175-
/// initial_cluster format: node_id=endpoint,grpc_api_addr
176-
#[clap(long)]
177-
pub initial_cluster: Vec<String>,
178-
179-
/// The node id. Used in these cases:
180-
///
181-
/// 1. when this server is not initialized, e.g. --boot or --single for the first time.
182-
/// 2. --initial_cluster with new cluster node id.
183-
///
184-
/// Otherwise this argument is ignored.
185-
#[clap(long, default_value = "0")]
186-
#[serde(alias = "kvsrv_id")]
187-
pub id: u64,
188-
}
189-
190-
impl From<ImportArgs> for RaftConfig {
191-
#[allow(clippy::field_reassign_with_default)]
192-
fn from(value: ImportArgs) -> Self {
193-
let mut c = Self::default();
194-
195-
c.raft_dir = value.raft_dir.unwrap_or_default();
196-
c.id = value.id;
197-
c
198-
}
199-
}
200-
201-
#[derive(Debug, Clone, Deserialize, Args)]
202-
pub struct TransferLeaderArgs {
203-
#[clap(long)]
204-
pub to: Option<u64>,
205-
206-
#[clap(long, default_value = "127.0.0.1:28002")]
207-
pub admin_api_address: String,
208-
}
209-
210-
#[derive(Debug, Clone, Deserialize, Args)]
211-
pub struct BenchArgs {
212-
#[clap(long, default_value = "127.0.0.1:9191")]
213-
pub grpc_api_address: String,
214-
}
215-
21641
#[derive(Debug, Deserialize, Parser)]
21742
#[clap(name = "databend-metactl", about, version = &**METASRV_COMMIT_VERSION, author)]
21843
struct App {

src/meta/control/Cargo.toml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[package]
2+
name = "databend-common-meta-control"
3+
description = "common meta control"
4+
version = { workspace = true }
5+
authors = { workspace = true }
6+
license = { workspace = true }
7+
publish = { workspace = true }
8+
edition = { workspace = true }
9+
10+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
11+
12+
[lib]
13+
doctest = false
14+
test = true
15+
16+
[dependencies]
17+
databend-common-meta-client = { workspace = true }
18+
databend-common-meta-raft-store = { workspace = true }
19+
databend-common-meta-sled-store = { workspace = true }
20+
databend-common-meta-types = { workspace = true }
21+
databend-common-tracing = { workspace = true }
22+
databend-meta = { workspace = true }
23+
24+
anyhow = { workspace = true }
25+
clap = { workspace = true }
26+
futures = { workspace = true }
27+
raft-log = { workspace = true }
28+
reqwest = { workspace = true }
29+
serde = { workspace = true }
30+
serde_json = { workspace = true }
31+
tokio = { workspace = true }
32+
tokio-stream = { workspace = true }
33+
url = { workspace = true }
34+
35+
[dev-dependencies]
36+
anyhow = { workspace = true }
37+
38+
[build-dependencies]
39+
databend-common-building = { workspace = true }
40+
41+
[lints]
42+
workspace = true

src/meta/control/build.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2021 Datafuse Labs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
fn main() {
16+
databend_common_building::setup();
17+
}
File renamed without changes.

0 commit comments

Comments
 (0)