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 1mETlJ-0000iB-MW for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Aug 2021 09:46:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mETlI-000560-Fp for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Aug 2021 09:46:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mETlI-00055s-1R for pgsql-hackers@lists.postgresql.org; Fri, 13 Aug 2021 09:46:00 +0000 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mETlF-00012a-63 for pgsql-hackers@lists.postgresql.org; Fri, 13 Aug 2021 09:45:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1628847957; x=1660383957; h=from:subject:cc:to:message-id:date:mime-version; bh=EjJTXvGUJ+HOWcbGxdiqy+7cSvmWA1KSwH41ZyrvBg8=; b=tsB69pAKC67FCDOR5E3rzOGQ8H7C1lcjfKFiciWQ+n6CtXsqo2p4BIFx oZPrVM7nrjpJ9DRghKhez77N333PP2o3DqtEULC9VZ5pv2HVKEIwJa9G4 WVk/TkF5Ov+qnmqtgL1MNEr6oXy/u0vLefUnmTjKLHw9qcDAywAuQlqq1 c=; X-Amazon-filename: v1-0001-ReorderBufferChangeMemoryUpdate-failed-assertion.patch X-IronPort-AV: E=Sophos;i="5.84,318,1620691200"; d="scan'208,217";a="141581986" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1e-c7f73527.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-33001.sea14.amazon.com with ESMTP; 13 Aug 2021 09:45:47 +0000 Received: from EX13D03EUC003.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1e-c7f73527.us-east-1.amazon.com (Postfix) with ESMTPS id 2FC76A621E; Fri, 13 Aug 2021 09:45:45 +0000 (UTC) Received: from 38f9d36c4abb.ant.amazon.com (10.43.161.69) by EX13D03EUC003.ant.amazon.com (10.43.164.192) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Fri, 13 Aug 2021 09:45:42 +0000 From: "Drouvot, Bertrand" Subject: [BUG] Failed Assertion in ReorderBufferChangeMemoryUpdate() CC: Amit Kapila , To: PostgreSQL Hackers Message-ID: <92b0ee65-b8bd-e42d-c082-4f3f4bf12d34@amazon.com> Date: Fri, 13 Aug 2021 11:45:37 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------1AF2C091E77C70C47BADFA94" Content-Language: en-US X-Originating-IP: [10.43.161.69] X-ClientProxiedBy: EX13D14UWB004.ant.amazon.com (10.43.161.137) To EX13D03EUC003.ant.amazon.com (10.43.164.192) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --------------1AF2C091E77C70C47BADFA94 Content-Type: multipart/alternative; boundary="------------CDC46AE52844C334A3A6E420" --------------CDC46AE52844C334A3A6E420 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit Hi hackers, While working on [1], it appears that (on master) the issue reproduction (of toast rewrite not resetting the toast_hash) is triggering a failed assertion: #2  0x0000000000b29fab in ExceptionalCondition (conditionName=0xce6850 "(rb->size >= sz) && (txn->size >= sz)", errorType=0xce5f84 "FailedAssertion", fileName=0xce5fd0 "reorderbuffer.c", lineNumber=3141) at assert.c:69 #3  0x00000000008ff1fb in ReorderBufferChangeMemoryUpdate (rb=0x11a7a40, change=0x11c94b8, addition=false) at reorderbuffer.c:3141 #4  0x00000000008fab27 in ReorderBufferReturnChange (rb=0x11a7a40, change=0x11c94b8, upd_mem=true) at reorderbuffer.c:477 #5  0x0000000000902ec1 in ReorderBufferToastReset (rb=0x11a7a40, txn=0x11b1998) at reorderbuffer.c:4799 #6  0x00000000008faaa2 in ReorderBufferReturnTXN (rb=0x11a7a40, txn=0x11b1998) at reorderbuffer.c:448 #7  0x00000000008fc95b in ReorderBufferCleanupTXN (rb=0x11a7a40, txn=0x11b1998) at reorderbuffer.c:1540 while on 12.5 for example, we would get (with the exact same repro): ERROR:  could not open relation with OID 0 The failed assertion is happening in the PG_CATCH() section of ReorderBufferProcessTXN(). We entered PG_CATCH() because elog(ERROR, "could not open relation with OID %u",...) has been triggered in ReorderBufferToastReplace(). But this elog(ERROR,) is being called after ReorderBufferChangeMemoryUpdate() being triggered with "addition" set to false. As a consequence of elog(ERROR,) then ReorderBufferChangeMemoryUpdate() with "addition" set to true is not called at the end of ReorderBufferToastReplace(). That leads to a subsequent call to ReorderBufferChangeMemoryUpdate() (being triggered by 4daa140a2f adding ReorderBufferToastReset() calls to ReorderBufferReturnTXN()) triggering the failed assertion. Please find attached a patch proposal to avoid the failed assertion (by ensuring that ReorderBufferChangeMemoryUpdate() being triggered with "addition" set to false in ReorderBufferToastReplace() is done after the elog(ERROR,)). Adding Amit and Dilip as they are also aware of [1] and have worked on 4daa140a2f. Also adding this patch in the commitfest. Thanks Bertrand [1]: https://www.postgresql.org/message-id/b5146fb1-ad9e-7d6e-f980-98ed68744a7c@amazon.com --------------CDC46AE52844C334A3A6E420 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: 8bit

