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 snapshot read.
27pub const SNAPSHOT_READ: &str = "snapshot_read";
28/// Option key for compaction type.
29pub const COMPACTION_TYPE: &str = "compaction.type";
30/// TWCS compaction strategy.
31pub const COMPACTION_TYPE_TWCS: &str = "twcs";
32/// Option key for twcs min file num to trigger a compaction.
33pub const TWCS_TRIGGER_FILE_NUM: &str = "compaction.twcs.trigger_file_num";
34/// Option key for twcs max output file size.
35pub const TWCS_MAX_OUTPUT_FILE_SIZE: &str = "compaction.twcs.max_output_file_size";
36/// Option key for twcs time window.
37pub const TWCS_TIME_WINDOW: &str = "compaction.twcs.time_window";
38/// Option key for twcs remote compaction.
39pub const TWCS_REMOTE_COMPACTION: &str = "compaction.twcs.remote_compaction";
40/// Option key for twcs fallback to local.
41pub const TWCS_FALLBACK_TO_LOCAL: &str = "compaction.twcs.fallback_to_local";
42/// Option key for memtable type.
43pub const MEMTABLE_TYPE: &str = "memtable.type";
44/// Option key for memtable partition tree index max keys per shard.
45pub const MEMTABLE_PARTITION_TREE_INDEX_MAX_KEYS_PER_SHARD: &str =
46    "memtable.partition_tree.index_max_keys_per_shard";
47/// Option key for memtable partition tree data freeze threshold.
48pub const MEMTABLE_PARTITION_TREE_DATA_FREEZE_THRESHOLD: &str =
49    "memtable.partition_tree.data_freeze_threshold";
50/// Option key for memtable partition tree fork dictionary bytes.
51pub const MEMTABLE_PARTITION_TREE_FORK_DICTIONARY_BYTES: &str =
52    "memtable.partition_tree.fork_dictionary_bytes";
53/// Option key for skipping WAL.
54pub const SKIP_WAL_KEY: &str = "skip_wal";
55/// Option key for sst format.
56pub const SST_FORMAT_KEY: &str = "sst_format";
57// Note: Adding new options here should also check if this option should be removed in [metric_engine::engine::create::region_options_for_metadata_region].
58
59/// Returns true if the `key` is a valid option key for the mito engine.
60pub fn is_mito_engine_option_key(key: &str) -> bool {
61    [
62        "ttl",
63        COMPACTION_TYPE,
64        TWCS_TRIGGER_FILE_NUM,
65        TWCS_MAX_OUTPUT_FILE_SIZE,
66        TWCS_TIME_WINDOW,
67        TWCS_REMOTE_COMPACTION,
68        TWCS_FALLBACK_TO_LOCAL,
69        "storage",
70        "index.inverted_index.ignore_column_ids",
71        "index.inverted_index.segment_row_count",
72        WAL_OPTIONS_KEY,
73        MEMTABLE_TYPE,
74        MEMTABLE_PARTITION_TREE_INDEX_MAX_KEYS_PER_SHARD,
75        MEMTABLE_PARTITION_TREE_DATA_FREEZE_THRESHOLD,
76        MEMTABLE_PARTITION_TREE_FORK_DICTIONARY_BYTES,
77        // We don't allow to create a mito table with sparse primary key encoding directly.
78        APPEND_MODE_KEY,
79        MERGE_MODE_KEY,
80        SST_FORMAT_KEY,
81    ]
82    .contains(&key)
83}
84
85#[cfg(test)]
86mod tests {
87    use super::*;
88
89    #[test]
90    fn test_is_mito_engine_option_key() {
91        assert!(is_mito_engine_option_key("ttl"));
92        assert!(is_mito_engine_option_key("compaction.type"));
93        assert!(is_mito_engine_option_key(
94            "compaction.twcs.trigger_file_num"
95        ));
96        assert!(is_mito_engine_option_key("compaction.twcs.time_window"));
97        assert!(is_mito_engine_option_key("storage"));
98        assert!(is_mito_engine_option_key(
99            "index.inverted_index.ignore_column_ids"
100        ));
101        assert!(is_mito_engine_option_key(
102            "index.inverted_index.segment_row_count"
103        ));
104        assert!(is_mito_engine_option_key("wal_options"));
105        assert!(is_mito_engine_option_key("memtable.type"));
106        assert!(is_mito_engine_option_key(
107            "memtable.partition_tree.index_max_keys_per_shard"
108        ));
109        assert!(is_mito_engine_option_key(
110            "memtable.partition_tree.data_freeze_threshold"
111        ));
112        assert!(is_mito_engine_option_key(
113            "memtable.partition_tree.fork_dictionary_bytes"
114        ));
115        assert!(is_mito_engine_option_key("append_mode"));
116        assert!(!is_mito_engine_option_key("foo"));
117    }
118}