public inbox for [email protected]
help / color / mirror / Atom feedFrom: shveta malik <[email protected]>
To: Zhijie Hou (Fujitsu) <[email protected]>
Cc: Amit Kapila <[email protected]>
Cc: Ajin Cherian <[email protected]>
Cc: Hayato Kuroda (Fujitsu) <[email protected]>
Cc: Ashutosh Sharma <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Cc: shveta malik <[email protected]>
Subject: Re: [PATCH] Support automatic sequence replication
Date: Fri, 6 Mar 2026 10:55:02 +0530
Message-ID: <CAJpy0uC0T_tp62zxJN_2d_A=Ypvf14ebjGFepckeJugW5OHOyA@mail.gmail.com> (raw)
In-Reply-To: <TY4PR01MB169072DEE7CC20E9B06F0164C947DA@TY4PR01MB16907.jpnprd01.prod.outlook.com>
References: <CAFPTHDZXX9WQ_X1ZfEvS248T+pKuk6SmCnXcvgPM059N1xPUfA@mail.gmail.com>
<CAJpy0uDLUEjHHME8om1vAf6qkXCeRR6cBvkpK8yWBAC=T0ZFLA@mail.gmail.com>
<CAFPTHDZg1JrunGgOj332hr+gUuH_Jm7skqPpYSvd-QE3yEdRDQ@mail.gmail.com>
<CAJpy0uBz7MCSUkvFJD9ij65vBahNmY+bfCgdGKRqXovYs+K_TA@mail.gmail.com>
<CAJpy0uDsuNqjWd-TmGBxqSS1rnVCJ3B8=SYrtxQ=Vs8kb71QFA@mail.gmail.com>
<CAJpy0uAMWg3KcXtVBS7B0rnchLNrCCVYBByJCzAp=u5LERgtfA@mail.gmail.com>
<CAFPTHDZwEhxhDAeqcPi0GuYN6xBs8gFXHOMUnbg3u2Xigcz4Zg@mail.gmail.com>
<CAE9k0PmTyCU1A9YEf+MRgfeZ8yK1bAYJu=o0bH8DNUTzXejQyQ@mail.gmail.com>
<CAA4eK1L6czEzG4mLNZSyjYC5nX0FMSjjk3csKuxPD3Ph5-7Yvw@mail.gmail.com>
<CAJpy0uAhGQJ=msVsn2GsqWXr+YESJK6x9NBvrUtKvtvp1OVuKQ@mail.gmail.com>
<CAJpy0uAOuu-M6wobH2wHOdTymm-cX9+MqwPyRNoOt=sPKBdCew@mail.gmail.com>
<CAFPTHDZiWYXoKoo4VcBYNH9a=gxDZhfkcBeXt5w6cLw4_ysyKw@mail.gmail.com>
<OS9PR01MB12149D9054CC7F2DC3F0D26A1F577A@OS9PR01MB12149.jpnprd01.prod.outlook.com>
<CAA4eK1KYxQALt46k5uWOO6SUtNjvjOaXwfNjH0AU656YrcGZEw@mail.gmail.com>
<CAFPTHDZYonM+SXG19VVjgWduXQJSuDhcOUWq0NCiiuQubCSt6g@mail.gmail.com>
<CAFPTHDYud1zr0VyizhyhEQXfHMgXVcHrPzE56WUKGCFNskQq2A@mail.gmail.com>
<CAA4eK1JTau3fV7br6xwAV+LXXwM65RuGCuM2J3PQpCONtL1KXA@mail.gmail.com>
<OS9PR01MB1691377CDB1468CDC9820BBEB9470A@OS9PR01MB16913.jpnprd01.prod.outlook.com>
<TY4PR01MB1690715895CDE6FEFA13C2A2C947EA@TY4PR01MB16907.jpnprd01.prod.outlook.com>
<CAJpy0uA1txsV5RhjZjLBDrUjvxVyBDtMXzHr6=DzLHf7ybBrqg@mail.gmail.com>
<TY4PR01MB1690739DE978BCBD12358478E947DA@TY4PR01MB16907.jpnprd01.prod.outlook.com>
<CAJpy0uAfu-VPqCknLLvJ+PUx_cyoR-b70xUNT6Pyv8N-odKizQ@mail.gmail.com>
<CAJpy0uBeAdz6-3P26Eryeq3TyjA-GiKY3z0hFMxzZD=AYGqQ3Q@mail.gmail.com>
<TY4PR01MB169072DEE7CC20E9B06F0164C947DA@TY4PR01MB16907.jpnprd01.prod.outlook.com>
On Thu, Mar 5, 2026 at 5:04 PM Zhijie Hou (Fujitsu)
<[email protected]> wrote:
>
>
> Thanks for catching this, I changed it to check the increment before reporting warning.
>
Thanks! I have changed comments atop sequencesync.c to get rid of old
implementation details (worker dependency upon INIT state) and
rephrased a little bit. Please take it if you find it okay. Attaching
patch as txt file. It is a top-up for 0001.
thanks
Shveta
From 22a575bc2ab43795c72f2240485c189262672035 Mon Sep 17 00:00:00 2001
From: Shveta Malik <[email protected]>
Date: Fri, 6 Mar 2026 10:45:01 +0530
Subject: [PATCH] header comment improvement
---
.../replication/logical/sequencesync.c | 49 +++++++++----------
1 file changed, 22 insertions(+), 27 deletions(-)
diff --git a/src/backend/replication/logical/sequencesync.c b/src/backend/replication/logical/sequencesync.c
index cde9eaba474..a80d5e5b335 100644
--- a/src/backend/replication/logical/sequencesync.c
+++ b/src/backend/replication/logical/sequencesync.c
@@ -19,37 +19,32 @@
* CREATE SUBSCRIPTION
* ALTER SUBSCRIPTION ... REFRESH PUBLICATION
*
- * The apply worker periodically scans pg_subscription_rel for sequences in
- * INIT state. When such sequences are found, it spawns a sequencesync worker
- * to handle synchronization.
- *
- * A single sequencesync worker is responsible for synchronizing all sequences.
- * It begins by retrieving the list of sequences that are flagged for
- * synchronization, i.e., those in the INIT state. These sequences are then
- * processed in batches, allowing multiple entries to be synchronized within a
- * single transaction. The worker fetches the current sequence values and page
- * LSNs from the remote publisher, updates the corresponding sequences on the
- * local subscriber, and finally marks each sequence as READY upon successful
+ * The apply worker periodically scans pg_subscription_rel for sequences
+ * When sequences are found, it spawns a sequencesync worker to handle
* synchronization.
*
- * The sequencesync worker then fetches all sequences that are
- * in the READY state, queries the publisher for current sequence values, and
- * updates any sequences that have drifted and then goes to sleep. The sleep
- * interval starts as SEQSYNC_MIN_SLEEP_MS and doubles after each wake cycle
- * (up to SEQSYNC_MAX_SLEEP_MS). When drift is detected, the interval resets to
- * the minimum to ensure timely updates.
- *
- * After CREATE SUBSCRIPTION, sequences begin in the INIT state. Sequences
- * added through ALTER SUBSCRIPTION.. REFRESH PUBLICATION also start in the INIT
- * state. All INIT sequences are synchronized unconditionally, then transition
- * to the READY state. Once in the READY state, sequences are checked for drift
- * from the publisher and synchronized only when drift is detected.
+ * A single sequencesync worker is responsible for synchronizing all sequences
+ * for a subscription. It begins by retrieving the list of sequences. These
+ * sequences are then processed in batches, allowing multiple entries to be
+ * synchronized within a single transaction. The worker fetches the current
+ * sequence values and page LSNs from the remote publisher and updates the
+ * corresponding sequences on the local subscriber. Sequences in the INIT
+ * state are unconditionally updated to the latest values from the publisher
+ * and then moved to the READY state. For sequences already in the READY
+ * state, the worker checks for drift and updates them only when needed.
*
* Sequence state transitions follow this pattern:
- * INIT --> READY ->-+
- * ^ | (check/synchronize)
- * | |
- * +--<---+
+
+ * (synchronize)
+ * INIT --------------> READY ->-+
+ * ^ | (check-drift/synchronize)
+ * | |
+ * +--<---+
+ *
+ * Between cycles, the worker sleeps for SEQSYNC_MIN_SLEEP_MS. If no drift is
+ * observed in any sequence, the sleep interval doubles after each wake cycle
+ * up to SEQSYNC_MAX_SLEEP_MS. When drift is detected, the interval resets to
+ * the minimum to ensure timely updates.
*
* To avoid creating too many transactions, up to MAX_SEQUENCES_SYNC_PER_BATCH
* sequences are synchronized per transaction. The locks on the sequence
--
2.34.1
Attachments:
[text/plain] 0001-header-comment-improvement.patch.txt (3.8K, 2-0001-header-comment-improvement.patch.txt)
download | inline diff:
From 22a575bc2ab43795c72f2240485c189262672035 Mon Sep 17 00:00:00 2001
From: Shveta Malik <[email protected]>
Date: Fri, 6 Mar 2026 10:45:01 +0530
Subject: [PATCH] header comment improvement
---
.../replication/logical/sequencesync.c | 49 +++++++++----------
1 file changed, 22 insertions(+), 27 deletions(-)
diff --git a/src/backend/replication/logical/sequencesync.c b/src/backend/replication/logical/sequencesync.c
index cde9eaba474..a80d5e5b335 100644
--- a/src/backend/replication/logical/sequencesync.c
+++ b/src/backend/replication/logical/sequencesync.c
@@ -19,37 +19,32 @@
* CREATE SUBSCRIPTION
* ALTER SUBSCRIPTION ... REFRESH PUBLICATION
*
- * The apply worker periodically scans pg_subscription_rel for sequences in
- * INIT state. When such sequences are found, it spawns a sequencesync worker
- * to handle synchronization.
- *
- * A single sequencesync worker is responsible for synchronizing all sequences.
- * It begins by retrieving the list of sequences that are flagged for
- * synchronization, i.e., those in the INIT state. These sequences are then
- * processed in batches, allowing multiple entries to be synchronized within a
- * single transaction. The worker fetches the current sequence values and page
- * LSNs from the remote publisher, updates the corresponding sequences on the
- * local subscriber, and finally marks each sequence as READY upon successful
+ * The apply worker periodically scans pg_subscription_rel for sequences
+ * When sequences are found, it spawns a sequencesync worker to handle
* synchronization.
*
- * The sequencesync worker then fetches all sequences that are
- * in the READY state, queries the publisher for current sequence values, and
- * updates any sequences that have drifted and then goes to sleep. The sleep
- * interval starts as SEQSYNC_MIN_SLEEP_MS and doubles after each wake cycle
- * (up to SEQSYNC_MAX_SLEEP_MS). When drift is detected, the interval resets to
- * the minimum to ensure timely updates.
- *
- * After CREATE SUBSCRIPTION, sequences begin in the INIT state. Sequences
- * added through ALTER SUBSCRIPTION.. REFRESH PUBLICATION also start in the INIT
- * state. All INIT sequences are synchronized unconditionally, then transition
- * to the READY state. Once in the READY state, sequences are checked for drift
- * from the publisher and synchronized only when drift is detected.
+ * A single sequencesync worker is responsible for synchronizing all sequences
+ * for a subscription. It begins by retrieving the list of sequences. These
+ * sequences are then processed in batches, allowing multiple entries to be
+ * synchronized within a single transaction. The worker fetches the current
+ * sequence values and page LSNs from the remote publisher and updates the
+ * corresponding sequences on the local subscriber. Sequences in the INIT
+ * state are unconditionally updated to the latest values from the publisher
+ * and then moved to the READY state. For sequences already in the READY
+ * state, the worker checks for drift and updates them only when needed.
*
* Sequence state transitions follow this pattern:
- * INIT --> READY ->-+
- * ^ | (check/synchronize)
- * | |
- * +--<---+
+
+ * (synchronize)
+ * INIT --------------> READY ->-+
+ * ^ | (check-drift/synchronize)
+ * | |
+ * +--<---+
+ *
+ * Between cycles, the worker sleeps for SEQSYNC_MIN_SLEEP_MS. If no drift is
+ * observed in any sequence, the sleep interval doubles after each wake cycle
+ * up to SEQSYNC_MAX_SLEEP_MS. When drift is detected, the interval resets to
+ * the minimum to ensure timely updates.
*
* To avoid creating too many transactions, up to MAX_SEQUENCES_SYNC_PER_BATCH
* sequences are synchronized per transaction. The locks on the sequence
--
2.34.1
view thread (58+ 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], [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Re: [PATCH] Support automatic sequence replication
In-Reply-To: <CAJpy0uC0T_tp62zxJN_2d_A=Ypvf14ebjGFepckeJugW5OHOyA@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