Skip to content

Commit

Permalink
config: Fix titan blob-run-mode setting (#15988) (#16013)
Browse files Browse the repository at this point in the history
close #15978, close #15987

Fix titan config blob-run-mode's from<ConfigValue> implementation.

Signed-off-by: tonyxuqqi <tonyxuqi@outlook.com>

Co-authored-by: tonyxuqqi <tonyxuqi@outlook.com>
  • Loading branch information
ti-chi-bot and tonyxuqqi committed Dec 4, 2023
1 parent 693a450 commit 07c8319
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
11 changes: 7 additions & 4 deletions components/engine_rocks/src/config.rs
Expand Up @@ -340,9 +340,9 @@ pub enum BlobRunMode {
impl From<BlobRunMode> for ConfigValue {
fn from(mode: BlobRunMode) -> ConfigValue {
let str_value = match mode {
BlobRunMode::Normal => "normal",
BlobRunMode::ReadOnly => "read-only",
BlobRunMode::Fallback => "fallback",
BlobRunMode::Normal => "kNormal",
BlobRunMode::ReadOnly => "kReadOnly",
BlobRunMode::Fallback => "kFallback",
};
ConfigValue::String(str_value.into())
}
Expand All @@ -366,8 +366,11 @@ impl FromStr for BlobRunMode {
"normal" => Ok(BlobRunMode::Normal),
"read-only" => Ok(BlobRunMode::ReadOnly),
"fallback" => Ok(BlobRunMode::Fallback),
"kNormal" => Ok(BlobRunMode::Normal),
"kReadOnly" => Ok(BlobRunMode::ReadOnly),
"kFallback" => Ok(BlobRunMode::Fallback),
m => Err(format!(
"expect: normal, read-only or fallback, got: {:?}",
"expect: normal, kNormal, read-only, kReadOnly, kFallback or fallback, got: {:?}",
m
)),
}
Expand Down
38 changes: 35 additions & 3 deletions src/config/mod.rs
Expand Up @@ -4251,15 +4251,20 @@ impl ConfigController {

pub fn update(&self, change: HashMap<String, String>) -> CfgResult<()> {
let diff = to_config_change(change.clone())?;
self.update_impl(diff, Some(change))
self.update_impl(diff, Some(change), true)
}

pub fn update_without_persist(&self, change: HashMap<String, String>) -> CfgResult<()> {
let diff = to_config_change(change.clone())?;
self.update_impl(diff, Some(change), false)
}

pub fn update_from_toml_file(&self) -> CfgResult<()> {
let current = self.get_current();
match TikvConfig::from_file(Path::new(&current.cfg_path), None) {
Ok(incoming) => {
let diff = current.diff(&incoming);
self.update_impl(diff, None)
self.update_impl(diff, None, true)
}
Err(e) => Err(e),
}
Expand All @@ -4269,6 +4274,7 @@ impl ConfigController {
&self,
mut diff: HashMap<String, ConfigValue>,
change: Option<HashMap<String, String>>,
persist: bool,
) -> CfgResult<()> {
diff = {
let incoming = self.get_current();
Expand Down Expand Up @@ -4301,6 +4307,11 @@ impl ConfigController {
}
}
debug!("all config change had been dispatched"; "change" => ?to_update);

if !persist {
return Ok(());
}

// we already verified the correctness at the beginning of this function.
inner.current.update(to_update).unwrap();
// Write change to the config file
Expand Down Expand Up @@ -5107,7 +5118,28 @@ mod tests {
let diff = config_value_to_string(diff.into_iter().collect());
assert_eq!(diff.len(), 1);
assert_eq!(diff[0].0.as_str(), "blob_run_mode");
assert_eq!(diff[0].1.as_str(), "fallback");
assert_eq!(diff[0].1.as_str(), "kFallback");
}

#[test]
fn test_update_titan_blob_run_mode_config() {
let mut cfg = TikvConfig::default();
cfg.rocksdb.titan.enabled = true;
let (_, cfg_controller, ..) = new_engines::<ApiV1>(cfg);
for run_mode in [
"kFallback",
"kNormal",
"kReadOnly",
"fallback",
"normal",
"read-only",
] {
let change = HashMap::from([(
"rocksdb.defaultcf.titan.blob-run-mode".to_string(),
run_mode.to_string(),
)]);
cfg_controller.update_without_persist(change).unwrap();
}
}

#[test]
Expand Down

0 comments on commit 07c8319

Please sign in to comment.