diff --git a/config/metasrv.example.toml b/config/metasrv.example.toml index 5d188ac69687..7ff5e4db55b7 100644 --- a/config/metasrv.example.toml +++ b/config/metasrv.example.toml @@ -44,4 +44,25 @@ first_heartbeat_estimate = "1000ms" # tcp_nodelay = true [wal] +# Available wal providers: +# - "raft-engine" (default) +# - "kafka" provider = "raft-engine" + +# There're none raft-engine wal config since meta srv only involves in remote wal currently. + +# Kafka wal config. +# The broker endpoints of the Kafka cluster. ["127.0.0.1:9090"] by default. +broker_endpoints = ["127.0.0.1:9090"] +# Number of topics to be created upon start. +num_topics = 64 +# Topic selector type. +# Available selector types: +# - "round-robin" (default) +selector_type = "round-robin" +# A Kafka topic is constructed by concatenating `topic_name_prefix` and `topic_id`. +topic_name_prefix = "greptimedb_kafka_wal" +# Number of partitions per topic. +num_partitions = 1 +# Expected number of replicas of each partition. +replication_factor = 3 diff --git a/src/common/meta/src/wal/kafka.rs b/src/common/meta/src/wal/kafka.rs index c835512051f2..5c07e98a1e2a 100644 --- a/src/common/meta/src/wal/kafka.rs +++ b/src/common/meta/src/wal/kafka.rs @@ -19,13 +19,40 @@ mod topic_selector; use serde::{Deserialize, Serialize}; use crate::wal::kafka::topic::Topic; +use crate::wal::kafka::topic_selector::SelectorType as TopicSelectorType; /// Configurations for bootstraping a kafka wal. -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Default)] -pub struct KafkaConfig; +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct KafkaConfig { + /// The broker endpoints of the Kafka cluster. + pub broker_endpoints: Vec, + /// Number of topics to be created upon start. + pub num_topics: usize, + /// The type of the topic selector with which to select a topic for a region. + pub selector_type: TopicSelectorType, + /// Topic name prefix. + pub topic_name_prefix: String, + /// Number of partitions per topic. + pub num_partitions: i32, + /// The replication factor of each topic. + pub replication_factor: i16, +} + +impl Default for KafkaConfig { + fn default() -> Self { + Self { + broker_endpoints: vec!["127.0.0.1:9090".to_string()], + num_topics: 64, + selector_type: TopicSelectorType::RoundRobin, + topic_name_prefix: "greptimedb_wal".to_string(), + num_partitions: 1, + replication_factor: 3, + } + } +} /// Kafka wal options allocated to a region. -#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq)] +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] pub struct KafkaWalOptions { /// Kafka wal topic. /// Publishers publish log entries to the topic while subscribers pull log entries from the topic. diff --git a/src/common/meta/src/wal/kafka/topic_selector.rs b/src/common/meta/src/wal/kafka/topic_selector.rs index 3b794a6aba8f..69501070b62b 100644 --- a/src/common/meta/src/wal/kafka/topic_selector.rs +++ b/src/common/meta/src/wal/kafka/topic_selector.rs @@ -12,12 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::default; use std::sync::Arc; +use serde::{Deserialize, Serialize}; + use crate::wal::kafka::topic::Topic; /// The type of the topic selector, i.e. with which strategy to select a topic. -pub(super) enum SelectorType { +#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)] +pub enum SelectorType { + #[default] RoundRobin, }