Skip to content

Commit

Permalink
cherry pick tikv#7946 to release-4.0
Browse files Browse the repository at this point in the history
Signed-off-by: sre-bot <sre-bot@pingcap.com>
  • Loading branch information
sticnarf authored and sre-bot committed Jun 1, 2020
1 parent 198a2ce commit da862b7
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,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 @@ -1684,6 +1692,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 @@ -1700,6 +1721,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 @@ -1780,11 +1806,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 @@ -2162,6 +2189,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 @@ -2932,4 +2961,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));
}
}

0 comments on commit da862b7

Please sign in to comment.