diff --git a/compute_tools/src/compute.rs b/compute_tools/src/compute.rs index caae072095..cca8dd5f97 100644 --- a/compute_tools/src/compute.rs +++ b/compute_tools/src/compute.rs @@ -2134,6 +2134,25 @@ impl ComputeNode { Ok(()) } + /// Tell postgres/pgbouncer/local_proxy to reload their configurations. + #[instrument(skip_all)] + pub fn reload(&self, spec: ComputeSpec) -> Result<()> { + let rt = tokio::runtime::Handle::current(); + if spec.pgbouncer_settings.is_some() { + rt.block_on(reload_pgbouncer())?; + } + if spec.local_proxy_config.is_some() { + local_proxy::reload()?; + } + self.pg_reload_conf()?; + + let unknown_op = "unknown".to_string(); + let op_id = spec.operation_uuid.as_ref().unwrap_or(&unknown_op); + info!("finished reload of compute node for operation {op_id}"); + + Ok(()) + } + #[instrument(skip_all)] pub fn configure_as_primary(&self, compute_state: &ComputeState) -> Result<()> { let pspec = compute_state.pspec.as_ref().expect("spec must be set"); diff --git a/compute_tools/src/local_proxy.rs b/compute_tools/src/local_proxy.rs index 3de3c58786..5c0615ea41 100644 --- a/compute_tools/src/local_proxy.rs +++ b/compute_tools/src/local_proxy.rs @@ -11,9 +11,11 @@ use utils::pid_file::{self, PidFileRead}; pub fn configure(local_proxy: &LocalProxySpec) -> Result<()> { write_local_proxy_conf("/etc/local_proxy/config.json".as_ref(), local_proxy)?; - notify_local_proxy("/etc/local_proxy/pid".as_ref())?; + reload() +} - Ok(()) +pub fn reload() -> Result<()> { + notify_local_proxy("/etc/local_proxy/pid".as_ref()) } /// Create or completely rewrite configuration file specified by `path` diff --git a/compute_tools/src/pg_helpers.rs b/compute_tools/src/pg_helpers.rs index 09bbe89b41..b82902b078 100644 --- a/compute_tools/src/pg_helpers.rs +++ b/compute_tools/src/pg_helpers.rs @@ -466,13 +466,7 @@ fn update_pgbouncer_ini( Ok(()) } -/// Tune pgbouncer. -/// 1. Apply new config using pgbouncer admin console -/// 2. Add new values to pgbouncer.ini to preserve them after restart -pub async fn tune_pgbouncer( - mut pgbouncer_config: IndexMap, - tls_config: Option, -) -> Result<()> { +async fn connect() -> Result { let pgbouncer_connstr = if std::env::var_os("AUTOSCALING").is_some() { // for VMs use pgbouncer specific way to connect to // pgbouncer admin console without password @@ -518,6 +512,16 @@ pub async fn tune_pgbouncer( } }; + Ok(client) +} + +/// Tune pgbouncer. +/// 1. Apply new config to pgbouncer.ini +/// 2. Notify pgbouncer to reload +pub async fn tune_pgbouncer( + mut pgbouncer_config: IndexMap, + tls_config: Option, +) -> Result<()> { if let Some(tls_config) = tls_config { // pgbouncer starts in a half-ok state if it cannot find these files. // It will default to client_tls_sslmode=deny, which causes proxy to error. @@ -550,9 +554,16 @@ pub async fn tune_pgbouncer( info!("Applying pgbouncer setting change"); + reload_pgbouncer().await +} + +/// Reload pgbouncer. +pub async fn reload_pgbouncer() -> Result<()> { + let client = connect().await?; + if let Err(err) = client.simple_query("RELOAD").await { // Don't fail on error, just print it into log - error!("Failed to apply pgbouncer setting change, {err}",); + error!("Failed to apply pgbouncer setting change: {err}",); }; Ok(())