From 1de9376fd0f7b031bd00252b73ebf76148df1340 Mon Sep 17 00:00:00 2001 From: karencfv Date: Tue, 27 Aug 2024 15:33:08 +1200 Subject: [PATCH] tidy up --- clickhouse-admin/types/src/config.rs | 25 ++++++++++---------- clickhouse-admin/types/src/lib.rs | 34 ++++++++++++++++++---------- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/clickhouse-admin/types/src/config.rs b/clickhouse-admin/types/src/config.rs index a9f0487c11..06afbcf95e 100644 --- a/clickhouse-admin/types/src/config.rs +++ b/clickhouse-admin/types/src/config.rs @@ -29,7 +29,7 @@ fn path_schema(gen: &mut SchemaGenerator) -> Schema { schema.into() } -/// Config for an individual Clickhouse Replica +/// Configuration for a ClickHouse replica server #[derive(Debug, Clone, PartialEq, Eq, JsonSchema, Serialize, Deserialize)] pub struct ReplicaConfig { pub logger: LogConfig, @@ -45,6 +45,7 @@ pub struct ReplicaConfig { } impl ReplicaConfig { + /// A new ClickHouse replica server configuration with default ports and directories pub fn new( logger: LogConfig, macros: Macros, @@ -166,6 +167,7 @@ pub struct Macros { } impl Macros { + /// A new macros configuration block with default cluster pub fn new(replica: ServerId) -> Self { Self { shard: 1, replica, cluster: OXIMETER_CLUSTER.to_string() } } @@ -191,6 +193,7 @@ pub struct RemoteServers { } impl RemoteServers { + /// A new remote_servers configuration block with default cluster pub fn new(replicas: Vec) -> Self { Self { cluster: OXIMETER_CLUSTER.to_string(), @@ -270,9 +273,10 @@ pub struct KeeperNodeConfig { } impl KeeperNodeConfig { + /// A new ClickHouse keeper node configuration with default port pub fn new(host: String) -> Self { let port = CLICKHOUSE_KEEPER_TCP_PORT; - KeeperNodeConfig { host, port } + Self { host, port } } } @@ -283,9 +287,10 @@ pub struct ServerNodeConfig { } impl ServerNodeConfig { + /// A new ClickHouse replica node configuration with default port pub fn new(host: String) -> Self { let port = CLICKHOUSE_TCP_PORT; - ServerNodeConfig { host, port } + Self { host, port } } } @@ -306,6 +311,7 @@ pub struct LogConfig { } impl LogConfig { + /// A new logger configuration with default directories pub fn new(path: Utf8PathBuf, node_type: NodeType) -> Self { let prefix = match node_type { NodeType::Server => "clickhouse", @@ -316,13 +322,7 @@ impl LogConfig { let log = logs.join(format!("{prefix}.log")); let errorlog = logs.join(format!("{prefix}.err.log")); - LogConfig { - level: LogLevel::default(), - log, - errorlog, - size: 100, - count: 1, - } + Self { level: LogLevel::default(), log, errorlog, size: 100, count: 1 } } pub fn to_xml(&self) -> String { @@ -395,11 +395,11 @@ pub struct RaftServerConfig { impl RaftServerConfig { pub fn new(id: KeeperId, hostname: String) -> Self { - RaftServerConfig { id, hostname, port: CLICKHOUSE_KEEPER_RAFT_PORT } + Self { id, hostname, port: CLICKHOUSE_KEEPER_RAFT_PORT } } } -/// Config for an individual Clickhouse Keeper +/// Configuration for a ClickHouse keeper #[derive(Debug, Clone, PartialEq, Eq, JsonSchema, Serialize, Deserialize)] pub struct KeeperConfig { pub logger: LogConfig, @@ -415,6 +415,7 @@ pub struct KeeperConfig { } impl KeeperConfig { + /// A new ClickHouse keeper node configuration with default ports and directories pub fn new( logger: LogConfig, listen_host: Ipv6Addr, diff --git a/clickhouse-admin/types/src/lib.rs b/clickhouse-admin/types/src/lib.rs index faf8a09de7..62ebf8679e 100644 --- a/clickhouse-admin/types/src/lib.rs +++ b/clickhouse-admin/types/src/lib.rs @@ -16,7 +16,7 @@ use config::*; pub const OXIMETER_CLUSTER: &str = "oximeter_cluster"; -/// A unique ID for a clickhouse keeper +/// A unique ID for a ClickHouse Keeper #[derive( Debug, Clone, @@ -35,7 +35,7 @@ pub const OXIMETER_CLUSTER: &str = "oximeter_cluster"; )] pub struct KeeperId(pub u64); -/// A unique ID for a clickhouse server +/// A unique ID for a Clickhouse Server #[derive( Debug, Clone, @@ -65,7 +65,6 @@ pub struct ClickhouseServerConfig { } impl ClickhouseServerConfig { - #[allow(clippy::too_many_arguments)] pub fn new( config_dir: Utf8PathBuf, id: ServerId, @@ -77,6 +76,7 @@ impl ClickhouseServerConfig { Self { config_dir, id, datastore_path, listen_addr, keepers, servers } } + /// Generate a configuration file for a replica server node pub fn generate_xml_file(&self) -> Result<()> { let logger = LogConfig::new(self.datastore_path.clone(), NodeType::Server); @@ -101,30 +101,39 @@ impl ClickhouseServerConfig { #[derive(Debug, Clone)] pub struct ClickhouseKeeperConfig { pub config_dir: Utf8PathBuf, + pub id: KeeperId, pub raft_servers: Vec, - pub path: Utf8PathBuf, + pub datastore_path: Utf8PathBuf, pub listen_addr: Ipv6Addr, } impl ClickhouseKeeperConfig { pub fn new( config_dir: Utf8PathBuf, + id: KeeperId, raft_servers: Vec, - path: Utf8PathBuf, + datastore_path: Utf8PathBuf, listen_addr: Ipv6Addr, ) -> Self { - ClickhouseKeeperConfig { config_dir, raft_servers, path, listen_addr } + ClickhouseKeeperConfig { + config_dir, + id, + raft_servers, + datastore_path, + listen_addr, + } } - /// Generate a configuration file for `this_keeper` consisting of the keepers in `raft_servers` - pub fn generate_xml_file(&self, this_keeper: KeeperId) -> Result<()> { - let logger = LogConfig::new(self.path.clone(), NodeType::Keeper); + /// Generate a configuration file for a keeper node + pub fn generate_xml_file(&self) -> Result<()> { + let logger = + LogConfig::new(self.datastore_path.clone(), NodeType::Keeper); let raft_config = RaftServers::new(self.raft_servers.clone()); let config = KeeperConfig::new( logger, self.listen_addr, - this_keeper, - self.path.clone(), + self.id, + self.datastore_path.clone(), raft_config, ); @@ -164,12 +173,13 @@ mod tests { let config = ClickhouseKeeperConfig::new( Utf8PathBuf::from(config_dir.path()), + KeeperId(1), keepers, Utf8PathBuf::from_str("./").unwrap(), Ipv6Addr::from_str("ff::08").unwrap(), ); - config.generate_xml_file(KeeperId(1)).unwrap(); + config.generate_xml_file().unwrap(); let expected_file = Utf8PathBuf::from_str("./testutils") .unwrap()