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 1oV9g4-00013F-Ub for pgsql-hackers@arkaria.postgresql.org; Mon, 05 Sep 2022 10:50:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oV9g3-00077j-M3 for pgsql-hackers@arkaria.postgresql.org; Mon, 05 Sep 2022 10:50:03 +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 1oV9g3-00077a-Cl for pgsql-hackers@lists.postgresql.org; Mon, 05 Sep 2022 10:50:03 +0000 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oV9g0-0000Zv-IT for pgsql-hackers@postgresql.org; Mon, 05 Sep 2022 10:50:02 +0000 Received: by mail-wr1-x42e.google.com with SMTP id t14so3522239wrx.8 for ; Mon, 05 Sep 2022 03:50:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date; bh=4GSUbmB/fCrDKgmoLSXiyhv6YYV85JhEUeas6opdWSQ=; b=aawNGk13Dakz02h0/hFe/+wLAuqTieByxKE82GG/xnEataDwya761Sw/7gQ5z1ybA7 51FdRQkzJD3JU/tMwtS7G/M38mHPAGYxhlqV24g9VDUCp2bmSFqfooAqoRL795svZzJw Wayhq/AgYlOF7ye/AA8CUH3YGD07q91s2HbZX1DxcuKChRrji/VXH33sSfNUBLDv1DP9 bLLBYSwKQt69gkd3crlReQRHe8xpQ+Q1tX6SwB09sHMTsQEKYOuBgU/j2a59shQCjGu8 JkByaEEr4IQmkQrwHhG6HjKRRsaFnVHgt3zyJ7RbLs0rBaZKNh8EwUKSV+ZPVRQ05RCF ikkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date; bh=4GSUbmB/fCrDKgmoLSXiyhv6YYV85JhEUeas6opdWSQ=; b=2Js4JOSENYLxgIiVs5T/jFG83Pm0crWg0tMb5Su7lE+xzf30ziygytk+2pfSDajHzv OS8NYCAAXIVBWvLjMlV6y/uU8GW7aGSuiQnGWTENcOqJDYkXJGxV/kF+e2P/UWM/Jkcp HYPbyS0nwNrWSdyds+bTVWBddfoY5Itwsf1lIykS6Ew8tvuU4UQF9zMAN+aLtKvOVrBM yetCYPP5u/i2SYNLmq6Wfl3Qwx8dOP/fLv26bZ/eN9VqgK3omO0cOm8sTWWTYvmTcEWr T7H6xW9Rzs7LfC2SB1PAlMNvxIbAjcWcntrAamgGxgFlDVZcUNSjTiTBhiwGpC+9iS8a By4A== X-Gm-Message-State: ACgBeo2K8Df1oaBF46kc+nZibp07Mjt0YOLmbbg6bPTWt+G++4WI4Pnn 104iX4zVvAK1xMmdhmtZfI/d6oCiok3RkCKmKT6jWRg19LbmzyfH+LqjOQVN+FECFh1x937RLHS PfyOwQghwE6N5UsaySbS9NkWBe0JcdLEV7UmCw83QlXCBigvGKPYREip+QjmEtt7ASBvCc06phV 343pNaVsV8+vuSsy/FPI/1PmY2MoN2bFzcmDOZvFR6SVj/ X-Google-Smtp-Source: AA6agR7K4Ns9TIgwSO8ylTN/4Xd07dKbCISu4K7NCJmJEquXgER3RF+Wn8Rb8A3lXmUPHLS/hZLFsw== X-Received: by 2002:a05:6000:1e1e:b0:226:e5c9:4b08 with SMTP id bj30-20020a0560001e1e00b00226e5c94b08mr16647073wrb.648.1662374998267; Mon, 05 Sep 2022 03:49:58 -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 bt24-20020a056000081800b0022377df817fsm8947185wrb.58.2022.09.05.03.49.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 05 Sep 2022 03:49:57 -0700 (PDT) Message-ID: Date: Mon, 5 Sep 2022 12:49:55 +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 To: Amit Kapila Cc: pgsql-hackers References: <7950f8c6-3fa9-ad32-b040-7024d8eb1bea@enterprisedb.com> From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 On 9/5/22 08:35, Amit Kapila wrote: > On Sun, Sep 4, 2022 at 11:10 PM Tomas Vondra > wrote: >> >> 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). >> > > I think there was a previously hard-coded way to detect that and we > have removed it in commit > (https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=e3ff789acfb2754cd7b5e87f6f4463fd08e35996). > I think it is possible that subtransaction gets logged without > previous top-level txn record as shown in the commit shared. > Well, yes and no. This wouldn't detect the issue, because the assert happens in the first ReorderBufferTXNByXid(), so it's still crash (in assert-enabled build, at least). Maybe removing the assumption was the wrong thing, and we should have changed the code so that we don't violate it? That's kinda what my "fix" does, in a way. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company