From 55e40d090ec83f5708acd788a9a4e38942a7b234 Mon Sep 17 00:00:00 2001 From: Arthur Petukhovsky Date: Tue, 25 Jul 2023 11:16:47 +0000 Subject: [PATCH] Run sync several times --- libs/walproposer/bindgen_deps.h | 2 ++ libs/walproposer/build.rs | 1 + libs/walproposer/src/simtest/wp_sk.rs | 9 ++++++++- pgxn/neon/walproposer.c | 27 +++++++++++++++++++++++++++ pgxn/neon/walproposer.h | 3 --- 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/libs/walproposer/bindgen_deps.h b/libs/walproposer/bindgen_deps.h index ab9365c8e8..e53cc2c0d7 100644 --- a/libs/walproposer/bindgen_deps.h +++ b/libs/walproposer/bindgen_deps.h @@ -20,5 +20,7 @@ void RunClientC(uint32_t serverId); void WalProposerRust(); +void WalProposerCleanup(); + // Initialize global variables before calling any Postgres C code. void MyContextInit(); diff --git a/libs/walproposer/build.rs b/libs/walproposer/build.rs index 627cbd3bed..e3713d20b2 100644 --- a/libs/walproposer/build.rs +++ b/libs/walproposer/build.rs @@ -108,6 +108,7 @@ fn main() -> anyhow::Result<()> { .allowlist_function("RunClientC") .allowlist_function("WalProposerRust") .allowlist_function("MyContextInit") + .allowlist_function("WalProposerCleanup") .allowlist_var("wal_acceptors_list") .allowlist_var("wal_acceptor_reconnect_timeout") .allowlist_var("wal_acceptor_connection_timeout") diff --git a/libs/walproposer/src/simtest/wp_sk.rs b/libs/walproposer/src/simtest/wp_sk.rs index 3d67266bb8..5bc7896832 100644 --- a/libs/walproposer/src/simtest/wp_sk.rs +++ b/libs/walproposer/src/simtest/wp_sk.rs @@ -10,7 +10,7 @@ use utils::{id::TenantTimelineId, logging, lsn::Lsn}; use crate::{ bindings::{ neon_tenant_walproposer, neon_timeline_walproposer, wal_acceptor_connection_timeout, - wal_acceptor_reconnect_timeout, wal_acceptors_list, WalProposerRust, + wal_acceptor_reconnect_timeout, wal_acceptors_list, WalProposerRust, WalProposerCleanup, }, c_context, simtest::safekeeper::run_server, @@ -94,6 +94,8 @@ impl Test { let list = CString::new(guc).unwrap(); unsafe { + WalProposerCleanup(); + wal_acceptors_list = list.into_raw(); wal_acceptor_reconnect_timeout = 1000; wal_acceptor_connection_timeout = 5000; @@ -134,4 +136,9 @@ fn sync_empty_safekeepers() { let lsn = test.sync_safekeepers().unwrap(); assert_eq!(lsn, Lsn(0)); + println!("Sucessfully synced empty safekeepers at 0/0"); + + let lsn = test.sync_safekeepers().unwrap(); + assert_eq!(lsn, Lsn(0)); + println!("Sucessfully synced empty safekeepers at 0/0"); } diff --git a/pgxn/neon/walproposer.c b/pgxn/neon/walproposer.c index 98988c8239..69007269bf 100644 --- a/pgxn/neon/walproposer.c +++ b/pgxn/neon/walproposer.c @@ -321,6 +321,33 @@ nwp_shmem_startup_hook(void) WalproposerShmemInit(); } +void WalProposerCleanup() +{ + n_safekeepers = 0; + quorum = 0; + lastSentCommitLsn = 0; + availableLsn = 0; + lastSentCommitLsn = 0; + truncateLsn = 0; + propTerm = 0; + propTermHistory.entries = NULL; + propTermHistory.n_entries = 0; + propEpochStartLsn = 0; + donorEpoch = 0; + donor = 0; + timelineStartLsn = 0; + n_votes = 0; + n_connected = 0; + last_reconnect_attempt = 0; + + if (walprop_shared != NULL) + { + memset(walprop_shared, 0, WalproposerShmemSize()); + SpinLockInit(&walprop_shared->mutex); + pg_atomic_init_u64(&walprop_shared->backpressureThrottlingTime, 0); + } +} + void WalProposerRust() { walprop_log(LOG, "WalProposerRust"); diff --git a/pgxn/neon/walproposer.h b/pgxn/neon/walproposer.h index ddf3163455..d122a9e58a 100644 --- a/pgxn/neon/walproposer.h +++ b/pgxn/neon/walproposer.h @@ -51,9 +51,6 @@ extern int wal_acceptor_reconnect_timeout; extern int wal_acceptor_connection_timeout; extern bool am_wal_proposer; -/* If true, we're exiting. */ -extern bool walproposer_exited; - struct WalProposerConn; /* Defined in libpqwalproposer */ typedef struct WalProposerConn WalProposerConn;