mirror of
https://github.com/neondatabase/neon.git
synced 2026-05-29 11:00:38 +00:00
In local dev environment, these steps take around 100 ms, and they are in the critical path of a compute startup on a compute pool hit. I don't know if it's like that in production, but as first step, add tracing spans to the functions so that they can be measured more easily.
28 lines
1.1 KiB
Rust
28 lines
1.1 KiB
Rust
use anyhow::Context;
|
|
use tracing::instrument;
|
|
|
|
pub const DISK_QUOTA_BIN: &str = "/neonvm/bin/set-disk-quota";
|
|
|
|
/// If size_bytes is 0, it disables the quota. Otherwise, it sets filesystem quota to size_bytes.
|
|
/// `fs_mountpoint` should point to the mountpoint of the filesystem where the quota should be set.
|
|
#[instrument]
|
|
pub fn set_disk_quota(size_bytes: u64, fs_mountpoint: &str) -> anyhow::Result<()> {
|
|
let size_kb = size_bytes / 1024;
|
|
// run `/neonvm/bin/set-disk-quota {size_kb} {mountpoint}`
|
|
let child_result = std::process::Command::new("/usr/bin/sudo")
|
|
.arg(DISK_QUOTA_BIN)
|
|
.arg(size_kb.to_string())
|
|
.arg(fs_mountpoint)
|
|
.spawn();
|
|
|
|
child_result
|
|
.context("spawn() failed")
|
|
.and_then(|mut child| child.wait().context("wait() failed"))
|
|
.and_then(|status| match status.success() {
|
|
true => Ok(()),
|
|
false => Err(anyhow::anyhow!("process exited with {status}")),
|
|
})
|
|
// wrap any prior error with the overall context that we couldn't run the command
|
|
.with_context(|| format!("could not run `/usr/bin/sudo {DISK_QUOTA_BIN}`"))
|
|
}
|