From f879c66f142df389abe03cf977e93a04f662ab43 Mon Sep 17 00:00:00 2001 From: Tristan Partin Date: Thu, 13 Mar 2025 15:12:20 -0500 Subject: [PATCH] BLAH --- Cargo.lock | 38 ++++++++--------------- Cargo.toml | 4 +-- compute_tools/src/pg_helpers.rs | 54 +++++++++++++++++---------------- vendor/postgres-v17 | 2 +- vendor/revisions.json | 2 +- 5 files changed, 44 insertions(+), 56 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 094bcb5045..f99c40f084 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3270,11 +3270,11 @@ dependencies = [ [[package]] name = "inotify" -version = "0.10.2" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdd168d97690d0b8c412d6b6c10360277f4d7ee495c5d0d5d5fe0854923255cc" +checksum = "f37dccff2791ab604f9babef0ba14fbe0be30bd368dc541e2b08d07c8aa908f3" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.8.0", "inotify-sys", "libc", ] @@ -3772,18 +3772,6 @@ dependencies = [ "adler2", ] -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "log", - "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys 0.48.0", -] - [[package]] name = "mio" version = "1.0.3" @@ -3791,6 +3779,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" dependencies = [ "libc", + "log", "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys 0.52.0", ] @@ -3868,8 +3857,9 @@ checksum = "38bf9645c8b145698bb0b18a4637dcacbc421ea49bef2317e4fd8065a387cf21" [[package]] name = "notify" -version = "6.1.1" -source = "git+https://github.com/notify-rs/notify?rev=ae69a5ca3463a1ffc3322c6a7b67894a2e545817#ae69a5ca3463a1ffc3322c6a7b67894a2e545817" +version = "8.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fee8403b3d66ac7b26aee6e40a897d85dc5ce26f44da36b8b73e987cc52e943" dependencies = [ "bitflags 2.8.0", "filetime", @@ -3878,19 +3868,17 @@ dependencies = [ "kqueue", "libc", "log", - "mio 0.8.11", + "mio", "notify-types", "walkdir", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] name = "notify-types" -version = "1.0.0" -source = "git+https://github.com/notify-rs/notify?rev=ae69a5ca3463a1ffc3322c6a7b67894a2e545817#ae69a5ca3463a1ffc3322c6a7b67894a2e545817" -dependencies = [ - "instant", -] +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e0826a989adedc2a244799e823aece04662b66609d96af8dff7ac6df9a8925d" [[package]] name = "ntapi" @@ -7197,7 +7185,7 @@ dependencies = [ "backtrace", "bytes", "libc", - "mio 1.0.3", + "mio", "parking_lot 0.12.1", "pin-project-lite", "signal-hook-registry", diff --git a/Cargo.toml b/Cargo.toml index 369055a006..e3f7f237df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -126,9 +126,7 @@ measured = { version = "0.0.22", features=["lasso"] } measured-process = { version = "0.0.22" } memoffset = "0.9" nix = { version = "0.27", features = ["dir", "fs", "process", "socket", "signal", "poll"] } -# Do not update to >= 7.0.0, at least. The update will have a significant impact -# on compute startup metrics (start_postgres_ms), >= 25% degradation. -notify = { git = "https://github.com/notify-rs/notify", rev = "ae69a5ca3463a1ffc3322c6a7b67894a2e545817" } +notify = "8.0.0" num_cpus = "1.15" num-traits = "0.2.15" once_cell = "1.13" diff --git a/compute_tools/src/pg_helpers.rs b/compute_tools/src/pg_helpers.rs index 802e3e93d9..9b70836a27 100644 --- a/compute_tools/src/pg_helpers.rs +++ b/compute_tools/src/pg_helpers.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use std::fmt::Write; use std::fs; use std::fs::File; -use std::io::{BufRead, BufReader}; +use std::io::{BufRead, BufReader, Seek}; use std::os::unix::fs::PermissionsExt; use std::path::Path; use std::process::Child; @@ -335,10 +335,25 @@ pub fn wait_for_postgres(pg: &mut Child, pgdata: &Path) -> Result<()> { } }; - watcher.watch(pgdata, RecursiveMode::NonRecursive)?; + // You cannot actually watch a file before it exists, so let's create the + // the postmaster.pid file for Postgres, so we can watch it even before + // Postgres actually starts. In the event that it already exists, just open + // the file for reading. Remember that we are racing Postgres here and that + // it doesn't matter who creates the postmaster.pid. + let mut file = match File::create(&pid_path) { + Ok(file) => file, + Err(e) => { + if e.kind() != std::io::ErrorKind::AlreadyExists { + return Err(anyhow::anyhow!(e)); + } + + File::open(&pid_path)? + } + }; + + watcher.watch(&pid_path, RecursiveMode::NonRecursive)?; let started_at = Instant::now(); - let mut postmaster_pid_seen = false; loop { if let Ok(Some(status)) = pg.try_wait() { // Postgres exited, that is not what we expected, bail out earlier. @@ -355,31 +370,18 @@ pub fn wait_for_postgres(pg: &mut Child, pgdata: &Path) -> Result<()> { debug!("swallowing extra event: {res:?}"); } - // Check that we can open pid file first. - if let Ok(file) = File::open(&pid_path) { - if !postmaster_pid_seen { - debug!("postmaster.pid appeared"); - watcher - .unwatch(pgdata) - .expect("Failed to remove pgdata dir watch"); - watcher - .watch(&pid_path, RecursiveMode::NonRecursive) - .expect("Failed to add postmaster.pid file watch"); - postmaster_pid_seen = true; - } + file.seek(std::io::SeekFrom::Start(0)).unwrap(); + let reader = BufReader::new(&file); + let last_line = reader.lines().last(); - let file = BufReader::new(file); - let last_line = file.lines().last(); + // Pid file could be there and we could read it, but it could be empty, for example. + if let Some(Ok(line)) = last_line { + let status = line.trim(); + debug!("last line of postmaster.pid: {status:?}"); - // Pid file could be there and we could read it, but it could be empty, for example. - if let Some(Ok(line)) = last_line { - let status = line.trim(); - debug!("last line of postmaster.pid: {status:?}"); - - // Now Postgres is ready to accept connections - if status == "ready" { - break; - } + // Now Postgres is ready to accept connections + if status == "ready" { + break; } } diff --git a/vendor/postgres-v17 b/vendor/postgres-v17 index e5e87b9f52..4cf26c3551 160000 --- a/vendor/postgres-v17 +++ b/vendor/postgres-v17 @@ -1 +1 @@ -Subproject commit e5e87b9f52d0eaeb83f3e2517bb9727aac37729b +Subproject commit 4cf26c355142dc9009042dbc90e0231a6218fe0d diff --git a/vendor/revisions.json b/vendor/revisions.json index 1d76e1da01..7c20487301 100644 --- a/vendor/revisions.json +++ b/vendor/revisions.json @@ -1,7 +1,7 @@ { "v17": [ "17.4", - "e5e87b9f52d0eaeb83f3e2517bb9727aac37729b" + "4cf26c355142dc9009042dbc90e0231a6218fe0d" ], "v16": [ "16.8",