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 1q6Yp6-0003xI-TM for pgsql-hackers@arkaria.postgresql.org; Tue, 06 Jun 2023 15:42:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q6Yp5-0005g6-Bx for pgsql-hackers@arkaria.postgresql.org; Tue, 06 Jun 2023 15:42:15 +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 1q6Yp5-0005fx-04 for pgsql-hackers@lists.postgresql.org; Tue, 06 Jun 2023 15:42:15 +0000 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1q6Yoz-000bhU-Kw for pgsql-hackers@postgresql.org; Tue, 06 Jun 2023 15:42:13 +0000 Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-5148e4a2f17so9600006a12.1 for ; Tue, 06 Jun 2023 08:42:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1686066128; x=1688658128; 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:message-id:reply-to; bh=OO5O1BsdMGPMsxyUEi0IeA83W9mtKW1tDttwc6AuLRM=; b=Whzoo8DSvS6+iLRr1+mZnGtDA2vx07XDCYS6HZSj0bUDMCzde3JGvIKTs5vg2PUCup oft1W+tnkkpJbimDNQ+/2CcDpU2E1tDbo97OBesXtM8TWCSuNfJSgkC2GcoPGLSfrjuX G1KRys7n2lp36uPX41ARRPuW8bxbJfeP0zNMph1gDUoM/zhPXr+lxDdovajTlDrhE3xp xoP/gCHnD16HYEXHa/76lLcGAuoz+pThq7cAS9/Ja+R9aXVuO+XHkQlHhVQwsrLy6PD7 7ZZDKH/v9O8eGJx4Kjob8KCQ0T9AMuZQ8RvQVZgQaIQq/NhBoWeYtZTzkvLDxLWsWG+F 4aKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686066128; x=1688658128; 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:message-id:reply-to; bh=OO5O1BsdMGPMsxyUEi0IeA83W9mtKW1tDttwc6AuLRM=; b=kn3ZtwC/3YIGmfyqXddwTchxdKoF5RaNmZ7/TesnVGFjhgV7V0RpNvj9twP4FLZ9Fs 1JjbGqjNsYJH1DuVJ2ycBFNbfK87mYa2ycDygWJ8k7n8G+5MSYxWKW6VylQ1C3EfYxuV 4Z4Kx+6gsQzwYzxXTZUQqqssBNuabmBsEuNwk/avnkzW75TLgfw6fqsAhxsw+PAILXUf kXJ/A92jV0RaC8Ay+pOcaj4NzC8SVYfkUvdT15X8wzv6jshO6SSyvVqN/7TGS232ASKo j0s7Osx8aS6PbD2PccMx4fwizxTfgno+8vqUWNsYeYnBdZLeR6Y2iS53XTiRGYyi/QVo FK8w== X-Gm-Message-State: AC+VfDwn2JGg7jgX+ZWefLoGZpwQ8QJPA9m65UZU9g3xcucw7qZfVH1J 9d5x+R1mBVbLcJQYKzOeKaVo0iXaxk9z3m37oaE= X-Google-Smtp-Source: ACHHUZ61vhHXsRcITzQqLfTcJ2YTMdXRJA8b0e+0iPrtk990I9I4sxfebanXwS2lzP8mBveMInPumA== X-Received: by 2002:aa7:c386:0:b0:514:a292:7b84 with SMTP id k6-20020aa7c386000000b00514a2927b84mr2193366edq.19.1686066128222; Tue, 06 Jun 2023 08:42:08 -0700 (PDT) Received: from [10.137.0.17] (static-84-42-175-93.bb.vodafone.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id h26-20020aa7de1a000000b005148f0e8568sm5136629edv.39.2023.06.06.08.42.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 06 Jun 2023 08:42:07 -0700 (PDT) Message-ID: Date: Tue, 6 Jun 2023 17:42:05 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: TRAP: FailedAssertion("prev_first_lsn < cur_txn->first_lsn", File: "reorderbuffer.c", Line: 927, PID: 568639) Content-Language: en-US To: Alexander Lakhin , Amit Kapila , Masahiko Sawada Cc: pgsql-hackers References: <99b45770-e3d8-4522-ea52-f4509931c65b@enterprisedb.com> <1f860e40-9f95-f0f8-ff4b-4b780f9151ad@gmail.com> From: Tomas Vondra In-Reply-To: <1f860e40-9f95-f0f8-ff4b-4b780f9151ad@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 6/6/23 14:00, Alexander Lakhin wrote: > Hello Tomas, > > 06.06.2023 12:56, Tomas Vondra wrote: >> On 6/6/23 11:00, Alexander Lakhin wrote: >>> Hello, >>> ...> With the debug logging added inside AssertTXNLsnOrder() I see: >>> ctx->snapshot_builder->start_decoding_at: 209807224, >>> ctx->reader->EndRecPtr: 210043072, >>> SnapBuildXactNeedsSkip(ctx->snapshot_builder, ctx->reader->EndRecPtr): 0 >>> and inside the loop: >>> cur_txn->first_lsn: 209792872 >>> cur_txn->first_lsn: 209975744 >>> cur_txn->first_lsn: 210043008 >>> cur_txn->first_lsn: 210043008 >>> and it triggers the Assert. >>> >> So what's the prev_first_lsn value for these first_lsn values? How does >> it change over time? Did you try looking at the pg_waldump for these >> positions? > > With more logging I've got (for another run): > ReorderBufferTXNByXid| xid: 3397, lsn: c1fbc80 > > ctx->snapshot_builder->start_decoding_at: c1f2cc0, > ctx->reader->EndRecPtr: c1fbcc0, > SnapBuildXactNeedsSkip(ctx->snapshot_builder, ctx->reader->EndRecPtr): 0 > prev_first_lsn: 0, cur_txn->first_lsn: c1fbc80 > prev_first_lsn: c1fbc80, cur_txn->first_lsn: c1fbc80 > TRAP: failed Assert("prev_first_lsn < cur_txn->first_lsn") ... > > waldump for 00000001000000000000000C shows: > grep c1fbc80: > rmgr: Heap2       len (rec/tot):     60/    60, tx:       3398, lsn: > 0/0C1FBC80, prev 0/0C1FBC50, desc: NEW_CID rel: 1663/18763/19987, tid: > 0/1, cmin: 1, cmax: 4294967295, combo: 4294967295 > rmgr: Heap        len (rec/tot):     59/    59, tx:       3398, lsn: > 0/0C1FBCC0, prev 0/0C1FBC80, desc: INSERT+INIT off: 1, flags: 0x08, > blkref #0: rel 1663/18763/19987 blk 0 > > grep '( 3397| 3398)' I've been able to reproduce this, after messing with the script a little bit (I had to skip the test_decoding regression tests, because that was complaining about slots already existing etc). Anyway, AssertTXNLsnOrder sees these two transactions (before aborting): 26662 0/6462E6F0 (first 0/0) 26661 0/6462E6F0 (first 0/6462E6F0) where 26661 is the top xact, 26662 is a subxact of 26661. This is clearly a problem, because we really should not have subxact in this list once the assignment gets applied. And the relevant WAL looks like this: --------------------------------------------------------------------- 26662, lsn: 0/645EDAA0, prev 0/645EDA60, desc: ASSIGNMENT xtop 26661: subxacts: 26662 26662, lsn: 0/645EDAD0, prev 0/645EDAA0, desc: INSERT+INIT off: 1, flags: 0x08, blkref #0: rel 1663/125447/126835 blk 0 ... 0, lsn: 0/6462E5D8, prev 0/6462E2A0, desc: RUNNING_XACTS nextXid 26673 latestCompletedXid 26672 oldestRunningXid 26661; 3 xacts: 26667 26661 26664; 3 subxacts: 26668 26662 26665 ... 26662, lsn: 0/6462E6F0, prev 0/6462E678, desc: NEW_CID rel: 1663/125447/126841, tid: 0/1, cmin: 1, cmax: 4294967295, combo: 4294967295 26662, lsn: 0/6462E730, prev 0/6462E6F0, desc: INSERT+INIT off: 1, flags: 0x08, blkref #0: rel 1663/125447/126841 blk 0 26661, lsn: 0/6462E770, prev 0/6462E730, desc: COMMIT 2023-06-06 16:41:24.442870 CEST; subxacts: 26662 --------------------------------------------------------------------- so the assignment is the *first* thing that happens for these xacts. However, we skip the assignment, because the log for this call of get_changes says this: LOG: logical decoding found consistent point at 0/6462E5D8 so we fail to realize the 26662 is a subxact. Then when processing the NEW_CID, SnapBuildProcessNewCid chimes in and does this: ReorderBufferXidSetCatalogChanges(builder->reorder, xid, lsn); ReorderBufferAddNewTupleCids(builder->reorder, xlrec->top_xid, lsn, xlrec->target_locator, xlrec->target_tid, xlrec->cmin, xlrec->cmax, xlrec->combocid); and ReorderBufferAddNewTupleCids() proceeds to enter an entry for the passed XID (which is xlrec->top_xid, 26661), but with LSN of the WAL record. But ReorderBufferXidSetCatalogChanges() already did the same thing for the subxact 26662, as it has no idea it's a subxact (due to the skipped assignment). I haven't figured out what exactly is happening / what it should be doing instead. But it seems wrong to skip the assignment - I wonder if SnapBuildProcessRunningXacts might be doing that too eagerly. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company