public inbox for [email protected]
help / color / mirror / Atom feedFrom: Chao Li <[email protected]>
To: Postgres hackers <[email protected]>
Subject: Refactor replication origin state reset helpers
Date: Wed, 24 Dec 2025 09:28:37 +0800
Message-ID: <CAEoWx2=pYvfRthXHTzSrOsf5_FfyY4zJyK4zV2v4W=yjUij1cA@mail.gmail.com> (raw)
Hi Hacker,
While reviewing patches [1] and [2], I noticed some duplicate code of
clearing replication origin states, I am proposing a small patch that
removes the duplicate code blocks by introducing a couple helper
functions. No functional change at all.
[1]
https://postgr.es/m/TY4PR01MB169078771FB31B395AB496A6B94B4A@TY4PR01MB16907.jpnprd01.prod.outlook.com
[2] https://postgr.es/m/[email protected]
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
Attachments:
[application/octet-stream] v1-0001-Refactor-replication-origin-state-reset-helpers.patch (4.3K, ../CAEoWx2=pYvfRthXHTzSrOsf5_FfyY4zJyK4zV2v4W=yjUij1cA@mail.gmail.com/3-v1-0001-Refactor-replication-origin-state-reset-helpers.patch)
download | inline diff:
From 49596baf76cfa393da071de672b193bf6ba83eca Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <[email protected]>
Date: Wed, 24 Dec 2025 09:17:27 +0800
Subject: [PATCH v1] Refactor replication origin state reset helpers
Factor out common logic for clearing per-transaction and per-session
replication origin state into dedicated helper functions.
This removes duplicated assignments of replorigin_session_origin,
replorigin_session_origin_lsn, and replorigin_session_origin_timestamp
across multiple call sites, and makes the intended scope of each reset
(clear per-transaction state vs. clear per-session state) explicit.
No functional change intended.
Author: Chao Li <[email protected]>
---
src/backend/replication/logical/origin.c | 28 +++++++++++++++++----
src/backend/replication/logical/tablesync.c | 4 +--
src/backend/replication/logical/worker.c | 4 +--
src/include/replication/origin.h | 1 +
4 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/src/backend/replication/logical/origin.c b/src/backend/replication/logical/origin.c
index 2380f369578..aec9e30b4d6 100644
--- a/src/backend/replication/logical/origin.c
+++ b/src/backend/replication/logical/origin.c
@@ -200,6 +200,17 @@ replorigin_check_prerequisites(bool check_origins, bool recoveryOK)
errmsg("cannot manipulate replication origins during recovery")));
}
+/*
+ * replorigin_xact_clear_state
+ * Clear per transaction state variables.
+ */
+static void
+replorigin_xact_clear_state(void)
+{
+ replorigin_session_origin_lsn = InvalidXLogRecPtr;
+ replorigin_session_origin_timestamp = 0;
+}
+
/*
* IsReservedOriginName
@@ -1244,6 +1255,16 @@ replorigin_session_reset(void)
ConditionVariableBroadcast(cv);
}
+/*
+ * Clear per-session replication origin state.
+ */
+void
+replorigin_session_clear_state(void)
+{
+ replorigin_xact_clear_state();
+ replorigin_session_origin = InvalidRepOriginId;
+}
+
/*
* Do the same work replorigin_advance() does, just on the session's
* configured origin.
@@ -1412,9 +1433,7 @@ pg_replication_origin_session_reset(PG_FUNCTION_ARGS)
replorigin_session_reset();
- replorigin_session_origin = InvalidRepOriginId;
- replorigin_session_origin_lsn = InvalidXLogRecPtr;
- replorigin_session_origin_timestamp = 0;
+ replorigin_session_clear_state();
PG_RETURN_VOID();
}
@@ -1482,8 +1501,7 @@ pg_replication_origin_xact_reset(PG_FUNCTION_ARGS)
{
replorigin_check_prerequisites(true, false);
- replorigin_session_origin_lsn = InvalidXLogRecPtr;
- replorigin_session_origin_timestamp = 0;
+ replorigin_xact_clear_state();
PG_RETURN_VOID();
}
diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c
index 2522e372036..d5b6782bc1d 100644
--- a/src/backend/replication/logical/tablesync.c
+++ b/src/backend/replication/logical/tablesync.c
@@ -323,9 +323,7 @@ ProcessSyncingTablesForSync(XLogRecPtr current_lsn)
* This is needed to allow the origin to be dropped.
*/
replorigin_session_reset();
- replorigin_session_origin = InvalidRepOriginId;
- replorigin_session_origin_lsn = InvalidXLogRecPtr;
- replorigin_session_origin_timestamp = 0;
+ replorigin_session_clear_state();
/*
* Drop the tablesync's origin tracking if exists.
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c
index d1ee0261c64..c67be657737 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -5857,9 +5857,7 @@ InitializeLogRepWorker(void)
static void
replorigin_reset(int code, Datum arg)
{
- replorigin_session_origin = InvalidRepOriginId;
- replorigin_session_origin_lsn = InvalidXLogRecPtr;
- replorigin_session_origin_timestamp = 0;
+ replorigin_session_clear_state();
}
/*
diff --git a/src/include/replication/origin.h b/src/include/replication/origin.h
index 2a73f6aa492..325f12bfd57 100644
--- a/src/include/replication/origin.h
+++ b/src/include/replication/origin.h
@@ -65,6 +65,7 @@ extern void replorigin_session_advance(XLogRecPtr remote_commit,
XLogRecPtr local_commit);
extern void replorigin_session_setup(RepOriginId node, int acquired_by);
extern void replorigin_session_reset(void);
+extern void replorigin_session_clear_state(void);
extern XLogRecPtr replorigin_session_get_progress(bool flush);
/* Checkpoint/Startup integration */
--
2.39.5 (Apple Git-154)
view thread (9+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: Refactor replication origin state reset helpers
In-Reply-To: <CAEoWx2=pYvfRthXHTzSrOsf5_FfyY4zJyK4zV2v4W=yjUij1cA@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox