Re: [PATCH] Send catalog_xmin separately in hot standby feedback

From: Craig Ringer <craig(at)2ndquadrant(dot)com>
To: Petr Jelinek <petr(at)2ndquadrant(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Simon Riggs <simon(dot)riggs(at)2ndquadrant(dot)com>
Subject: Re: [PATCH] Send catalog_xmin separately in hot standby feedback
Date: 2016-11-11 05:48:36
Message-ID: CAMsr+YE-qNSh-BTBnOH=NvAL8HCvf5-+hpaAPqkgxjhVfUM=Xg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox
Thread:
Lists: pgsql-hackers

On 25 October 2016 at 00:19, Petr Jelinek <petr(at)2ndquadrant(dot)com> wrote:

>> Now formatted a series:
>>
>> 1. Send catalog_xmin in hot standby feedback protocol
>
>> + xmin_epoch = nextEpoch;
>> if (nextXid < xmin)
>> - nextEpoch--;
>> + xmin_epoch --;
>> + catalog_xmin_epoch = nextEpoch;
>> + if (nextXid < catalog_xmin)
>> + catalog_xmin_epoch --;
>
> Don't understand why you keep the nextEpoch here, it's not used anywhere
> that I can see, you could just as well use the xmin_epoch directly if
> that's how you want to name it.

Fixed, thanks.

>> + /*
>> + * A 10.0+ standby's walsender passes the lowest catalog xmin of any
>> + * replication slot up to the master.
>> + */
>> + feedbackCatalogXmin = pq_getmsgint(&reply_message, 4);
>> + feedbackCatalogEpoch = pq_getmsgint(&reply_message, 4);
>>
>
> I'd be more interested to know why this is sent rather than it's sent
> since version 10+ in this comment.

Removed. It's explained in a comment inside the if
(hot_standby_feedback) block in walreceiver anyway.

>> 2. Make walsender respect catalog_xmin in hot standby feedback messages
>
>> + if (TransactionIdIsNormal(feedbackCatalogXmin)
>> + && TransactionIdPrecedes(feedbackCatalogXmin, feedbackXmin))
>> + {
>> + MyPgXact->xmin = feedbackCatalogXmin;
>> + }
>> + else
>> + {
>> + MyPgXact->xmin = feedbackXmin;
>> + }
>
> This not how we usually use the {} brackets (there are some more
> instances of using them for one line of code in this particular commit).

Whoops. Thanks. I find the Pg convention pretty ghastly when dealing
with multi-line 'if' conditions followed by a single-line statement,
but it's still the convention whether I like it or not.

>> 3. Allow GetOldestXmin(...) to optionally disregard the catalog_xmin
>> By ignoring slot catalog_xmin in the GetOldestXmin() call then
>> separately calling ProcArrayGetReplicationSlotXmin() to get the
>> catalog_xmin to we might produce a catalog xmin slightly later than
>> what was in the procarray at the time we previously called
>> GetOldestXmin() to examine backend/session state. ProcArrayLock is
>> released so it can be advanced in-between the calls. That's harmless -
>> it isn't necessary for the reported catalog_xmin to be exactly
>> consistent with backend state. If it advances it's safe to report the
>> new position since we know the confirmed positions are on-disk
>> locally.
>>
>> The alternative here is to extend GetOldestXmin() to take an out-param
>> to report the slot catalog xmin. That really just duplicates the
>> functionality of ProcArrayGetReplicationSlotXmin but means we can grab
>> it within a single ProcArray lock. Variants of GetOldestXmin and
>> ProcArrayGetReplicationSlotXmin that take an already-locked flag would
>> work too, but would hold the lock across parts of GetOldestXmin() that
>> currently don't retain it. I could also convert the current boolean
>> param ignoreVacuum into a flags argument instead of adding another
>> boolean. No real preference from me.
>>
>
> I would honestly prefer the change to GetOldestXmin to return the
> catalog_xmin. It seems both cleaner and does less locking.

Fair enough. Done.

> In general it's simpler patch than I expected which is good. But it
> would be good to have some tests.

Agreed. OK, I've added basic tests for physical replication slots and
hot_standby_feedback to t/001_stream_rep.pl since it make sense to
test both along with stream_rep.pl's tests of cascading, etc and I
don't think a separate test is needed.

It's not actually practical to add tests for the catalog_xmin on
standby functionality until the next patch in the series (pending)
which enables logical decoding on standby. Currently you can't create
a slot on a standby so you can't cause the standby to hold down
catalog_xmin. But the tests show things work how they should within
the range of currently exposed functionality.

In the process I noticed how skeletal those tests still are. We have a
great framework now (thanks Michael!) and I'd like to start filling it
out with tests involving unclean shutdowns, promotions, etc. There's a
lot still to write to get solid coverage. Tests aren't hard. Who's
keen to write some? I'll happily help any volunteers out.

New patch series attached. 0001 is the new tests. The guts is patches
2-5. I'm not sure whether 2, 3, 4 and 5 should be squashed for commit
or not, but I left them separate for easier review.

For complete functionality this series will want to be coupled with
logical decoding timeline following and a pending patch to enable
logical decoding on standby.

--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachment Content-Type Size
0005-Send-catalog_xmin-separately-in-hot_standby_feedback.patch text/x-patch 2.0 KB
0004-Allow-GetOldestXmin-.-to-optionally-disregard-the-ca.patch text/x-patch 9.6 KB
0003-Make-walsender-respect-catalog_xmin-in-hot-standby-f.patch text/x-patch 7.4 KB
0002-Send-catalog_xmin-in-hot-standby-feedback-protocol.patch text/x-patch 5.6 KB
0001-Expand-streaming-replication-tests-to-cover-hot-stan.patch text/x-patch 6.9 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tsunakawa, Takayuki 2016-11-11 06:25:13 Re: Patch: Implement failover on libpq connect level.
Previous Message Ashutosh Sharma 2016-11-11 05:11:23 Re: Microvacuum support for Hash Index