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 1oUtci-0004zY-Gc for pgsql-hackers@arkaria.postgresql.org; Sun, 04 Sep 2022 17:41:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oUtbh-0004Yp-K0 for pgsql-hackers@arkaria.postgresql.org; Sun, 04 Sep 2022 17:40:29 +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 1oUtbg-0004Yd-R9 for pgsql-hackers@lists.postgresql.org; Sun, 04 Sep 2022 17:40:29 +0000 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oUtbZ-0003ea-Pq for pgsql-hackers@postgresql.org; Sun, 04 Sep 2022 17:40:27 +0000 Received: by mail-wm1-x333.google.com with SMTP id az24-20020a05600c601800b003a842e4983cso4535734wmb.0 for ; Sun, 04 Sep 2022 10:40:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=in-reply-to:references:cc:to:from:content-language:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date; bh=78OhPTt7ZmFBKSdtxlJ22xnH3GA5E0Cx4ZvQepwpyGw=; b=KgQ/aSPsYSl5H+RJamQOtmvglwK69FRzrTNeQH7OjGAjGA+n3AWMHFJONBZ0JOlggJ 8/xylVY4FzvvZMCil3ihbM4rMXTwkEKL61QA08XaKzaWr9vv2RbBRmwhcxCraRFgNEtH 7Lqb+Kd8qi+42/lz14zbBkSz1kcOiu00eLSflPDJW4jynhqZa3WPrbqliZR5Xl2aEoRx MVBVSPhfBzKeTJ6N8CZK4b34PE2SEIsnnFhFMPIIG6EGbAGXmumKnKWfYxQbR6xhUJpG bhsbHa/ZxLUEi7eNK0zWzmNZawEhN1tCE4Ic4fottx1H2RVo6OeI20shcqE7gqbGT+Vs 7+2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:references:cc:to:from:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date; bh=78OhPTt7ZmFBKSdtxlJ22xnH3GA5E0Cx4ZvQepwpyGw=; b=y4wK7HG/pDMln3rQw31EedBhP0ltOXLbcPD3v6RlHL/ey42RcHwQCPyFlC7OLxOlpJ 0YFaTDYvdZr0gv+U5gGaAm9yEB7uIebVmxEk+Qejkzta1mK8Hm1zA+pSwdxkkfZtBumS JelBSVIHhS6p2+jG2yodfEjzMdaNCgpOk6viD2NmYxsPTnwGC/5gQa5i1WT66PISND1+ yp2ioiTtE6l3jHX2CvXKTIsRt0KWkq0nGKdKq2MkT28ORezyI6bnD8aNaw2JAUml74eZ Gu4OIUZuD8bJ+owZCtQM2hCUopD5Vi/KXNZ5Nh2QzLcTIU+oIBkcajysZ5/7NmQBsn4R VhSg== X-Gm-Message-State: ACgBeo0UoAjjQe4MlLxc8Eoen2nk/Sa12sFhCBi85D/xZ712Ywoz/pTf cVylGJkSUKf43TQc0W83FA4jSw+sTTQIHfAm74gSddxtX0jvHjungorJo2OJPvoc+7V2KENgLA2 nhXttVFUvmlXXkrWINgX2t+SzQdowKA0leQt6uq1lV0Ifxv0a+pIcNPjoJlCyR2Cjh2a9o71KJ3 IZkMxgnLoUlidwAXjPBhC9A8uA63rfGBm3TO0p X-Google-Smtp-Source: AA6agR5I4bahoAEeWsjLkC6vkuRG17T7hTFdOnSerJxcUETr2ZrzIGJkg6C/OAYNkXo1z/BsKuWFSg== X-Received: by 2002:a7b:c5c3:0:b0:3a6:14f3:8ea7 with SMTP id n3-20020a7bc5c3000000b003a614f38ea7mr8521040wmk.76.1662313219428; Sun, 04 Sep 2022 10:40:19 -0700 (PDT) Received: from [10.137.0.17] (ip-86-49-229-52.bb.vodafone.cz. [86.49.229.52]) by smtp.gmail.com with ESMTPSA id a18-20020adffb92000000b002237fd66585sm6423802wrr.92.2022.09.04.10.40.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 04 Sep 2022 10:40:18 -0700 (PDT) Content-Type: multipart/mixed; boundary="------------Olp0uOgAvI5OVRrc4cZeyPlC" Message-ID: Date: Sun, 4 Sep 2022 19:40:14 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: TRAP: FailedAssertion("prev_first_lsn < cur_txn->first_lsn", File: "reorderbuffer.c", Line: 927, PID: 568639) Content-Language: en-US From: Tomas Vondra To: Amit Kapila Cc: pgsql-hackers References: <7950f8c6-3fa9-ad32-b040-7024d8eb1bea@enterprisedb.com> In-Reply-To: <7950f8c6-3fa9-ad32-b040-7024d8eb1bea@enterprisedb.com> X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------Olp0uOgAvI5OVRrc4cZeyPlC Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 9/4/22 16:08, Tomas Vondra wrote: > ... > > so in fact we *know* 849 is a subxact of 848, but we don't call > ReorderBufferAssignChild in this case. In fact we can't even do the > assignment easily in this case, because we create the subxact first, so > that the crash happens right when we attempt to create the toplevel one, > and we never even get a chance to do the assignment: > > 1) process the NEW_CID record, logged for 849 (subxact) > 2) process CIDs in the WAL record, which has topleve_xid 848 > > > So IMHO we need to figure out what to do for WAL records that create > both the toplevel and subxact - either we need to skip them, or rethink > how we create the ReorderBufferTXN structs. > This fixes the crash for me, by adding a ReorderBufferAssignChild call to SnapBuildProcessNewCid, and tweaking ReorderBufferAssignChild to ensure we don't try to create the top xact before updating the subxact and removing it from the toplevel_by_lsn list. Essentially, what's happening is this: 1) We read the NEW_CID record, which is logged with XID 849, i.e. the subxact. But we don't know it's a subxact, so we create it as a top-level xact with the LSN. 2) We start processing contents of the NEW_CID, which however has info that 849 is subxact of 848, calls ReorderBufferAddNewTupleCids which promptly does ReorderBufferTXNByXid() with the top-level XID, which creates it with the same LSN, and crashes because of the assert. I'm not sure what's the right/proper way to fix this ... The problem is ReorderBufferAssignChild was coded in a way that did not expect the subxact to be created first (as a top-level xact). And indeed, if I add Assert(false) to the (!new_sub) branch that converts top-level xact to subxact, check-world still passes. So we never test this case, but the NEW_CID breaks this assumption and creates them in the opposite order (i.e. subxact first). So the patch "fixes" this by (a) tweaking ReorderBufferAssignChild to first remove the subxact from the list of top-level transactions (b) call ReorderBufferAssignChild when processing NEW_CID However, I wonder whether we even have to process these records? If the restart_lsn is half-way through the xact, so can we even decode it? Maybe we can just skip all of this, somehow? We'd still need to remember 849 is a subxact of 848, at least, so that we know to skip it too. Thread [1] suggested to relax the assert to allow the same LSN, provided it's xact and it's subxact. That goes directly against the expectation the toplevel_by_lsn list contains no known subxacts, and I don't think we should be relaxing that. After all, just tweaking the LSN does not really fix the issue, because not remembering it's xact+subxact is part of the issue. In principle, I think the issue is exactly the opposite, i.e. that we don't realize 849 is a subxact, and leave it in the list. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company --------------Olp0uOgAvI5OVRrc4cZeyPlC Content-Type: text/x-patch; charset=UTF-8; name="crash-wip-fix.patch" Content-Disposition: attachment; filename="crash-wip-fix.patch" Content-Transfer-Encoding: base64 ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL3JlcGxpY2F0aW9uL2xvZ2ljYWwvcmVvcmRlcmJ1 ZmZlci5jIGIvc3JjL2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