From aea4f9222eb53cdb9c49190d79bfb6659c44f536 Mon Sep 17 00:00:00 2001 From: Hou Zhijie Date: Fri, 10 Jan 2025 09:58:15 +0800 Subject: [PATCH v21 7/7] Update flush location more frequently --- src/backend/replication/logical/worker.c | 28 ++++++++++-------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c index 5fa382ab3e..453bd22432 100644 --- a/src/backend/replication/logical/worker.c +++ b/src/backend/replication/logical/worker.c @@ -448,7 +448,6 @@ static void request_publisher_status(RetainConflictInfoData *data); static void wait_for_publisher_status(RetainConflictInfoData *data, bool status_received); static void wait_for_local_flush(RetainConflictInfoData *data); -static inline bool can_advance_nonremovable_xid(RetainConflictInfoData *data); static void adjust_xid_advance_interval(RetainConflictInfoData *data, bool new_xid_found); @@ -3771,13 +3770,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received) apply_dispatch(&s); - /* - * Attempt to advance the non-removable transaction ID - * to avoid accumulating dead rows when the worker is - * busy. - */ - if (can_advance_nonremovable_xid(&data)) - maybe_advance_nonremovable_xid(&data, false); + maybe_advance_nonremovable_xid(&data, false); } else if (c == 'k') { @@ -4300,6 +4293,10 @@ wait_for_publisher_status(RetainConflictInfoData *data, bool status_received) static void wait_for_local_flush(RetainConflictInfoData *data) { + XLogRecPtr writepos; + XLogRecPtr flushpos; + bool have_pending_txes; + Assert(!XLogRecPtrIsInvalid(data->remote_lsn) && FullTransactionIdIsValid(data->candidate_xid)); @@ -4334,6 +4331,12 @@ wait_for_local_flush(RetainConflictInfoData *data) if (!AllTablesyncsReady()) return; + /* Fetch and update latest remote flush position */ + get_flush_position(&writepos, &flushpos, &have_pending_txes); + + if (flushpos > last_flushpos) + last_flushpos = flushpos; + /* * Return to wait for the changes to be applied. * @@ -4378,15 +4381,6 @@ wait_for_local_flush(RetainConflictInfoData *data) maybe_advance_nonremovable_xid(data, false); } -/* - * Determine if we can attempt to advance transaction ID. - */ -static inline bool -can_advance_nonremovable_xid(RetainConflictInfoData *data) -{ - return data->phase == RCI_GET_CANDIDATE_XID; -} - /* * Adjust the interval for advancing non-removable transaction IDs. * -- 2.43.0