mirror of
https://github.com/neondatabase/neon.git
synced 2026-05-30 11:30:37 +00:00
* Poll more frequently when waiting for process start/stop. This speeds up startup and shutdown in tests. We did this already in commit52ce1c9d53, which reduced the interval to 100 ms, but it was inadvertently increased back to 500 ms in commitd42700280f. Reduce it to 100 ms again, for both start and stop operations. * Harmonize the start and stop loops, printing the dots and notices the same way in both. I considered extracting the logic to a separate retry-function that takes a closure as argument that does the polling, but as long as we only have two copies, the code duplication isn't that bad. * Remove newline after "Starting pageserver" and "Starting etcd" messages, so that the progress-indicator dots that are printed once a second are printed on the same line. Before: Starting pageserver at '127.0.0.1:64000' in '.neon' ... pageserver started, pid: 2538937 After: Starting pageserver at '127.0.0.1:64000' in '.neon'... pageserver started, pid: 2538937 The "Starting safekeeper" message already got this right. * Update example output in README.md to match
78 lines
2.6 KiB
Rust
78 lines
2.6 KiB
Rust
use std::{fs, path::PathBuf};
|
|
|
|
use anyhow::Context;
|
|
|
|
use crate::{background_process, local_env};
|
|
|
|
pub fn start_etcd_process(env: &local_env::LocalEnv) -> anyhow::Result<()> {
|
|
let etcd_broker = &env.etcd_broker;
|
|
print!(
|
|
"Starting etcd broker using {:?}",
|
|
etcd_broker.etcd_binary_path
|
|
);
|
|
|
|
let etcd_data_dir = env.base_data_dir.join("etcd");
|
|
fs::create_dir_all(&etcd_data_dir)
|
|
.with_context(|| format!("Failed to create etcd data dir {etcd_data_dir:?}"))?;
|
|
|
|
let client_urls = etcd_broker.comma_separated_endpoints();
|
|
let args = [
|
|
format!("--data-dir={}", etcd_data_dir.display()),
|
|
format!("--listen-client-urls={client_urls}"),
|
|
format!("--advertise-client-urls={client_urls}"),
|
|
// Set --quota-backend-bytes to keep the etcd virtual memory
|
|
// size smaller. Our test etcd clusters are very small.
|
|
// See https://github.com/etcd-io/etcd/issues/7910
|
|
"--quota-backend-bytes=100000000".to_string(),
|
|
// etcd doesn't compact (vacuum) with default settings,
|
|
// enable it to prevent space exhaustion.
|
|
"--auto-compaction-mode=revision".to_string(),
|
|
"--auto-compaction-retention=1".to_string(),
|
|
];
|
|
|
|
let pid_file_path = etcd_pid_file_path(env);
|
|
|
|
let client = reqwest::blocking::Client::new();
|
|
|
|
background_process::start_process(
|
|
"etcd",
|
|
&etcd_data_dir,
|
|
&etcd_broker.etcd_binary_path,
|
|
&args,
|
|
background_process::InitialPidFile::Create(&pid_file_path),
|
|
|| {
|
|
for broker_endpoint in &etcd_broker.broker_endpoints {
|
|
let request = broker_endpoint
|
|
.join("health")
|
|
.with_context(|| {
|
|
format!(
|
|
"Failed to append /health path to broker endopint {}",
|
|
broker_endpoint
|
|
)
|
|
})
|
|
.and_then(|url| {
|
|
client.get(&url.to_string()).build().with_context(|| {
|
|
format!("Failed to construct request to etcd endpoint {url}")
|
|
})
|
|
})?;
|
|
if client.execute(request).is_ok() {
|
|
return Ok(true);
|
|
}
|
|
}
|
|
|
|
Ok(false)
|
|
},
|
|
)
|
|
.context("Failed to spawn etcd subprocess")?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
pub fn stop_etcd_process(env: &local_env::LocalEnv) -> anyhow::Result<()> {
|
|
background_process::stop_process(true, "etcd", &etcd_pid_file_path(env))
|
|
}
|
|
|
|
fn etcd_pid_file_path(env: &local_env::LocalEnv) -> PathBuf {
|
|
env.base_data_dir.join("etcd.pid")
|
|
}
|