Skip to content

Commit

Permalink
Fix value toml parsing and add a ut
Browse files Browse the repository at this point in the history
  • Loading branch information
shanyp committed Nov 29, 2023
1 parent aae5190 commit b26f4c8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
13 changes: 13 additions & 0 deletions pageserver/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,19 @@ trace_read_requests = {trace_read_requests}"#,
Ok(())
}

#[test]
fn parse_override_tenant_config() -> anyhow::Result<()> {
let config_string = r#"tenant_config={ min_resident_size_override = 400 }"#.to_string();

let toml: Document = config_string.parse()?;
let item = toml.get("tenant_config").unwrap();
let conf = TenantConfOpt::try_from(item.to_owned()).unwrap();

assert_eq!(conf.min_resident_size_override, Some(400));

Ok(())
}

#[test]
fn eviction_pageserver_config_parse() -> anyhow::Result<()> {
let tempdir = tempdir()?;
Expand Down
8 changes: 3 additions & 5 deletions pageserver/src/tenant/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,11 +546,9 @@ impl TryFrom<toml_edit::Item> for TenantConfOpt {
fn try_from(item: toml_edit::Item) -> Result<Self, Self::Error> {
match item {
toml_edit::Item::Value(value) => {
let mut table = toml_edit::Table::new();
table["value"] = toml_edit::Item::Value(value);
let deserializer = toml_edit::de::Deserializer::new(table.into());
serde_path_to_error::deserialize(deserializer)
.map_err(|e| anyhow::anyhow!("{}: {}", e.path(), e.inner().message()))
let d = value.into_deserializer();
return serde_path_to_error::deserialize(d)
.map_err(|e| anyhow::anyhow!("{}: {}", e.path(), e.inner().message()));
}
toml_edit::Item::Table(table) => {
let deserializer = toml_edit::de::Deserializer::new(table.into());
Expand Down

0 comments on commit b26f4c8

Please sign in to comment.