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

refactor(pageserver): better pageservice command parsing #9597

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

skyzh
Copy link
Member

@skyzh skyzh commented Oct 31, 2024

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

  • I have performed a self-review of my code.
  • If it is a core feature, I have added thorough tests.
  • Do we need to implement analytics? if so did you add the relevant metrics to the dashboard?
  • If this PR requires public announcement, mark it with /release-notes label and add several sentences in this section.

Checklist before merging

  • Do not forget to reformat commit message to not include the above checklist

@skyzh skyzh requested a review from a team as a code owner October 31, 2024 17:18
@skyzh skyzh requested a review from arpad-m October 31, 2024 17:18
Signed-off-by: Alex Chi Z <chi@neon.tech>
@skyzh skyzh force-pushed the skyzh/pageservice-cmd-handle branch from 6d2a5ba to 9daae35 Compare October 31, 2024 17:25
Copy link

github-actions bot commented Oct 31, 2024

5328 tests run: 5106 passed, 0 failed, 222 skipped (full report)


Code coverage* (full report)

  • functions: 31.5% (7782 of 24697 functions)
  • lines: 49.1% (61328 of 124959 lines)

* 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bail!("invalid lease command: {}", cmd);
bail!("invalid lease command: {cmd}");

}
}
"set" => Ok(Self::Set),
_ => Err(anyhow::anyhow!("unsupported command {} in {}", cmd, query)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_ => 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bail!("duplicate parameter for basebackup command: {}", param)
bail!("duplicate parameter for basebackup command: {param}")

}
"--replica" => {
if replica {
bail!("duplicate parameter for basebackup command: {}", param)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bail!("duplicate parameter for basebackup command: {}", param)
bail!("duplicate parameter for basebackup command: {param}")

}
replica = true
}
_ => bail!("invalid parameter for basebackup command: {}", param),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_ => 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))?,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bail!("invalid lease command: {}", cmd);
bail!("invalid lease command: {cmd}");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pageserver: basebackup cmdline parsing refactor
2 participants