From a345ff7f835b49c9addf4883b339ce268e1668cc Mon Sep 17 00:00:00 2001 From: Andreas Date: Tue, 20 Apr 2021 13:01:54 +0200 Subject: [PATCH] Validate `config-template.toml` (#10010) * Added tests to validate config-template.toml Signed-off-by: Andreas Zimmerer * Fixed comment about default value for pd_config.endpoints Signed-off-by: Andreas Zimmerer * Fixed issues in config-template.toml to pass tests Signed-off-by: Andreas Zimmerer * Fix fields that differed in TiKvConfig::default() and config-template Signed-off-by: Andreas Zimmerer * added level_merge in TitanCfConfig again Signed-off-by: Andreas Zimmerer * renamed level_merge to level-merge Signed-off-by: Andreas Zimmerer * added batch-size again Signed-off-by: Andreas Zimmerer Co-authored-by: Andy Lok Co-authored-by: Ti Chi Robot <71242396+ti-chi-bot@users.noreply.github.com> --- components/pd_client/src/config.rs | 2 +- etc/config-template.toml | 41 ++++++++-------- src/config.rs | 79 ++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 22 deletions(-) diff --git a/components/pd_client/src/config.rs b/components/pd_client/src/config.rs index d572d8744c8..958ee737f00 100644 --- a/components/pd_client/src/config.rs +++ b/components/pd_client/src/config.rs @@ -13,7 +13,7 @@ use tikv_util::config::ReadableDuration; pub struct Config { /// The PD endpoints for the client. /// - /// Default is empty. + /// Default is `"127.0.0.1:2379"`. pub endpoints: Vec, /// The interval at which to retry a PD connection initialization. /// diff --git a/etc/config-template.toml b/etc/config-template.toml index 4d698ef5d30..38db63ac636 100644 --- a/etc/config-template.toml +++ b/etc/config-template.toml @@ -39,7 +39,7 @@ ## It won't take effect when compiling without BCC_IOSNOOP=1. # enable-io-snoop = true -# Configurations for the single thread pool serving read requests. +## Configurations for the single thread pool serving read requests. [readpool.unified] ## The minimal working thread count of the thread pool. # min-thread-count = 1 @@ -56,7 +56,7 @@ [readpool.storage] ## Whether to use the unified read pool to handle storage requests. -# use-unified-pool = false +# use-unified-pool = true ## The following configurations only take effect when `use-unified-pool` is false. @@ -123,7 +123,7 @@ # grpc-compression-type = "none" ## Size of the thread pool for the gRPC server. -# grpc-concurrency = 4 +# grpc-concurrency = 5 ## The number of max concurrent streams/requests on a client connection. # grpc-concurrent-stream = 1024 @@ -179,12 +179,12 @@ [storage] ## The path to RocksDB directory. -# data-dir = "/tmp/tikv/store" +# data-dir = "./" ## The number of slots in Scheduler latches, which controls write concurrency. ## In most cases you can use the default value. When importing data, you can set it to a larger ## value. -# scheduler-concurrency = 2048000 +# scheduler-concurrency = 524288 ## Scheduler's worker pool size, i.e. the number of write threads. ## It should be less than total CPU cores. When there are frequent write operations, set it to a @@ -232,7 +232,7 @@ [pd] ## PD endpoints. -# endpoints = [] +# endpoints = ["127.0.0.1:2379"] ## The interval at which to retry a PD connection initialization. ## Default is 300ms. @@ -296,7 +296,7 @@ # raft-log-gc-threshold = 50 ## When the entry count exceeds this value, GC will be forced to trigger. -# raft-log-gc-count-limit = 72000 +# raft-log-gc-count-limit = 73728 ## When the approximate size of Raft log entries exceeds this value, GC will be forced trigger. ## It's recommanded to set it to 3/4 of `region-split-size`. @@ -331,8 +331,8 @@ # lock-cf-compact-interval = "10m" # lock-cf-compact-bytes-threshold = "256MB" -## Interval (s) to check Region whether the data are consistent. -# consistency-check-interval = 0 +## Interval to check region whether the data is consistent. +# consistency-check-interval = "0s" ## Interval to clean up import SST files. # cleanup-import-sst-interval = "10m" @@ -417,7 +417,7 @@ ## persistent storage. See https://github.com/facebook/rocksdb/wiki/How-to-persist-in-memory-RocksDB-database . ## If there are two disks on the machine, storing RocksDB data and WAL logs on different disks can ## improve performance. -# wal-dir = "/tmp/tikv/store" +# wal-dir = "" ## The following two fields affect how archived WAL will be deleted. ## 1. If both values are set to 0, logs will be deleted ASAP and will not get into the archive. @@ -505,7 +505,7 @@ ## absolute path will be used as the log file name's prefix. # info-log-dir = "" -# RocksDB log levels +## RocksDB log levels # info-log-level = "info" ## Options for `Titan`. @@ -516,7 +516,7 @@ # enabled = false ## Maximum number of threads of `Titan` background gc jobs. -# default: 4 +## default: 4 # max-background-gc = 4 ## Options for "Default" Column Family, which stores actual user data. @@ -690,16 +690,16 @@ ## lz4: kLZ4Compression ## lz4hc: kLZ4HCCompression ## zstd: kZSTD -# default: lz4 +## default: lz4 # blob-file-compression = "lz4" ## Specifics cache size for blob records -# default: 0 +## default: 0 # blob-cache-size = "0GB" ## If the ratio of discardable size of a blob file is larger than ## this threshold, the blob file will be GCed out. -# default: 0.5 +## default: 0.5 # discardable-ratio = 0.5 ## The mode used to process blob files. In read-only mode Titan @@ -709,7 +709,7 @@ ## default: kNormal ## read-only: kReadOnly ## fallback: kFallback -# default: normal +## default: normal # blob-run-mode = "normal" ## If set true, values in blob file will be merged to a new blob file while @@ -722,7 +722,7 @@ ## ## Requirement: level_compaction_dynamic_level_base = true ## default: false -# level_merge = false +# level-merge = false ## Use merge operator to rewrite GC blob index. ## default: false @@ -789,7 +789,7 @@ # writable-file-max-buffer-size = "1MB" # use-direct-io-for-flush-and-compaction = false # enable-pipelined-write = true -# allow-concurrent-memtable-write = false +# allow-concurrent-memtable-write = true # bytes-per-sync = "1MB" # wal-bytes-per-sync = "512KB" @@ -798,7 +798,6 @@ # info-log-keep-log-file-num = 10 # info-log-dir = "" # info-log-level = "info" -# optimize-filters-for-hits = true [raftdb.defaultcf] ## Recommend to set it the same as `rocksdb.defaultcf.compression-per-level`. @@ -848,7 +847,7 @@ ## Default is false. # redact-info-log = false -# Configurations for encryption at rest. Experimental. +## Configurations for encryption at rest. Experimental. [security.encryption] ## Encryption method to use for data files. ## Possible values are "plaintext", "aes128-ctr", "aes192-ctr" and "aes256-ctr". Value other than @@ -925,7 +924,7 @@ # num-threads = 24 ## Number of ranges to backup in one batch. -# batch = 8 +# batch-size = 8 ## When Backup region [a,e) size exceeds `sst-max-size`, it will be backuped into several Files [a,b), ## [b,c), [c,d), [d,e) and the size of [a,b), [b,c), [c,d) will be `sst-max-size` (or a diff --git a/src/config.rs b/src/config.rs index 02838d7034d..01945d02c80 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3095,6 +3095,7 @@ impl ConfigController { #[cfg(test)] mod tests { + use itertools::Itertools; use tempfile::Builder; use super::*; @@ -3787,4 +3788,82 @@ mod tests { } ); } + + #[test] + fn test_config_template_is_valid() { + let template_config = std::include_str!("../etc/config-template.toml") + .lines() + .map(|l| l.strip_prefix('#').unwrap_or(l)) + .join("\n"); + + let mut cfg: TiKvConfig = toml::from_str(&template_config).unwrap(); + cfg.validate().unwrap(); + } + + #[test] + fn test_config_template_no_superfluous_keys() { + let template_config = std::include_str!("../etc/config-template.toml") + .lines() + .map(|l| l.strip_prefix('#').unwrap_or(l)) + .join("\n"); + + let mut deserializer = toml::Deserializer::new(&template_config); + let mut unrecognized_keys = Vec::new(); + let _: TiKvConfig = serde_ignored::deserialize(&mut deserializer, |key| { + unrecognized_keys.push(key.to_string()) + }) + .unwrap(); + + // Don't use `is_empty()` so we see which keys are superfluous on failure. + assert_eq!(unrecognized_keys, Vec::::new()); + } + + #[test] + fn test_config_template_matches_default() { + let template_config = std::include_str!("../etc/config-template.toml") + .lines() + .map(|l| l.strip_prefix('#').unwrap_or(l)) + .join("\n"); + + let mut cfg: TiKvConfig = toml::from_str(&template_config).unwrap(); + let mut default_cfg = TiKvConfig::default(); + + // Some default values are computed based on the environment. + // Because we can't set config values for these in `config-template.toml`, we will handle + // them manually. + cfg.readpool.unified.max_thread_count = default_cfg.readpool.unified.max_thread_count; + cfg.readpool.storage.high_concurrency = default_cfg.readpool.storage.high_concurrency; + cfg.readpool.storage.normal_concurrency = default_cfg.readpool.storage.normal_concurrency; + cfg.readpool.storage.low_concurrency = default_cfg.readpool.storage.low_concurrency; + cfg.readpool.coprocessor.high_concurrency = + default_cfg.readpool.coprocessor.high_concurrency; + cfg.readpool.coprocessor.normal_concurrency = + default_cfg.readpool.coprocessor.normal_concurrency; + cfg.readpool.coprocessor.low_concurrency = default_cfg.readpool.coprocessor.low_concurrency; + cfg.server.grpc_memory_pool_quota = default_cfg.server.grpc_memory_pool_quota; + cfg.server.background_thread_count = default_cfg.server.background_thread_count; + cfg.server.end_point_max_concurrency = default_cfg.server.end_point_max_concurrency; + cfg.storage.scheduler_worker_pool_size = default_cfg.storage.scheduler_worker_pool_size; + cfg.rocksdb.max_background_jobs = default_cfg.rocksdb.max_background_jobs; + cfg.rocksdb.max_background_flushes = default_cfg.rocksdb.max_background_flushes; + cfg.rocksdb.max_sub_compactions = default_cfg.rocksdb.max_sub_compactions; + cfg.rocksdb.titan.max_background_gc = default_cfg.rocksdb.titan.max_background_gc; + cfg.raftdb.max_background_jobs = default_cfg.raftdb.max_background_jobs; + cfg.raftdb.max_background_flushes = default_cfg.raftdb.max_background_flushes; + cfg.raftdb.max_sub_compactions = default_cfg.raftdb.max_sub_compactions; + cfg.raftdb.titan.max_background_gc = default_cfg.raftdb.titan.max_background_gc; + cfg.backup.num_threads = default_cfg.backup.num_threads; + + // There is another set of config values that we can't directly compare: + // When the default values are `None`, but are then resolved to `Some(_)` later on. + default_cfg.readpool.storage.adjust_use_unified_pool(); + default_cfg.readpool.coprocessor.adjust_use_unified_pool(); + default_cfg.security.redact_info_log = Some(false); + + // Other special cases. + cfg.pd.retry_max_count = default_cfg.pd.retry_max_count; // Both -1 and isize::MAX are the same. + cfg.storage.block_cache.capacity = OptionReadableSize(None); // Either `None` and a value is computed or `Some(_)` fixed value. + + assert_eq!(cfg, default_cfg); + } }