From bf56ea8c43932696cfdb91217c98c407cbe1eb2f Mon Sep 17 00:00:00 2001 From: Stas Kelvich Date: Wed, 9 Jun 2021 18:04:30 +0300 Subject: [PATCH] Locate postgres binary and libs for 'postgres --wal-redo' based on POSTGRES_DISTRIB_DIR. --- control_plane/src/compute.rs | 2 +- control_plane/src/storage.rs | 8 +------- pageserver/src/walredo.rs | 31 ++++++++++++++++--------------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/control_plane/src/compute.rs b/control_plane/src/compute.rs index 2e49776865..fd41b7a946 100644 --- a/control_plane/src/compute.rs +++ b/control_plane/src/compute.rs @@ -154,7 +154,7 @@ impl ComputeControlPlane { concat!( "shared_preload_libraries = zenith\n", "synchronous_standby_names = 'pageserver'\n", // TODO: add a new function arg? - "zenith.callmemaybe_connstring = '{}'\n", // FIXME escaping + "zenith.callmemaybe_connstring = '{}'\n", // FIXME escaping ), node.connstr() ) diff --git a/control_plane/src/storage.rs b/control_plane/src/storage.rs index 3e98a0c5e0..d57b8863e9 100644 --- a/control_plane/src/storage.rs +++ b/control_plane/src/storage.rs @@ -52,9 +52,6 @@ impl PageServerNode { self.env.pg_distrib_dir.to_str().unwrap(), ) .env("ZENITH_REPO_DIR", self.repo_path()) - .env("PATH", self.env.pg_bin_dir().to_str().unwrap()) // needs postres-wal-redo binary - .env("LD_LIBRARY_PATH", self.env.pg_lib_dir().to_str().unwrap()) - .env("DYLD_LIBRARY_PATH", self.env.pg_lib_dir().to_str().unwrap()) .status() .expect("pageserver init failed"); @@ -94,10 +91,7 @@ impl PageServerNode { "POSTGRES_DISTRIB_DIR", self.env.pg_distrib_dir.to_str().unwrap(), ) - .env("ZENITH_REPO_DIR", self.repo_path()) - .env("PATH", self.env.pg_bin_dir().to_str().unwrap()) // needs postres-wal-redo binary - .env("LD_LIBRARY_PATH", self.env.pg_lib_dir().to_str().unwrap()) - .env("DYLD_LIBRARY_PATH", self.env.pg_lib_dir().to_str().unwrap()); + .env("ZENITH_REPO_DIR", self.repo_path()); if !cmd.status()?.success() { bail!( diff --git a/pageserver/src/walredo.rs b/pageserver/src/walredo.rs index 5fca43b011..f410693178 100644 --- a/pageserver/src/walredo.rs +++ b/pageserver/src/walredo.rs @@ -22,7 +22,7 @@ use std::fs; use std::fs::OpenOptions; use std::io::prelude::*; use std::io::Error; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use std::process::Stdio; use std::sync::mpsc; use std::sync::Mutex; @@ -206,15 +206,10 @@ impl PostgresRedoManagerInternal { let process: PostgresRedoProcess; - // FIXME: We need a dummy Postgres cluster to run the process in. Currently, we - // just create one with constant name. That fails if you try to launch more than - // one WAL redo manager concurrently. - let datadir = self.conf.workdir.join("wal-redo-datadir"); - info!("launching WAL redo postgres process"); process = runtime - .block_on(PostgresRedoProcess::launch(&datadir)) + .block_on(PostgresRedoProcess::launch(self.conf)) .unwrap(); // Loop forever, handling requests as they come. @@ -290,12 +285,12 @@ impl PostgresRedoProcess { // // Start postgres binary in special WAL redo mode. // - // Tests who run pageserver binary are setting proper PG_BIN_DIR - // and PG_LIB_DIR so that WalRedo would start right postgres. + async fn launch(conf: &PageServerConf) -> Result { + // FIXME: We need a dummy Postgres cluster to run the process in. Currently, we + // just create one with constant name. That fails if you try to launch more than + // one WAL redo manager concurrently. + let datadir = conf.workdir.join("wal-redo-datadir"); - // do that: We may later - // switch to setting same things in pageserver config file. - async fn launch(datadir: &Path) -> Result { // Create empty data directory for wal-redo postgres, deleting old one first. if datadir.exists() { info!("directory {:?} exists, removing", &datadir); @@ -304,9 +299,12 @@ impl PostgresRedoProcess { } } info!("running initdb in {:?}", datadir.display()); - let initdb = Command::new("initdb") + let initdb = Command::new(conf.pg_bin_dir().join("initdb")) .args(&["-D", datadir.to_str().unwrap()]) .arg("-N") + .env_clear() + .env("LD_LIBRARY_PATH", conf.pg_lib_dir().to_str().unwrap()) + .env("DYLD_LIBRARY_PATH", conf.pg_lib_dir().to_str().unwrap()) .output() .await .expect("failed to execute initdb"); @@ -328,12 +326,15 @@ impl PostgresRedoProcess { config.write_all(b"zenith.wal_redo=on\n")?; } // Start postgres itself - let mut child = Command::new("postgres") + let mut child = Command::new(conf.pg_bin_dir().join("postgres")) .arg("--wal-redo") .stdin(Stdio::piped()) .stderr(Stdio::piped()) .stdout(Stdio::piped()) - .env("PGDATA", datadir) + .env_clear() + .env("LD_LIBRARY_PATH", conf.pg_lib_dir().to_str().unwrap()) + .env("DYLD_LIBRARY_PATH", conf.pg_lib_dir().to_str().unwrap()) + .env("PGDATA", &datadir) .spawn() .expect("postgres --wal-redo command failed to start");