Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m3FNE-0008FV-Je for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Jul 2021 10:10:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m3FNC-0007e3-I9 for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Jul 2021 10:10:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m3FNC-0007dQ-6i for pgsql-hackers@lists.postgresql.org; Tue, 13 Jul 2021 10:10:42 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m3FN5-0004tC-E3 for pgsql-hackers@postgresql.org; Tue, 13 Jul 2021 10:10:41 +0000 Received: from mail.postgrespro.ru (cyclops.postgrespro.ru [93.174.131.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id E104521C8DD9; Tue, 13 Jul 2021 13:10:34 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1626171034; bh=1dIaL9Ra7E99Ni9Vc+G375lucmamah6w64VLdAD5DDg=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=KDGermyeViSXcsmVEBJ5pDtXTgXFCJjP85jjHQlvRBPmyjmtTal4Cw6gFTjgN+Izb dW+jP52iW6x29oHWqTJf5O21IoBJ8yHWyECc8eyOp5E8QWKEAivCsO5H6Z4ncP/GD3 zxGfTpsSr2VIoIs5wUpri/JC2LwvXf5K3ZVGLkpo= MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=_1e8aae32afca14b52ae0cb0d28524359" Content-Transfer-Encoding: 7bit Date: Tue, 13 Jul 2021 13:10:34 +0300 From: Maxim Orlov To: Tomas Vondra Cc: Pavel Borisov , Greg Nancarrow , Robert Haas , Michael Paquier , Pengchengliu , Andres Freund , PostgreSQL-development Subject: Re: Parallel scan with SubTransGetTopmostTransaction assert coredump In-Reply-To: <5d730e4e-4fb2-bd5c-f6be-488ad692ed3a@enterprisedb.com> References: <000901d74b84$fa262890$ee7279b0$@tju.edu.cn> <000801d74d16$150494c0$3f0dbe40$@tju.edu.cn> <09788181118f7bd8000d3bb097e0720f@postgrespro.ru> <08ae178b309c617a9701cbc7ed8a98f0@postgrespro.ru> <5d730e4e-4fb2-bd5c-f6be-488ad692ed3a@enterprisedb.com> User-Agent: Roundcube Webmail/1.4.0 Message-ID: <150825360832da68872abb4d891dfc3a@postgrespro.ru> X-Sender: m.orlov@postgrespro.ru List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --=_1e8aae32afca14b52ae0cb0d28524359 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed On 2021-07-09 20:36, Tomas Vondra wrote: > Hi, > > I took a quick look on this - I'm no expert in the details of > snapshots, > so take my comments with a grain of salt. > > AFAICS both Greg Nancarrow and Pavel Borisov are kinda right. I think > Greg is right the v3 patch does not seem like the right (or correct) > solution, for a couple reasons: > > > 1) It fixes the symptoms, not the cause. If we set TransactionXmin to a > bogus value, this only fixes it locally in > SubTransGetTopmostTransaction > but I'd be surprised if other places did not have the same issue. > > > 2) The xid/TransactionXmin comparison in the v2 fix: > > xid = xid > TransactionXmin ? xid : TransactionXmin; > > seems broken, because it compares the XIDs directly, but that's not > going to work after generating enough transactions. > > > 3) But even if this uses TransactionIdFollowsOrEquals, it seems very > strange because the "xid" comes from > > XidInMVCCSnapshot(HeapTupleHeaderGetRawXmin(tuple), snapshot)) > > i.e. it's the raw xmin from the tuple, so why should we be setting it > to > TransactionXmin? That seems pretty strange, TBH. > > > So yeah, I think this is due to confusion with two snapshots and > failing > to consider both of them when calculating TransactionXmin. > > But I think removing one of the snapshots (as the v2 does it) is rather > strange too. I very much doubt having both the transaction and active > snapshots in the parallel worker is not intentional, and Pavel may very > well be right this breaks isolation levels that use the xact snapshot > (i.e. REPEATABLE READ and SERIALIZABLE). I haven't checked, though. > > So I think we need to keep both snapshots, but fix TransactionXmin to > consider both of them - I suppose ParallelWorkerMain could simply look > at the two snapshots, and use the minimum. Which is what [1] (already > linked by Pavel) talks about, although that's related to concerns about > one of the processes dying, which is not what's happening here. > > > I'm wondering what consequences this may have on production systems, > though. We've only seen this failing because of the assert, so what > happens when the build has asserts disabled? > > Looking at SubTransGetTopmostTransaction, it seems the while loop ends > immediately (because it's pretty much the opposite of the assert), so > we > just return the "xid" as topmost XID. But will that produce incorrect > query results, or what? > > > > regards > > > [1] > https://www.postgresql.org/message-id/20150208002027.GH9201%40alap3.anarazel.de PFA v4 patch based on the ideas above. In principle I see little difference with v3. But I agree it is more correct. I did test this patch on Linux and MacOS using testing algo above and got no error. On master branch before the patch I still see this error. --- Best regards, Maxim Orlov. --=_1e8aae32afca14b52ae0cb0d28524359 Content-Transfer-Encoding: base64 Content-Type: text/x-diff; name=v4-0001-PG14-Fix-parallel-worker-failed-assertion-and-coredump.patch Content-Disposition: attachment; filename*0*=UTF-8''v4-0001-PG14-Fix-parallel-worker-failed-assertion-and-; filename*1*=coredump.patch; size=1587 ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL2FjY2Vzcy90cmFuc2FtL3BhcmFsbGVsLmMgYi9zcmMv YmFja2VuZC9hY2Nlc3MvdHJhbnNhbS9wYXJhbGxlbC5jCmluZGV4IDM1NTBlZjEzYmFhLi42NDQz ZDQ5MjUwMSAxMDA2NDQKLS0tIGEvc3JjL2JhY2tlbmQvYWNjZXNzL3RyYW5zYW0vcGFyYWxsZWwu YworKysgYi9zcmMvYmFja2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