Compare commits

...

7 Commits

Author SHA1 Message Date
Tristan Partin
f879c66f14 BLAH 2025-03-13 15:12:35 -05:00
Tristan Partin
387b5c585e Commit 6 2025-03-13 15:12:35 -05:00
Tristan Partin
ad83156e2f Commit 5 2025-03-13 15:12:35 -05:00
Tristan Partin
3bcfaeb936 Commit 4 2025-03-13 15:12:35 -05:00
Tristan Partin
7c102b92fb Commit 3 2025-03-13 15:12:35 -05:00
Tristan Partin
2e59a41c98 Commit 2 2025-03-13 15:12:35 -05:00
Tristan Partin
358b59a5d7 Commit 1
Signed-off-by: Tristan Partin <tristan@neon.tech>
2025-03-13 15:12:35 -05:00
5 changed files with 47 additions and 52 deletions

37
Cargo.lock generated
View File

@@ -3270,11 +3270,11 @@ dependencies = [
[[package]]
name = "inotify"
version = "0.9.6"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff"
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,23 +3857,29 @@ checksum = "38bf9645c8b145698bb0b18a4637dcacbc421ea49bef2317e4fd8065a387cf21"
[[package]]
name = "notify"
version = "6.1.1"
version = "8.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d"
checksum = "2fee8403b3d66ac7b26aee6e40a897d85dc5ce26f44da36b8b73e987cc52e943"
dependencies = [
"bitflags 2.8.0",
"crossbeam-channel",
"filetime",
"fsevent-sys",
"inotify",
"kqueue",
"libc",
"log",
"mio 0.8.11",
"mio",
"notify-types",
"walkdir",
"windows-sys 0.48.0",
"windows-sys 0.59.0",
]
[[package]]
name = "notify-types"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e0826a989adedc2a244799e823aece04662b66609d96af8dff7ac6df9a8925d"
[[package]]
name = "ntapi"
version = "0.4.1"
@@ -7190,7 +7185,7 @@ dependencies = [
"backtrace",
"bytes",
"libc",
"mio 1.0.3",
"mio",
"parking_lot 0.12.1",
"pin-project-lite",
"signal-hook-registry",

View File

@@ -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 = "6.0.0"
notify = "8.0.0"
num_cpus = "1.15"
num-traits = "0.2.15"
once_cell = "1.13"

View File

@@ -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;
}
}

View File

@@ -1,7 +1,7 @@
{
"v17": [
"17.4",
"e5e87b9f52d0eaeb83f3e2517bb9727aac37729b"
"4cf26c355142dc9009042dbc90e0231a6218fe0d"
],
"v16": [
"16.8",