Skip to main content

common_wal/config/kafka/
metasrv.rs

1// Copyright 2023 Greptime Team
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
15use std::time::Duration;
16
17use common_base::readable_size::ReadableSize;
18use serde::{Deserialize, Serialize};
19
20use crate::config::kafka::common::{
21    DEFAULT_AUTO_PRUNE_INTERVAL, DEFAULT_AUTO_PRUNE_LOGICAL_DELETE, DEFAULT_AUTO_PRUNE_PARALLELISM,
22    DEFAULT_CHECKPOINT_TRIGGER_SIZE, DEFAULT_FLUSH_TRIGGER_SIZE,
23    DEFAULT_PERIODIC_CHECKPOINT_PERSIST_INTERVAL, DEFAULT_REGION_FLUSH_TRIGGER_INTERVAL,
24    KafkaConnectionConfig, KafkaTopicConfig,
25};
26
27/// Kafka wal configurations for metasrv.
28#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
29#[serde(default)]
30pub struct MetasrvKafkaConfig {
31    /// The kafka connection config.
32    #[serde(flatten)]
33    pub connection: KafkaConnectionConfig,
34    /// The kafka config.
35    #[serde(flatten)]
36    pub kafka_topic: KafkaTopicConfig,
37    // Automatically create topics for WAL.
38    pub auto_create_topics: bool,
39    // Interval of WAL pruning.
40    #[serde(with = "humantime_serde")]
41    pub auto_prune_interval: Duration,
42    // Whether auto WAL pruning only updates metadata and skips Kafka DeleteRecords.
43    pub auto_prune_logical_delete: bool,
44    // Limit of concurrent active pruning procedures.
45    pub auto_prune_parallelism: usize,
46    // The size of WAL to trigger flush.
47    pub flush_trigger_size: ReadableSize,
48    // The checkpoint trigger size.
49    pub checkpoint_trigger_size: ReadableSize,
50    /// Internal interval of remote WAL region flush trigger.
51    #[serde(with = "humantime_serde")]
52    pub region_flush_trigger_interval: Duration,
53    /// Internal interval to periodically persist remote WAL checkpoints.
54    #[serde(with = "humantime_serde")]
55    pub periodic_checkpoint_persist_interval: Duration,
56}
57
58impl Default for MetasrvKafkaConfig {
59    fn default() -> Self {
60        Self {
61            connection: Default::default(),
62            kafka_topic: Default::default(),
63            auto_create_topics: true,
64            auto_prune_interval: DEFAULT_AUTO_PRUNE_INTERVAL,
65            auto_prune_logical_delete: DEFAULT_AUTO_PRUNE_LOGICAL_DELETE,
66            auto_prune_parallelism: DEFAULT_AUTO_PRUNE_PARALLELISM,
67            flush_trigger_size: DEFAULT_FLUSH_TRIGGER_SIZE,
68            checkpoint_trigger_size: DEFAULT_CHECKPOINT_TRIGGER_SIZE,
69            region_flush_trigger_interval: DEFAULT_REGION_FLUSH_TRIGGER_INTERVAL,
70            periodic_checkpoint_persist_interval: DEFAULT_PERIODIC_CHECKPOINT_PERSIST_INTERVAL,
71        }
72    }
73}