Fix logical decoding sendtime update

Started by Shulgin, Oleksandrover 10 years ago2 messages
#1Shulgin, Oleksandr
oleksandr.shulgin@zalando.de
1 attachment(s)

Hi Hackers,

it turns out, that the code in WalSndWriteData is setting the timestamp of
the replication message just *after* it has been sent out to the client,
thus the sendtime field always reads as zero.

Attached is a trivial patch to fix this. The physical replication path
already does the correct thing apparently.

Cheers!
--
Alex

Attachments:

logical-decoding-sendtime-fix.difftext/plain; charset=US-ASCII; name=logical-decoding-sendtime-fix.diffDownload
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
new file mode 100644
index eb1b89b..c9444ca
*** a/src/backend/replication/walsender.c
--- b/src/backend/replication/walsender.c
*************** static void
*** 1048,1056 ****
  WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
  				bool last_write)
  {
- 	/* 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's set as it's already used for
--- 1048,1053 ----
*************** WalSndWriteData(LogicalDecodingContext *
*** 1061,1066 ****
--- 1058,1066 ----
  	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);
+ 
  	/* fast path */
  	/* Try to flush pending output to the client */
  	if (pq_flush_if_writable() != 0)
#2Andres Freund
andres@anarazel.de
In reply to: Shulgin, Oleksandr (#1)
Re: Fix logical decoding sendtime update

On 2015-06-10 17:57:42 +0200, Shulgin, Oleksandr wrote:

it turns out, that the code in WalSndWriteData is setting the timestamp of
the replication message just *after* it has been sent out to the client,
thus the sendtime field always reads as zero.

Ugh, what a stupid bug. Thanks!

Andres

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers