From 13e94bf6876102d6d5d1a901dd2a816d6d4d2557 Mon Sep 17 00:00:00 2001 From: Arthur Petukhovsky Date: Tue, 29 Aug 2023 09:03:22 +0000 Subject: [PATCH] Fix truncateLsn bug --- libs/walproposer/src/simtest/safekeeper.rs | 5 +++-- libs/walproposer/src/simtest/wp_sk.rs | 2 +- libs/walproposer/test.c | 1 + pgxn/neon/walproposer.c | 11 +++++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/libs/walproposer/src/simtest/safekeeper.rs b/libs/walproposer/src/simtest/safekeeper.rs index 5a106274a3..4daf69e804 100644 --- a/libs/walproposer/src/simtest/safekeeper.rs +++ b/libs/walproposer/src/simtest/safekeeper.rs @@ -16,7 +16,7 @@ use safekeeper::{ timeline::TimelineError, SafeKeeperConf, }; -use tracing::debug; +use tracing::{debug, info_span}; use utils::{ id::{NodeId, TenantId, TenantTimelineId, TimelineId}, lsn::Lsn, @@ -147,7 +147,8 @@ impl GlobalMap { } pub fn run_server(os: NodeOs, disk: Arc) -> Result<()> { - debug!("started server {}", os.id()); + let _enter = info_span!("safekeeper", id = os.id()).entered(); + debug!("started server"); let conf = SafeKeeperConf { workdir: PathBuf::from("."), my_id: NodeId(os.id() as u64), diff --git a/libs/walproposer/src/simtest/wp_sk.rs b/libs/walproposer/src/simtest/wp_sk.rs index cd3a1a8db1..8d2bdc5c5f 100644 --- a/libs/walproposer/src/simtest/wp_sk.rs +++ b/libs/walproposer/src/simtest/wp_sk.rs @@ -191,7 +191,7 @@ fn test_one_schedule() -> anyhow::Result<()> { // test.run_schedule(&schedule)?; // test.world.stop_all(); - let seed = 14035854184686918762; + let seed = 16600359418126807633; let test = config.start(seed); warn!("Running test with seed {}", seed); diff --git a/libs/walproposer/test.c b/libs/walproposer/test.c index dcda54552e..01f2480536 100644 --- a/libs/walproposer/test.c +++ b/libs/walproposer/test.c @@ -81,6 +81,7 @@ void MyContextInit() { exit(1); log_min_messages = FATAL; + // log_min_messages = LOG; Log_line_prefix = "[%p] "; InitializeMaxBackends(); diff --git a/pgxn/neon/walproposer.c b/pgxn/neon/walproposer.c index 158c1bbc83..a858c5cdea 100644 --- a/pgxn/neon/walproposer.c +++ b/pgxn/neon/walproposer.c @@ -1505,6 +1505,17 @@ DetermineEpochStartLsn(void) walprop_log(LOG, "bumped epochStartLsn to the first record %X/%X", LSN_FORMAT_ARGS(propEpochStartLsn)); } + if (truncateLsn == InvalidXLogRecPtr && timelineStartLsn == propEpochStartLsn) + { + /* + * If truncateLsn is 0 everywhere, we are bootstrapping -- nothing was + * committed yet. But if timelineStartLsn is not 0, we already know + * the first record location, so we can bump truncateLsn to it. + */ + truncateLsn = timelineStartLsn; + walprop_log(LOG, "bumped truncateLsn to timelineStartLsn %X/%X", LSN_FORMAT_ARGS(truncateLsn)); + } + /* * If propEpochStartLsn is not 0, at least one msg with WAL was sent to * some connected safekeeper; it must have carried truncateLsn pointing to