-
Notifications
You must be signed in to change notification settings - Fork 437
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
refactor(pageserver): better pageservice command parsing #9597
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Alex Chi Z <chi@neon.tech>
6d2a5ba
to
9daae35
Compare
5328 tests run: 5106 passed, 0 failed, 222 skipped (full report)Code coverage* (full report)
* collected from Rust tests only The comment gets automatically updated with the latest test results
60791a6 at 2024-10-31T20:29:54.727Z :recycle: |
Signed-off-by: Alex Chi Z <chi@neon.tech>
fn parse(query: &str) -> anyhow::Result<Self> { | ||
let query = query.trim(); | ||
let Some((cmd, other)) = query.split_once(' ') else { | ||
bail!("cannot parse query: {}", query) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bail!("cannot parse query: {}", query) | |
bail!("cannot parse query: {query}") |
if cmd2 == "lsn" { | ||
Ok(Self::LeaseLsn(LeaseLsnCmd::parse(other)?)) | ||
} else { | ||
bail!("invalid lease command: {}", cmd); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bail!("invalid lease command: {}", cmd); | |
bail!("invalid lease command: {cmd}"); |
} | ||
} | ||
"set" => Ok(Self::Set), | ||
_ => Err(anyhow::anyhow!("unsupported command {} in {}", cmd, query)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_ => Err(anyhow::anyhow!("unsupported command {} in {}", cmd, query)), | |
_ => Err(anyhow::anyhow!("unsupported command {cmd} in {query}")), |
match param { | ||
"--gzip" => { | ||
if gzip { | ||
bail!("duplicate parameter for basebackup command: {}", param) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bail!("duplicate parameter for basebackup command: {}", param) | |
bail!("duplicate parameter for basebackup command: {param}") |
} | ||
"--replica" => { | ||
if replica { | ||
bail!("duplicate parameter for basebackup command: {}", param) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bail!("duplicate parameter for basebackup command: {}", param) | |
bail!("duplicate parameter for basebackup command: {param}") |
} | ||
replica = true | ||
} | ||
_ => bail!("invalid parameter for basebackup command: {}", param), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_ => bail!("invalid parameter for basebackup command: {}", param), | |
_ => bail!("invalid parameter for basebackup command: {param}"), |
} else { | ||
lsn = Some( | ||
Lsn::from_str(maybe_lsn) | ||
.with_context(|| format!("Failed to parse lsn from {}", maybe_lsn))?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.with_context(|| format!("Failed to parse lsn from {}", maybe_lsn))?, | |
.with_context(|| format!("Failed to parse lsn from {maybe_lsn}"))?, |
"fullbackup" => Ok(Self::FullBackup(FullBackupCmd::parse(other)?)), | ||
"lease" => { | ||
let Some((cmd2, other)) = other.split_once(' ') else { | ||
bail!("invalid lease command: {}", cmd); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bail!("invalid lease command: {}", cmd); | |
bail!("invalid lease command: {cmd}"); |
Problem
close #9460
Summary of changes
A full rewrite of pagestream cmdline parsing to make it more robust and readable.
Checklist before requesting a review
Checklist before merging