Skip to content

Commit

Permalink
Validate config-template.toml (tikv#10010)
Browse files Browse the repository at this point in the history
* Added tests to validate config-template.toml

Signed-off-by: Andreas Zimmerer <[email protected]>

* Fixed comment about default value for pd_config.endpoints

Signed-off-by: Andreas Zimmerer <[email protected]>

* Fixed issues in config-template.toml to pass tests

Signed-off-by: Andreas Zimmerer <[email protected]>

* Fix fields that differed in TiKvConfig::default() and config-template

Signed-off-by: Andreas Zimmerer <[email protected]>

* added level_merge in TitanCfConfig again

Signed-off-by: Andreas Zimmerer <[email protected]>

* renamed level_merge to level-merge

Signed-off-by: Andreas Zimmerer <[email protected]>

* added batch-size again

Signed-off-by: Andreas Zimmerer <[email protected]>

Co-authored-by: Andy Lok <[email protected]>
Co-authored-by: Ti Chi Robot <[email protected]>
  • Loading branch information
3 people authored Apr 20, 2021
1 parent 95ebc5c commit a345ff7
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 22 deletions.
2 changes: 1 addition & 1 deletion components/pd_client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// The interval at which to retry a PD connection initialization.
///
Expand Down
41 changes: 20 additions & 21 deletions etc/config-template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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`.
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"

Expand All @@ -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`.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
79 changes: 79 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3095,6 +3095,7 @@ impl ConfigController {

#[cfg(test)]
mod tests {
use itertools::Itertools;
use tempfile::Builder;

use super::*;
Expand Down Expand Up @@ -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::<String>::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);
}
}

0 comments on commit a345ff7

Please sign in to comment.