Skip to content

Commit 5f88da5

Browse files
committed
Add comments explaining overflow entries in the replication lag tracker.
Commit 883a956 introduced overflow entries in the replication lag tracker to fix an issue where lag columns in pg_stat_replication could stall when the replay LSN stopped advancing. This commit adds comments clarifying the purpose and behavior of overflow entries to improve code readability and understanding. Since commit 883a956 was recently applied and backpatched to all supported branches, this follow-up commit is also backpatched accordingly. Author: Xuneng Zhou <xunengzhou@gmail.com> Reviewed-by: Fujii Masao <masao.fujii@gmail.com> Discussion: https://postgr.es/m/CABPTF7VxqQA_DePxyZ7Y8V+ErYyXkmwJ1P6NC+YC+cvxMipWKw@mail.gmail.com Backpatch-through: 13
1 parent 2bc01ef commit 5f88da5

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/backend/replication/walsender.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,19 @@ typedef struct
230230
int write_head;
231231
int read_heads[NUM_SYNC_REP_WAIT_MODE];
232232
WalTimeSample last_read[NUM_SYNC_REP_WAIT_MODE];
233+
234+
/*
235+
* Overflow entries for read heads that collide with the write head.
236+
*
237+
* When the cyclic buffer fills (write head is about to collide with a
238+
* read head), we save that read head's current sample here and mark it as
239+
* using overflow (read_heads[i] = -1). This allows the write head to
240+
* continue advancing while the overflowed mode continues lag computation
241+
* using the saved sample.
242+
*
243+
* Once the standby's reported LSN advances past the overflow entry's LSN,
244+
* we transition back to normal buffer-based tracking.
245+
*/
233246
WalTimeSample overflowed[NUM_SYNC_REP_WAIT_MODE];
234247
} LagTracker;
235248

0 commit comments

Comments
 (0)