mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-11 07:22:55 +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
53 lines
1.6 KiB
Rust
53 lines
1.6 KiB
Rust
use anyhow::{Ok, Result, anyhow};
|
|
use tokio_postgres::NoTls;
|
|
use tracing::{error, instrument, warn};
|
|
|
|
use crate::compute::ComputeNode;
|
|
|
|
/// Update timestamp in a row in a special service table to check
|
|
/// that we can actually write some data in this particular timeline.
|
|
#[instrument(skip_all)]
|
|
pub async fn check_writability(compute: &ComputeNode) -> Result<()> {
|
|
// Connect to the database.
|
|
let conf = compute.get_tokio_conn_conf(Some("compute_ctl:availability_checker"));
|
|
let (client, connection) = conf.connect(NoTls).await?;
|
|
if client.is_closed() {
|
|
return Err(anyhow!("connection to postgres closed"));
|
|
}
|
|
|
|
// The connection object performs the actual communication with the database,
|
|
// so spawn it off to run on its own.
|
|
tokio::spawn(async move {
|
|
if let Err(e) = connection.await {
|
|
error!("connection error: {}", e);
|
|
}
|
|
});
|
|
|
|
let query = "
|
|
INSERT INTO health_check VALUES (1, now())
|
|
ON CONFLICT (id) DO UPDATE
|
|
SET updated_at = now();";
|
|
|
|
match client.simple_query(query).await {
|
|
Result::Ok(result) => {
|
|
if result.len() != 1 {
|
|
return Err(anyhow::anyhow!(
|
|
"expected 1 query results, but got {}",
|
|
result.len()
|
|
));
|
|
}
|
|
}
|
|
Err(err) => {
|
|
if let Some(state) = err.code() {
|
|
if state == &tokio_postgres::error::SqlState::DISK_FULL {
|
|
warn!("Tenant disk is full");
|
|
return Ok(());
|
|
}
|
|
}
|
|
return Err(err.into());
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|