pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: Andres Freund <andres@anarazel.de>
Cc: Postgres hackers <pgsql-hackers@postgresql.org>
Subject: Re: pgsql: Avoid duplicate XIDs at recovery when building initial snapshot
Date: Mon, 22 Oct 2018 12:03:26 +0900
Message-ID: <20181022030326.GE14282@paquier.xyz> (raw)
In-Reply-To: <20181014174240.byktkskdymae7kmy@alap3.anarazel.de>
References: <E1gBgPY-0006hw-HN@gemulon.postgresql.org>
	<20181014174240.byktkskdymae7kmy@alap3.anarazel.de>

(moving to -hackers)

On Sun, Oct 14, 2018 at 10:42:40AM -0700, Andres Freund wrote:
> I'm unhappy this approach was taken over objections. Without a real
> warning.

Oops, that was not clear to me.  Sorry about that!  I did not see you
objecting again after the last arguments I raised.  The end of PREPARE
TRANSACTION is designed like that since it has been introduced, so
changing the way the dummy GXACT is inserted before the main one is
cleared from its XID does not sound wise to me.  The current design is
also present for a couple of reasons, please see this thread:
https://www.postgresql.org/message-id/13905.1119109281@sss.pgh.pa.us
This has resulted in e26b0abd.

Among the things I thought are:
- Clearing the XID at the same time the dummy entry is added, which
actually means to hold on ProcArrayLock longer while doing more at the
end of prepare.  I actually don't think you can do that cleanly without
endangering the transaction visibility for other backends, and syncrep
may cause the window to get wider.
- Changing GetRunningTransactionData so as duplicates are removed at
this stage.  However this also requires to hold ProcArrayLock for
longer.  For most deployments, if no dummy entries from 2PC transactions
are present it would be possible to bypass the checks to remove the
duplicated entries, but if at least one dummy entry is found it would be
necessary to scan again the whole ProcArray, which would be most likely
the case at each checkpoint with workloads like what Konstantin has
mentioned in the original report.  And ProcArrayLock is already a point
of contention for many OLTP workloads with small transactions.  So the
performance argument worries me.

Speaking of which, I have looked at the performance of qsort, and for a
couple of thousand entries, we may not see any impact.  But I am not
confident enough to say that it would be OK for all platforms each time
a standby snapshot is taken when ordering works on 4-bytes elements, so
the performance argument from Konstantin seems quite sensible to me (see
the quickly-hacked qsort_perf.c attached).

> Even leaving the crummyness aside, did you check other users of
> XLOG_RUNNING_XACTS, e.g. logical decoding? 

I actually spent some time checking that, so it is not innocent.
SnapBuildWaitSnapshot() waits for transactions to commit or abort based
on the XIDs in the record.  And that's the only place where those XIDs
are used so it won't matter to wait twice for the same transaction to
finish.  The error callback would be used only once.
--
Michael

Attachments:

qsort_perf.c (text/x-csrc, 811B) download /* * Measure performance of qsort: * qsort_perf number_elements */ #include <stdio.h> #include <time.h> #include <stdlib.h> #include <unistd.h> int int_compare(const void *arg1, const void *arg2) { int int1 = *(const int *) arg1; int int2 = *(const int *) arg2; if (int1 > int2) return 1; if (int1 < int2) return -1; return 0; } int main(int argc, char **argv) { int num_elts, i; int *elts; if (argc != 2) { fprintf(stderr, "Incorrect number of arguments\n"); exit(1); } num_elts = atoi(argv[1]); elts = (int *) malloc(num_elts * sizeof(int)); for (i = 0; i < num_elts; i++) elts[i] = random(); fprintf(stdout, "Beginning %u\n", (unsigned) time(NULL)); qsort(elts, num_elts, sizeof(int), int_compare); fprintf(stdout, "Finishing %u\n", (unsigned) time(NULL)); exit(0); }
signature.asc (application/pgp-signature, 832B) download

view thread (20+ messages)  latest in thread

Message-ID: <20181022030326.GE14282@paquier.xyz>
Permalink:  ../20181022030326.GE14282@paquier.xyz/
Also on:    postgresql.org/message-id/20181022030326.GE14282@paquier.xyz

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: michael@paquier.xyz, andres@anarazel.de, pgsql-hackers@postgresql.org
  Subject: Re: pgsql: Avoid duplicate XIDs at recovery when building initial snapshot
  In-Reply-To: <20181022030326.GE14282@paquier.xyz>
  References: <E1gBgPY-0006hw-HN@gemulon.postgresql.org> <20181014174240.byktkskdymae7kmy@alap3.anarazel.de> <20181022030326.GE14282@paquier.xyz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox