Signalling the postgres server when the leader changes, but does not become this node
Dependencies
- [2]
FIIWK33FFixing lock issues - [3]
ENEREHTWRestart and rewind the server during failover (requires policykit) - [4]
NPSWSVZNInit - [5]
6Z6PYXTSTesting and debugging
Change contents
- replacement in src/main.rs at line 261
rewind(&path, port, &db_name, leader).await;rewind(&path, port, &db_name, leader, &password).await;} else {reload(&path).await; - edit in src/main.rs at line 265
} else {reload(&path).await; - replacement in src/main.rs at line 287
async fn rewind(path: &str, port: u16, db_name: &str, leader: &str) {debug!("rewinding");async fn reload(path: &str) {debug!("reload"); - replacement in src/main.rs at line 290
let out = Command::new("systemctl").args(["stop", "postgresql-repl"])let out = Command::new("pg_ctl").args(["reload", "-D", path]) - edit in src/main.rs at line 298
}async fn rewind(path: &str, port: u16, db_name: &str, leader: &str, password: &str) {debug!("rewinding");use std::io::Write;use tokio::process::Command; - edit in src/main.rs at line 306
let out = Command::new("systemctl").args(["stop", "postgresql-repl"]).output().await.expect("failed to execute process");std::io::stdout().write_all(&out.stdout).unwrap();std::io::stderr().write_all(&out.stderr).unwrap();success = out.status.success();tokio::time::sleep(std::time::Duration::from_secs(1)).await;}let mut success = false;while !success { - replacement in src/main.rs at line 338[2.3449]→[2.3449:3489](∅→∅),[2.3489]→[3.3989:4112](∅→∅),[3.3989]→[3.3989:4112](∅→∅),[3.4112]→[2.3490:3600](∅→∅)
let out = Command::new("systemctl").args(["start", "postgresql-repl"]).output().await.expect("failed to execute process");std::io::stdout().write_all(&out.stdout).unwrap();std::io::stderr().write_all(&out.stderr).unwrap();std::fs::write(std::path::Path::new(path).join("postgresql.auto.conf"),format!("primary_conninfo = 'host={} port=5432 user=replication password={}'",leader, password,),).unwrap();let mut success = false;while !success {let out = Command::new("systemctl").args(["start", "postgresql-repl"]).output().await.expect("failed to execute process");std::io::stdout().write_all(&out.stdout).unwrap();std::io::stderr().write_all(&out.stderr).unwrap();success = out.status.success();tokio::time::sleep(std::time::Duration::from_secs(1)).await;}