Signalling the postgres server when the leader changes, but does not become this node

pmeunier
Jan 18, 2022, 11:35 PM
UEGA35KU63HPNZLXVR5CS2BNMCVOV7HOBTDR4K6YZSPDFWXIKKZQC

Dependencies

  • [2] FIIWK33F Fixing lock issues
  • [3] ENEREHTW Restart and rewind the server during failover (requires policykit)
  • [4] NPSWSVZN Init
  • [5] 6Z6PYXTS Testing and debugging

Change contents

  • replacement in src/main.rs at line 261
    [2.2226][2.2226:2287]()
    rewind(&path, port, &db_name, leader).await;
    [2.2226]
    [2.2287]
    rewind(&path, port, &db_name, leader, &password).await;
    } else {
    reload(&path).await;
  • edit in src/main.rs at line 265
    [2.2301]
    [3.3173]
    } else {
    reload(&path).await;
  • replacement in src/main.rs at line 287
    [3.3348][3.3348:3418](),[3.3418][2.2501:2526]()
    async fn rewind(path: &str, port: u16, db_name: &str, leader: &str) {
    debug!("rewinding");
    [3.3348]
    [3.3418]
    async fn reload(path: &str) {
    debug!("reload");
  • replacement in src/main.rs at line 290
    [3.3451][2.2527:2567](),[2.2567][3.3481:3524](),[3.3481][3.3481:3524]()
    let out = Command::new("systemctl")
    .args(["stop", "postgresql-repl"])
    [3.3451]
    [3.3524]
    let out = Command::new("pg_ctl")
    .args(["reload", "-D", path])
  • edit in src/main.rs at line 298
    [2.2702]
    [2.2702]
    }
    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
    [2.2752]
    [2.2752]
    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();
    [2.3449]
    [3.4112]
    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;
    }