mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-16 09:52:54 +00:00
Migrates the remaining 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. Like the previous migration PRs, this is comprised of three commits: * the first does the edition update and makes `cargo check`/`cargo clippy` pass. we had to update bindgen to make its output [satisfy the requirements of edition 2024](https://doc.rust-lang.org/edition-guide/rust-2024/unsafe-extern.html) * the second commit does a `cargo fmt` for the new style edition. * the third commit reorders imports as a one-off change. As before, it is entirely optional. Part of #10918
63 lines
1.9 KiB
Rust
63 lines
1.9 KiB
Rust
//! Code to manage the storage broker
|
|
//!
|
|
//! In the local test environment, the storage broker stores its data directly in
|
|
//!
|
|
//! ```text
|
|
//! .neon
|
|
//! ```
|
|
use std::time::Duration;
|
|
|
|
use anyhow::Context;
|
|
use camino::Utf8PathBuf;
|
|
|
|
use crate::{background_process, local_env};
|
|
|
|
pub async fn start_broker_process(
|
|
env: &local_env::LocalEnv,
|
|
retry_timeout: &Duration,
|
|
) -> anyhow::Result<()> {
|
|
let broker = &env.broker;
|
|
let listen_addr = &broker.listen_addr;
|
|
|
|
print!("Starting neon broker at {}", listen_addr);
|
|
|
|
let args = [format!("--listen-addr={listen_addr}")];
|
|
|
|
let client = reqwest::Client::new();
|
|
background_process::start_process(
|
|
"storage_broker",
|
|
&env.base_data_dir,
|
|
&env.storage_broker_bin(),
|
|
args,
|
|
[],
|
|
background_process::InitialPidFile::Create(storage_broker_pid_file_path(env)),
|
|
retry_timeout,
|
|
|| async {
|
|
let url = broker.client_url();
|
|
let status_url = url.join("status").with_context(|| {
|
|
format!("Failed to append /status path to broker endpoint {url}")
|
|
})?;
|
|
let request = client
|
|
.get(status_url)
|
|
.build()
|
|
.with_context(|| format!("Failed to construct request to broker endpoint {url}"))?;
|
|
match client.execute(request).await {
|
|
Ok(resp) => Ok(resp.status().is_success()),
|
|
Err(_) => Ok(false),
|
|
}
|
|
},
|
|
)
|
|
.await
|
|
.context("Failed to spawn storage_broker subprocess")?;
|
|
Ok(())
|
|
}
|
|
|
|
pub fn stop_broker_process(env: &local_env::LocalEnv) -> anyhow::Result<()> {
|
|
background_process::stop_process(true, "storage_broker", &storage_broker_pid_file_path(env))
|
|
}
|
|
|
|
fn storage_broker_pid_file_path(env: &local_env::LocalEnv) -> Utf8PathBuf {
|
|
Utf8PathBuf::from_path_buf(env.base_data_dir.join("storage_broker.pid"))
|
|
.expect("non-Unicode path")
|
|
}
|