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
18use common_wal::options::WAL_OPTIONS_KEY;
19
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 max active window runs.
33pub const TWCS_MAX_ACTIVE_WINDOW_RUNS: &str = "compaction.twcs.max_active_window_runs";
34/// Option key for twcs max active window files.
35pub const TWCS_MAX_ACTIVE_WINDOW_FILES: &str = "compaction.twcs.max_active_window_files";
36/// Option key for twcs max inactive window runs.
37pub const TWCS_MAX_INACTIVE_WINDOW_RUNS: &str = "compaction.twcs.max_inactive_window_runs";
38/// Option key for twcs max inactive window files.
39pub const TWCS_MAX_INACTIVE_WINDOW_FILES: &str = "compaction.twcs.max_inactive_window_files";
40/// Option key for twcs max output file size.
41pub const TWCS_MAX_OUTPUT_FILE_SIZE: &str = "compaction.twcs.max_output_file_size";
42/// Option key for twcs time window.
43pub const TWCS_TIME_WINDOW: &str = "compaction.twcs.time_window";
44/// Option key for twcs remote compaction.
45pub const REMOTE_COMPACTION: &str = "compaction.twcs.remote_compaction";
46/// Option key for twcs fallback to local.
47pub const TWCS_FALLBACK_TO_LOCAL: &str = "compaction.twcs.fallback_to_local";
48/// Option key for memtable type.
49pub const MEMTABLE_TYPE: &str = "memtable.type";
50/// Option key for memtable partition tree primary key encoding.
51pub const MEMTABLE_PARTITION_TREE_PRIMARY_KEY_ENCODING: &str =
52    "memtable.partition_tree.primary_key_encoding";
53/// Option key for memtable partition tree index max keys per shard.
54pub const MEMTABLE_PARTITION_TREE_INDEX_MAX_KEYS_PER_SHARD: &str =
55    "memtable.partition_tree.index_max_keys_per_shard";
56/// Option key for memtable partition tree data freeze threshold.
57pub const MEMTABLE_PARTITION_TREE_DATA_FREEZE_THRESHOLD: &str =
58    "memtable.partition_tree.data_freeze_threshold";
59/// Option key for memtable partition tree fork dictionary bytes.
60pub const MEMTABLE_PARTITION_TREE_FORK_DICTIONARY_BYTES: &str =
61    "memtable.partition_tree.fork_dictionary_bytes";
62/// Option key for skipping WAL.
63pub const SKIP_WAL_KEY: &str = "skip_wal";
64// Note: Adding new options here should also check if this option should be removed in [metric_engine::engine::create::region_options_for_metadata_region].
65
66/// Returns true if the `key` is a valid option key for the mito engine.
67pub fn is_mito_engine_option_key(key: &str) -> bool {
68    [
69        "ttl",
70        COMPACTION_TYPE,
71        TWCS_MAX_ACTIVE_WINDOW_RUNS,
72        TWCS_MAX_ACTIVE_WINDOW_FILES,
73        TWCS_MAX_INACTIVE_WINDOW_RUNS,
74        TWCS_MAX_INACTIVE_WINDOW_FILES,
75        TWCS_MAX_OUTPUT_FILE_SIZE,
76        TWCS_TIME_WINDOW,
77        REMOTE_COMPACTION,
78        TWCS_FALLBACK_TO_LOCAL,
79        "storage",
80        "index.inverted_index.ignore_column_ids",
81        "index.inverted_index.segment_row_count",
82        WAL_OPTIONS_KEY,
83        MEMTABLE_TYPE,
84        MEMTABLE_PARTITION_TREE_INDEX_MAX_KEYS_PER_SHARD,
85        MEMTABLE_PARTITION_TREE_DATA_FREEZE_THRESHOLD,
86        MEMTABLE_PARTITION_TREE_FORK_DICTIONARY_BYTES,
87        MEMTABLE_PARTITION_TREE_PRIMARY_KEY_ENCODING,
88        APPEND_MODE_KEY,
89        MERGE_MODE_KEY,
90    ]
91    .contains(&key)
92}
93
94#[cfg(test)]
95mod tests {
96    use super::*;
97
98    #[test]
99    fn test_is_mito_engine_option_key() {
100        assert!(is_mito_engine_option_key("ttl"));
101        assert!(is_mito_engine_option_key("compaction.type"));
102        assert!(is_mito_engine_option_key(
103            "compaction.twcs.max_active_window_runs"
104        ));
105        assert!(is_mito_engine_option_key(
106            "compaction.twcs.max_inactive_window_runs"
107        ));
108        assert!(is_mito_engine_option_key("compaction.twcs.time_window"));
109        assert!(is_mito_engine_option_key("storage"));
110        assert!(is_mito_engine_option_key(
111            "index.inverted_index.ignore_column_ids"
112        ));
113        assert!(is_mito_engine_option_key(
114            "index.inverted_index.segment_row_count"
115        ));
116        assert!(is_mito_engine_option_key("wal_options"));
117        assert!(is_mito_engine_option_key("memtable.type"));
118        assert!(is_mito_engine_option_key(
119            "memtable.partition_tree.index_max_keys_per_shard"
120        ));
121        assert!(is_mito_engine_option_key(
122            "memtable.partition_tree.data_freeze_threshold"
123        ));
124        assert!(is_mito_engine_option_key(
125            "memtable.partition_tree.fork_dictionary_bytes"
126        ));
127        assert!(is_mito_engine_option_key("append_mode"));
128        assert!(!is_mito_engine_option_key("foo"));
129    }
130}