Skip to main content

store_api/
mito_engine_options.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
15//! Option keys for the mito engine.
16//! We define them in this mod so the create parser can use it to validate table options.
17
18/// Option key for all WAL options.
19pub use common_wal::options::WAL_OPTIONS_KEY;
20/// Option key for append mode.
21pub const APPEND_MODE_KEY: &str = "append_mode";
22/// Option key for merge mode.
23pub const MERGE_MODE_KEY: &str = "merge_mode";
24/// Option key for TTL(time-to-live)
25pub const TTL_KEY: &str = "ttl";
26/// Option key for the per-table auto flush interval.
27pub const AUTO_FLUSH_INTERVAL_KEY: &str = "auto_flush_interval";
28/// Option key for snapshot read.
29pub const SNAPSHOT_READ: &str = "snapshot_read";
30/// Option key for compaction type.
31pub const COMPACTION_TYPE: &str = "compaction.type";
32/// Option key for forcing compaction options override.
33pub const COMPACTION_OVERRIDE: &str = "compaction.override";
34/// TWCS compaction strategy.
35pub const COMPACTION_TYPE_TWCS: &str = "twcs";
36/// Option key for twcs min file num to trigger a compaction.
37pub const TWCS_TRIGGER_FILE_NUM: &str = "compaction.twcs.trigger_file_num";
38/// Option key for twcs max output file size.
39pub const TWCS_MAX_OUTPUT_FILE_SIZE: &str = "compaction.twcs.max_output_file_size";
40/// Option key for twcs time window.
41pub const TWCS_TIME_WINDOW: &str = "compaction.twcs.time_window";
42/// Option key for twcs remote compaction.
43pub const TWCS_REMOTE_COMPACTION: &str = "compaction.twcs.remote_compaction";
44/// Option key for twcs fallback to local.
45pub const TWCS_FALLBACK_TO_LOCAL: &str = "compaction.twcs.fallback_to_local";
46/// Option key for memtable type.
47pub const MEMTABLE_TYPE: &str = "memtable.type";
48/// Option key for bulk memtable merge threshold.
49pub const MEMTABLE_BULK_MERGE_THRESHOLD: &str = "memtable.bulk.merge_threshold";
50/// Option key for bulk memtable encode row threshold.
51pub const MEMTABLE_BULK_ENCODE_ROW_THRESHOLD: &str = "memtable.bulk.encode_row_threshold";
52/// Option key for bulk memtable encode bytes threshold.
53pub const MEMTABLE_BULK_ENCODE_BYTES_THRESHOLD: &str = "memtable.bulk.encode_bytes_threshold";
54/// Option key for bulk memtable max merge groups.
55pub const MEMTABLE_BULK_MAX_MERGE_GROUPS: &str = "memtable.bulk.max_merge_groups";
56/// Option key for memtable partition tree index max keys per shard.
57pub const MEMTABLE_PARTITION_TREE_INDEX_MAX_KEYS_PER_SHARD: &str =
58    "memtable.partition_tree.index_max_keys_per_shard";
59/// Option key for memtable partition tree data freeze threshold.
60pub const MEMTABLE_PARTITION_TREE_DATA_FREEZE_THRESHOLD: &str =
61    "memtable.partition_tree.data_freeze_threshold";
62/// Option key for memtable partition tree fork dictionary bytes.
63pub const MEMTABLE_PARTITION_TREE_FORK_DICTIONARY_BYTES: &str =
64    "memtable.partition_tree.fork_dictionary_bytes";
65/// Option key for skipping WAL.
66pub const SKIP_WAL_KEY: &str = "skip_wal";
67/// Option key for sst format.
68pub const SST_FORMAT_KEY: &str = "sst_format";
69// Note: Adding new options here should also check if this option should be removed in [metric_engine::engine::create::region_options_for_metadata_region].
70
71/// Returns true if the `key` is a valid option key for the mito engine.
72pub fn is_mito_engine_option_key(key: &str) -> bool {
73    [
74        "ttl",
75        AUTO_FLUSH_INTERVAL_KEY,
76        COMPACTION_TYPE,
77        COMPACTION_OVERRIDE,
78        TWCS_TRIGGER_FILE_NUM,
79        TWCS_MAX_OUTPUT_FILE_SIZE,
80        TWCS_TIME_WINDOW,
81        TWCS_REMOTE_COMPACTION,
82        TWCS_FALLBACK_TO_LOCAL,
83        "storage",
84        "index.inverted_index.ignore_column_ids",
85        "index.inverted_index.segment_row_count",
86        WAL_OPTIONS_KEY,
87        MEMTABLE_TYPE,
88        MEMTABLE_BULK_MERGE_THRESHOLD,
89        MEMTABLE_BULK_ENCODE_ROW_THRESHOLD,
90        MEMTABLE_BULK_ENCODE_BYTES_THRESHOLD,
91        MEMTABLE_BULK_MAX_MERGE_GROUPS,
92        MEMTABLE_PARTITION_TREE_INDEX_MAX_KEYS_PER_SHARD,
93        MEMTABLE_PARTITION_TREE_DATA_FREEZE_THRESHOLD,
94        MEMTABLE_PARTITION_TREE_FORK_DICTIONARY_BYTES,
95        // We don't allow to create a mito table with sparse primary key encoding directly.
96        APPEND_MODE_KEY,
97        MERGE_MODE_KEY,
98        SST_FORMAT_KEY,
99    ]
100    .contains(&key)
101}
102
103#[cfg(test)]
104mod tests {
105    use super::*;
106
107    #[test]
108    fn test_is_mito_engine_option_key() {
109        assert!(is_mito_engine_option_key("ttl"));
110        assert!(is_mito_engine_option_key("auto_flush_interval"));
111        assert!(is_mito_engine_option_key("compaction.type"));
112        assert!(is_mito_engine_option_key("compaction.override"));
113        assert!(is_mito_engine_option_key(
114            "compaction.twcs.trigger_file_num"
115        ));
116        assert!(is_mito_engine_option_key("compaction.twcs.time_window"));
117        assert!(is_mito_engine_option_key("storage"));
118        assert!(is_mito_engine_option_key(
119            "index.inverted_index.ignore_column_ids"
120        ));
121        assert!(is_mito_engine_option_key(
122            "index.inverted_index.segment_row_count"
123        ));
124        assert!(is_mito_engine_option_key("wal_options"));
125        assert!(is_mito_engine_option_key("memtable.type"));
126        assert!(is_mito_engine_option_key("memtable.bulk.merge_threshold"));
127        assert!(is_mito_engine_option_key(
128            "memtable.bulk.encode_row_threshold"
129        ));
130        assert!(is_mito_engine_option_key(
131            "memtable.bulk.encode_bytes_threshold"
132        ));
133        assert!(is_mito_engine_option_key("memtable.bulk.max_merge_groups"));
134        assert!(is_mito_engine_option_key(
135            "memtable.partition_tree.index_max_keys_per_shard"
136        ));
137        assert!(is_mito_engine_option_key(
138            "memtable.partition_tree.data_freeze_threshold"
139        ));
140        assert!(is_mito_engine_option_key(
141            "memtable.partition_tree.fork_dictionary_bytes"
142        ));
143        assert!(is_mito_engine_option_key("append_mode"));
144        assert!(!is_mito_engine_option_key("foo"));
145    }
146}