Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gEQVI-00045D-NA for pgsql-hackers@arkaria.postgresql.org; Mon, 22 Oct 2018 03:03:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gEQVG-0006PD-Qt for pgsql-hackers@arkaria.postgresql.org; Mon, 22 Oct 2018 03:03:38 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gEQVG-0006P6-Jh for pgsql-hackers@lists.postgresql.org; Mon, 22 Oct 2018 03:03:38 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gEQVB-0004nc-0C for pgsql-hackers@postgresql.org; Mon, 22 Oct 2018 03:03:38 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 58E6B217DD; Sun, 21 Oct 2018 23:03:31 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Sun, 21 Oct 2018 23:03:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=nAv5cM9Qc+UVnydFwoNC/DyKaQ7 7xssm0wIs6541k80=; b=H+4CLwRR4WeK7xXr3gvYEZbdQZLewpWGrZ6nwSRnS7V 1lngsGnCOI6kEyN7+BE1malV0NALATQB61g6Sf22RLsi7englf4XxFEBmeQJiO/x yuLZD/dqY5C10Y0oQE6uYDEjr176SYWqmdLd+2BGAKCbdrkrGtHwjywnShVmEhp9 Wi3oJJnzNSKpR1QrT/hkg3Ocgx2/1SulpcWzfwbqKtp134lLRbFJHQ3RksRsxxSJ hnNbeH3vAuvQ+Ye/+e/TnP42X5k0zBYaDRuaXHnIdbw+IoddACHF8h92f2woDNBP Xq9llEYD3VoNH4vXiBpQnDf43Cup06qZZZka0xW5/Tg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=nAv5cM 9Qc+UVnydFwoNC/DyKaQ77xssm0wIs6541k80=; b=srrSqUy4LHLdlsrphvUyuz 4tKVvTAWFaY/QdycVG8uiBFHR8ZjIGuxcm3MmPGkfCTWITXRW0rL4/delzfGGjLW M7Ee8kaqaDLUqL7b+gfT3UjBpZkcQ8bQag+x3uHK23T9bVs7d75PEPTYX3/A1/lA nrVIlHp7Ls0VCwEB3xE46lnxd/lupNKA9oyUedb814CXU9TK0XOIB8PIAEJatPJ0 Sx/deJzMjbfJatrSb+I1j/n9wroMC5vDSsjxTaeJ9ggSVNF7CenBNqjiz6X+fcid xajGsvGXFhadNT80JZh9SyGJfoc6Kp/QXwVyp25xFD7nswxkwQn16tDsi1w97J0A == X-ME-Sender: X-ME-Proxy: Received: from paquier.xyz (c137162.net61215.cablenet.ne.jp [61.215.137.162]) by mail.messagingengine.com (Postfix) with ESMTPA id 625E4102A0; Sun, 21 Oct 2018 23:03:29 -0400 (EDT) Date: Mon, 22 Oct 2018 12:03:26 +0900 From: Michael Paquier To: Andres Freund Cc: Postgres hackers Subject: Re: pgsql: Avoid duplicate XIDs at recovery when building initial snapshot Message-ID: <20181022030326.GE14282@paquier.xyz> References: <20181014174240.byktkskdymae7kmy@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="vJguvTgX93MxBIIe" Content-Disposition: inline In-Reply-To: <20181014174240.byktkskdymae7kmy@alap3.anarazel.de> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --vJguvTgX93MxBIIe Content-Type: multipart/mixed; boundary="vA66WO2vHvL/CRSR" Content-Disposition: inline --vA66WO2vHvL/CRSR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable (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?=20 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 --vA66WO2vHvL/CRSR Content-Type: text/x-csrc; charset=us-ascii Content-Disposition: attachment; filename="qsort_perf.c" /* * Measure performance of qsort: * qsort_perf number_elements */ #include #include #include #include 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); } --vA66WO2vHvL/CRSR-- --vJguvTgX93MxBIIe Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAlvNPf4ACgkQnvQgOdby QH1kvQ//cDHxA79THU+IOlDupPhlg1QA+LvHYe4GQNiAstsvH8ey7+3KKKkRrjaB B9foLQyYoIVXXHQxynvXnUMyXdoiSP5WPVen2AiCSILP29cJoezWoU0kaIQZkOYU wd82+R6HyPR8oLX8CVUHGA1cGfN+mnvw2KPWGxdoTMg0OMNfKPUD4Yp6+Oa4Y1+T dx+gLb9QzvzRfVw2+WXCgoG3WEN6WoV7SZ418sI2mVxLd6J4ME3HLLV9jAbyzUd6 VS8Zi7vB31wZd37TBo1iH/H7zQ0pxUfDRQZnFI5YF8fEHdUUuh4hc95aMAI6+Jwa RUl2fV3n9XK/OmDTXebeOk2ydOMjVf0Sn63H5cHAZBtx9TMxGuYxf5pCwWlI1aJz YYRTIhThRUateMDVz0IKzo6qioY1PH+j8rxQSdIgyEhSyeKKkcti+xXCfAS8wgu1 aWf1K+m3J2LhoAdr78mhv2KaflqUuoRNfljYVqMuA3BN5/dxtQyMayRqXN4JrQ7P tJYXzc0KQ9gHNhUiThg7MqJ5WrMH71eYOXNaxh6PHSndiTYZCFhZ/yWZgM0PzvRP CXcVd4kJG3evTwmxOx/FjOXzO8A4uqaa2UNsk+quw9Nv0gA7vJYiIVaFXeEOK8/Q FdLr0D9sjedbCn3KtkTfTjtmbROST2cKy0asKOABiEhSut3bzPE= =60xB -----END PGP SIGNATURE----- --vJguvTgX93MxBIIe--