From: | Heikki Linnakangas <hlinnakangas(at)vmware(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andres Freund <andres(at)2ndquadrant(dot)com> |
Cc: | <s(dot)zuban(at)gmail(dot)com>, <pgsql-bugs(at)postgresql(dot)org> |
Subject: | Re: BUG #11032: Prepared transactions do not update pg_last_xact_replay_timestamp() anymore |
Date: | 2014-07-28 10:05:13 |
Message-ID: | 53D62059.6060304@vmware.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
On 07/25/2014 01:50 AM, Tom Lane wrote:
> Andres Freund <andres(at)2ndquadrant(dot)com> writes:
>> Afaics before the commit a LockGXact() did a GetTopTransactionId(),
>> afterwards it doesn't anymore. That'd fit, right?
>
> Ah, I think you've got it.
Yep. The extra commit record masked the issue that getRecordTimestamp()
ignores commit/abort prepared records.
> Now I'm worried. I have a very vague
> recollection that that behavior (forcing our own COMMIT to be written
> after a COMMIT PREPARED) was intentional. I don't recall exactly
> why though.
Hmm. I've always considered it just a quirk that we didn't bother to fix
when two-phase commit was implemented, because it would've required more
invasive code changes. But the code has since moved on - not all
transactions are assigned an XID anymore - and now it was
straightforward to fix that quirk.
It wouldn't surprise me much though, if we find more little things like
this that were previously masked by the extra commit record:
At a quick glance, the recovery_min_apply_delay code in xlog.c seems to
be oblivious of prepared transactions. Now that we no longer write the
normal COMMIT record after a COMMIT_PREPARED record, that's become
worse, but it was always wrong. The COMMIT_PREPARED record would always
be applied immediately, regardless of recovery_min_apply_delay, although
we would then pause at the commit record that follows. The
recovery_target_xid handling also ignores prepared transactions.
> xact.h points out
>
> /*
> * COMMIT_PREPARED and ABORT_PREPARED are identical to COMMIT/ABORT records
> * except that we have to store the XID of the prepared transaction explicitly
> * --- the XID in the record header will be for the transaction doing the
> * COMMIT PREPARED or ABORT PREPARED command.
> */
>
> and what this change means is that there isn't actually any valid XID in
> the record header, which at least means that comment needs an update.
> But I'm concerned about the knock-on aspects of that. In particular
> I wonder if we were expecting commit of the surrounding transaction to
> result in a WAL flush or anything like that. The proposal you made
> recently to not sync non-XID-assigning WAL records would affect this.
RecordTransactionCommitPrepared calls XLogFlush() and
SyncRepWaitForLSN(), so those particular things are covered.
We probably should set XLogRecord->xl_xid in COMMIT_/ABORT_PREPARED
records though. It seems weird not to, and it would simplify code that
interprets those records. But I don't think we should back-patch that.
> As far as the timestamp aspects go, I wonder if we were thinking that
> commit/abort prepared might contain stale timestamps by design. They
> don't --- in the current coding, the timestamp is the time of creating the
> WAL record, not of the prepare --- but it's not that hard to imagine that
> time-of-prepare might have been the original intent.
Time-of-commit makes much more sense to me. The transaction doesn't
appear as committed to other transactions until it's committed,
regardless of when it prepared.
It surprises me that there is no timestamp at all in the prepare-record
though. That could be very useful information, if you wanted to monitor
the delay between prepare and commit, for example. But that's another issue.
I propose the attached (untested) patch that fixes the issues mentioned
this far. I'll set up streaming replication and test
recovery_target_xid, recovery_min_apply_delay, and
pg_last_xact_replay_timestamp() with the patch, and barring
objections/bugs, commit and backpatch. For master branch, I'll
investigate how hacky it would be to set XLogRecord->xl_xid to the XID
of the prepared transaction.
- Heikki
Attachment | Content-Type | Size |
---|---|---|
fix-commit-abort-prepared-oversights-1.patch | text/x-diff | 5.5 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Andres Freund | 2014-07-28 14:17:57 | Re: BUG #11032: Prepared transactions do not update pg_last_xact_replay_timestamp() anymore |
Previous Message | Rainer Tammer | 2014-07-28 05:58:33 | Re: Fwd: Re: Compile fails on AIX 6.1 |