Skip to content

Commit

Permalink
[#22929] YSQL: Fix Server's System Clock in XLogData in Logical Repli…
Browse files Browse the repository at this point in the history
…cation

Summary:
This diff imports the upstream PG commit `Fix timestamp of sent message for write context in logical decoding`-`5f6b1eb0cf4b0fb101478da51c294a63fd4726ef`

PG commit: postgres/postgres@5f6b1eb
PG commit description:
```
When sending data for logical decoding using the streaming replication
protocol via a WAL sender, the timestamp of the sent write message is
allocated at the beginning of the message when preparing for the write,
and actually computed when the write message is ready to be sent.

The timestamp was getting computed after sending the message.  This
impacts anything using logical decoding, causing for example logical
replication to report mostly NULL for last_msg_send_time in
pg_stat_subscription.

This commit makes sure that the timestamp is computed before sending the
message.

Discussion: https://postgr.es/m/CAMkU=1z=WMn8jt7iEdC5sYNaPgAgOASb_OW5JYv-vMdYaJSL-w@mail.gmail.com
```
Jira: DB-11846

Test Plan: Jenkins: test regex: .*ReplicationSlot.*

Reviewers: asrinivasan, stiwary, skumar

Reviewed By: asrinivasan

Subscribers: yql, ycdcxcluster

Differential Revision: https://phorge.dev.yugabyte.com/D36470
  • Loading branch information
michaelpq authored and Sumukh-Phalgaonkar committed Jul 10, 2024
1 parent 2a56a86 commit b0ee793
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/postgres/src/backend/replication/walsender.c
Original file line number Diff line number Diff line change
Expand Up @@ -1344,9 +1344,6 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
if (IsYugaByteEnabled())
yb_start_time = GetCurrentTimestamp();

/* output previously gathered data in a CopyData packet */
pq_putmessage_noblock('d', ctx->out->data, ctx->out->len);

/*
* Fill the send timestamp last, so that it is taken as late as possible.
* This is somewhat ugly, but the protocol is set as it's already used for
Expand All @@ -1358,6 +1355,9 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
memcpy(&ctx->out->data[1 + sizeof(int64) + sizeof(int64)],
tmpbuf.data, sizeof(int64));

/* output previously gathered data in a CopyData packet */
pq_putmessage_noblock('d', ctx->out->data, ctx->out->len);

CHECK_FOR_INTERRUPTS();

/* Try to flush pending output to the client */
Expand Down

0 comments on commit b0ee793

Please sign in to comment.