mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-16 09:52:54 +00:00
Updates `compute_tools` and `compute_api` crates to edition 2024. We like to stay on the latest edition if possible. There is no functional changes, however some code changes had to be done to accommodate the edition's breaking changes. The PR has three commits: * the first commit updates the named crates to edition 2024 and appeases `cargo clippy` by changing code. * the second commit performs a `cargo fmt` that does some minor changes (not many) * the third commit performs a cargo fmt with nightly options to reorder imports as a one-time thing. it's completely optional, but I offer it here for the compute team to review it. I'd like to hear opinions about the third commit, if it's wanted and felt worth the diff or not. I think most attention should be put onto the first commit. Part of #10918
47 lines
1.9 KiB
Rust
47 lines
1.9 KiB
Rust
use std::path::Path;
|
|
|
|
use anyhow::{Context, anyhow};
|
|
use tracing::{instrument, warn};
|
|
|
|
pub const RESIZE_SWAP_BIN: &str = "/neonvm/bin/resize-swap";
|
|
|
|
#[instrument]
|
|
pub fn resize_swap(size_bytes: u64) -> anyhow::Result<()> {
|
|
// run `/neonvm/bin/resize-swap --once {size_bytes}`
|
|
//
|
|
// Passing '--once' causes resize-swap to delete itself after successful completion, which
|
|
// means that if compute_ctl restarts later, we won't end up calling 'swapoff' while
|
|
// postgres is running.
|
|
//
|
|
// NOTE: resize-swap is not very clever. If present, --once MUST be the first arg.
|
|
let child_result = std::process::Command::new("/usr/bin/sudo")
|
|
.arg(RESIZE_SWAP_BIN)
|
|
.arg("--once")
|
|
.arg(size_bytes.to_string())
|
|
.spawn();
|
|
|
|
child_result
|
|
.context("spawn() failed")
|
|
.and_then(|mut child| child.wait().context("wait() failed"))
|
|
.and_then(|status| match status.success() {
|
|
true => Ok(()),
|
|
false => {
|
|
// The command failed. Maybe it was because the resize-swap file doesn't exist?
|
|
// The --once flag causes it to delete itself on success so we don't disable swap
|
|
// while postgres is running; maybe this is fine.
|
|
match Path::new(RESIZE_SWAP_BIN).try_exists() {
|
|
Err(_) | Ok(true) => Err(anyhow!("process exited with {status}")),
|
|
// The path doesn't exist; we're actually ok
|
|
Ok(false) => {
|
|
warn!("ignoring \"not found\" error from resize-swap to avoid swapoff while compute is running");
|
|
Ok(())
|
|
},
|
|
}
|
|
}
|
|
})
|
|
// wrap any prior error with the overall context that we couldn't run the command
|
|
.with_context(|| {
|
|
format!("could not run `/usr/bin/sudo {RESIZE_SWAP_BIN} --once {size_bytes}`")
|
|
})
|
|
}
|