Hi hackers,

While working on [1], it appears that (on master) the issue reproduction (of toast rewrite not resetting the toast_hash) is triggering a failed assertion:

#2  0x0000000000b29fab in ExceptionalCondition (conditionName=0xce6850
"(rb->size >= sz) && (txn->size >= sz)", errorType=0xce5f84
"FailedAssertion", fileName=0xce5fd0 "reorderbuffer.c", lineNumber=3141)
at assert.c:69
#3  0x00000000008ff1fb in ReorderBufferChangeMemoryUpdate (rb=0x11a7a40,
change=0x11c94b8, addition=false) at reorderbuffer.c:3141
#4  0x00000000008fab27 in ReorderBufferReturnChange (rb=0x11a7a40,
change=0x11c94b8, upd_mem=true) at reorderbuffer.c:477
#5  0x0000000000902ec1 in ReorderBufferToastReset (rb=0x11a7a40,
txn=0x11b1998) at reorderbuffer.c:4799
#6  0x00000000008faaa2 in ReorderBufferReturnTXN (rb=0x11a7a40,
txn=0x11b1998) at reorderbuffer.c:448
#7  0x00000000008fc95b in ReorderBufferCleanupTXN (rb=0x11a7a40,
txn=0x11b1998) at reorderbuffer.c:1540

while on 12.5 for example, we would get (with the exact same repro):

ERROR:  could not open relation with OID 0

The failed assertion is happening in the PG_CATCH() section of ReorderBufferProcessTXN().

We entered PG_CATCH() because elog(ERROR, "could not open relation with OID %u",...) has been triggered in ReorderBufferToastReplace().

But this elog(ERROR,) is being called after ReorderBufferChangeMemoryUpdate() being triggered with "addition" set to false.

As a consequence of elog(ERROR,) then ReorderBufferChangeMemoryUpdate() with "addition" set to true is not called at the end of ReorderBufferToastReplace().

That leads to a subsequent call to ReorderBufferChangeMemoryUpdate() (being triggered by 4daa140a2f adding ReorderBufferToastReset() calls to ReorderBufferReturnTXN()) triggering the failed assertion.


Please find attached a patch proposal to avoid the failed assertion (by ensuring that ReorderBufferChangeMemoryUpdate() being triggered with "addition" set to false in ReorderBufferToastReplace() is done after the elog(ERROR,)).

Adding Amit and Dilip as they are also aware of [1] and have worked on 4daa140a2f.

Also adding this patch in the commitfest.

Thanks

Bertrand

[1]: https://www.postgresql.org/message-id/b5146fb1-ad9e-7d6e-f980-98ed68744a7c@amazon.com

--------------CDC46AE52844C334A3A6E420-- --------------1AF2C091E77C70C47BADFA94 Content-Type: text/plain; charset="UTF-8"; x-mac-type=0; x-mac-creator=0; name="v1-0001-ReorderBufferChangeMemoryUpdate-failed-assertion.patch" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename*0="v1-0001-ReorderBufferChangeMemoryUpdate-failed-assertion.pat"; filename*1="ch" ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL3JlcGxpY2F0aW9uL2xvZ2ljYWwvcmVvcmRlcmJ1 ZmZlci5jIGIvc3JjL2JhY2tlbmQvcmVwbGljYXRpb24vbG9naWNhbC9yZW9yZGVyYnVmZmVy LmMKaW5kZXggNzM3OGJlYjY4NC4uMjczMzJhNGNmZCAxMDA2NDQKLS0tIGEvc3JjL2JhY2tl bmQvcmVwbGljYXRpb24vbG9naWNhbC9yZW9yZGVyYnVmZmVyLmMKKysrIGIvc3JjL2JhY2tl bmQvcmVwbGljYXRpb24vbG9naWNhbC9yZW9yZGVyYnVmZmVyLmMKQEAgLTQ2MTAsNiArNDYx MCwxMSBAQCBSZW9yZGVyQnVmZmVyVG9hc3RSZXBsYWNlKFJlb3JkZXJCdWZmZXIgKnJiLCBS ZW9yZGVyQnVmZmVyVFhOICp0eG4sCiAJaWYgKHR4bi0+dG9hc3RfaGFzaCA9PSBOVUxMKQog CQlyZXR1cm47CiAKKwl0b2FzdF9yZWwgPSBSZWxhdGlvbklkR2V0UmVsYXRpb24ocmVsYXRp b24tPnJkX3JlbC0+cmVsdG9hc3RyZWxpZCk7CisJaWYgKCFSZWxhdGlvbklzVmFsaWQodG9h c3RfcmVsKSkKKwkJZWxvZyhFUlJPUiwgImNvdWxkIG5vdCBvcGVuIHJlbGF0aW9uIHdpdGgg T0lEICV1IiwKKwkJCSByZWxhdGlvbi0+cmRfcmVsLT5yZWx0b2FzdHJlbGlkKTsKKwogCS8q CiAJICogV2UncmUgZ29pbmcgdG8gbW9kaWZ5IHRoZSBzaXplIG9mIHRoZSBjaGFuZ2UsIHNv IHRvIG1ha2Ugc3VyZSB0aGUKIAkgKiBhY2NvdW50a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