Question about WalSndWriteData - Mailing list pgsql-hackers

From Konstantin Knizhnik
Subject Question about WalSndWriteData
Date
Msg-id ce2bc24e-9fe4-28ad-6f9e-f8bf842a96af@postgrespro.ru
Whole thread Raw
Responses Re: Question about WalSndWriteData  (Peter Eisentraut <peter.eisentraut@2ndquadrant.com>)
List pgsql-hackers
Hi hackes,

I confused by the following code in WalSndWriteData:

     /* 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
      * several releases by streaming physical replication.
      */
     resetStringInfo(&tmpbuf);
     now = GetCurrentTimestamp();
     pq_sendint64(&tmpbuf, now);
     memcpy(&ctx->out->data[1 + sizeof(int64) + sizeof(int64)],
            tmpbuf.data, sizeof(int64));


pq_putmessage_noblock copies data from ctx->out buffer to libpq buffers.
After it we write timestamp to ctx->out buffer.
And comments says that we should do it "as late as possible".
But this timestamp is not included in the copy data packet which is 
already copied to libpq connection buffer.
And next WalSndPrepareWrite call will reset ctx->out buffer.

So I wonder what is the reason of writing timestamp in ctx->out buffer 
after processing it by pq_putmessage_noblock?

-- 
Konstantin Knizhnik
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company



pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: SSL passphrase prompt external command
Next
From: Peter Eisentraut
Date:
Subject: Re: fixing more format truncation issues