Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conf: rewrite unified pool related configurations #7946

Merged
merged 11 commits into from
Jun 1, 2020
54 changes: 53 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,14 @@ impl StorageReadPoolConfig {
// The storage module does not use the unified pool by default.
self.use_unified_pool.unwrap_or(false)
}

pub fn adjust_use_unified_pool(&mut self) {
if self.use_unified_pool.is_none() {
// The storage module does not use the unified pool by default.
info!("readpool.storage.use-unified-pool is not set, set to false by default");
self.use_unified_pool = Some(false);
}
}
}

const DEFAULT_COPROCESSOR_READPOOL_MIN_CONCURRENCY: usize = 2;
Expand Down Expand Up @@ -1752,6 +1760,19 @@ impl CoprReadPoolConfig {
self.use_unified_pool
.unwrap_or_else(|| *self == Default::default())
}

pub fn adjust_use_unified_pool(&mut self) {
if self.use_unified_pool.is_none() {
// The coprocessor module uses the unified pool unless it has customized configurations.
if *self == Default::default() {
info!("readpool.coprocessor.use-unified-pool is not set, set to true by default");
self.use_unified_pool = Some(true);
} else {
info!("readpool.coprocessor.use-unified-pool is not set, set to false because there are other customized configurations");
self.use_unified_pool = Some(false);
}
}
}
}

#[derive(Clone, Serialize, Deserialize, Default, PartialEq, Debug)]
Expand All @@ -1768,6 +1789,11 @@ impl ReadPoolConfig {
self.storage.use_unified_pool() || self.coprocessor.use_unified_pool()
}

pub fn adjust_use_unified_pool(&mut self) {
self.storage.adjust_use_unified_pool();
self.coprocessor.adjust_use_unified_pool();
}

pub fn validate(&self) -> Result<(), Box<dyn Error>> {
if self.is_unified_pool_enabled() {
self.unified.validate()?;
Expand Down Expand Up @@ -1848,11 +1874,12 @@ mod readpool_tests {
assert!(storage.validate().is_ok());
let coprocessor = CoprReadPoolConfig::default();
assert!(coprocessor.validate().is_ok());
let cfg = ReadPoolConfig {
let mut cfg = ReadPoolConfig {
unified,
storage,
coprocessor,
};
cfg.adjust_use_unified_pool();
assert!(cfg.is_unified_pool_enabled());
assert!(cfg.validate().is_err());
}
Expand Down Expand Up @@ -2191,6 +2218,8 @@ impl TiKvConfig {
+ self.raftdb.defaultcf.block_cache_size.0,
});
}

self.readpool.adjust_use_unified_pool();
}

pub fn check_critical_cfg_with(&self, last_cfg: &Self) -> Result<(), String> {
Expand Down Expand Up @@ -2961,4 +2990,27 @@ mod tests {
assert_eq!(c, cfg);
}
}

#[test]
fn test_readpool_compatible_adjust_config() {
let content = r#"
[readpool.storage]
[readpool.coprocessor]
"#;
let mut cfg: TiKvConfig = toml::from_str(content).unwrap();
cfg.compatible_adjust();
assert_eq!(cfg.readpool.storage.use_unified_pool, Some(false));
assert_eq!(cfg.readpool.coprocessor.use_unified_pool, Some(true));

let content = r#"
[readpool.storage]
stack-size = "10MB"
[readpool.coprocessor]
normal-concurrency = 1
"#;
let mut cfg: TiKvConfig = toml::from_str(content).unwrap();
cfg.compatible_adjust();
assert_eq!(cfg.readpool.storage.use_unified_pool, Some(false));
assert_eq!(cfg.readpool.coprocessor.use_unified_pool, Some(false));
}
}