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 1mYken-0003ru-6P for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Oct 2021 07:51:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mYkek-0004S3-Fp for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Oct 2021 07:51:02 +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 1mYkek-0004Rt-53 for pgsql-hackers@lists.postgresql.org; Fri, 08 Oct 2021 07:51:02 +0000 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mYkeh-0000vt-O4 for pgsql-hackers@lists.postgresql.org; Fri, 08 Oct 2021 07:51:00 +0000 Received: by mail-pf1-x42b.google.com with SMTP id i65so4537869pfe.12 for ; Fri, 08 Oct 2021 00:50:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:message-id:to:cc:subject:from:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=MjnFJEaHYJKJYoTO3pv6JHlkEZ3XVruEqXDbijghnys=; b=AGWNK2cA96UOS9DMv09TtuqpaqNJ6D6d70fc2c6Fa4MHHvpbmU2lwES3Hg8GatJXVV 49IPSZ9Fn3UIdrxK+NchkK6DKjaW6Uh3tjZ6QnRvDE/7AJUTLO6LfhAn1odbZlcW207a Z1RfnA7lt+VUkkrI+fKpGcCU1AJPvkRr3BNzpWyOwXPnVaUwGvLhwl74QE3hlHA9IgJk AG7WaqIRzI0yvThJYDA4uHicaw392BYqpiObrFyhOl8I0ZVSmdTxizEJVuPrVSEYl0/B wpZZbvGZRO2pcRkLgoETxQRhlmfjq9wE4L/U+WN9/EER3jd0P8jxLXE2a8/JRuG0PdGL 8ykg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:to:cc:subject:from:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=MjnFJEaHYJKJYoTO3pv6JHlkEZ3XVruEqXDbijghnys=; b=f5+NN9oheVOOLXbK01I2PzRa1p1veBqcL1i1rKIzEE2lZo+I5JF+tWJWvvX6aq5UTU gEPW/FYxEi0yybzqa67xuGRhHFdx7lMJ3+2GUfIukP/px3lHGrHPhizsedG1JkzYefT2 Z8ong3VdFk/n73t90CadCt41YSEoj+P8wilB6hmROHDNh2GqqVjIc3vuTscGZNNwRy2V C+MW2VmaLPs50hVs4RUMb99kM86QNHPf/n2Yc0b8EBKqetnZA470IegKcL+8UB0evGRr Lk3ZVQEV4NASA6pZTcLCKd57YoKS7ig7z0KxUoT7FkZxmH4ZICCTlOf80sBTvyqQu/Dd VYog== X-Gm-Message-State: AOAM533BEEgUUnUUIKY3QZapIlqRNfMm0GhILHA6BUKB5g4Cy9NuLHMd pmsjwG2D+8N80WA7sUAwt7I= X-Google-Smtp-Source: ABdhPJw2OZCIfExjGLW5CGG1CY+z+wU72jUFz1g4UF1qRNmpSC2MNqXEC4EurK+4h6HbfWKczFNnTw== X-Received: by 2002:a65:624b:: with SMTP id q11mr3426724pgv.232.1633679458616; Fri, 08 Oct 2021 00:50:58 -0700 (PDT) Received: from localhost (KD036014041111.ppp-bb.dion.ne.jp. [36.14.41.111]) by smtp.gmail.com with ESMTPSA id r130sm1597918pfc.89.2021.10.08.00.50.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 08 Oct 2021 00:50:57 -0700 (PDT) Date: Fri, 08 Oct 2021 16:50:55 +0900 (JST) Message-Id: <20211008.165055.1621145185927268721.horikyota.ntt@gmail.com> To: sawada.mshk@gmail.com Cc: bdrouvot@amazon.com, pgsql-hackers@lists.postgresql.org, minsoo@amazon.com Subject: Re: [BUG] Logical replication failure "ERROR: could not map filenode "base/13237/442428" to relation OID" with catalog modifying txns From: Kyotaro Horiguchi In-Reply-To: References: <6a176936-1af1-41d9-9ded-bde0eb47dd5c@amazon.com> User-Agent: Mew version 6.8 on Emacs 26.1 Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Fri_Oct__8_16_50_55_2021_184)--" Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ----Next_Part(Fri_Oct__8_16_50_55_2021_184)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit At Thu, 7 Oct 2021 13:20:14 +0900, Masahiko Sawada wrote in > Another idea to fix this problem would be that before calling > SnapBuildCommitTxn() we create transaction entries in ReorderBuffer > for (sub)transactions whose COMMIT record has XACT_XINFO_HAS_INVALS, > and then mark all of them as catalog-changed by calling > ReorderBufferXidSetCatalogChanges(). I've attached a PoC patch for > this idea. What the patch does is essentially the same as what the > proposed patch does. But the patch doesn't modify the > SnapBuildCommitTxn(). And we remember the list of last running > transactions in reorder buffer and the list is periodically purged > during decoding RUNNING_XACTS records, eventually making it empty. I came up with the third way. SnapBuildCommitTxn already properly handles the case where a ReorderBufferTXN with RBTXN_HAS_CATALOG_CHANGES. So this issue can be resolved by create such ReorderBufferTXNs in SnapBuildProcessRunningXacts. One problem with this is that change creates the case where multiple ReorderBufferTXNs share the same first_lsn. I haven't come up with a clean idea to avoid relaxing the restriction of AssertTXNLsnOrder.. regards. -- Kyotaro Horiguchi NTT Open Source Software Center ----Next_Part(Fri_Oct__8_16_50_55_2021_184)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="register_running_xacts_at_logical_decoding_start_PoC.txt" diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 46e66608cf..503116764f 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -887,9 +887,14 @@ AssertTXNLsnOrder(ReorderBuffer *rb) if (cur_txn->end_lsn != InvalidXLogRecPtr) Assert(cur_txn->first_lsn <= cur_txn->end_lsn); - /* Current initial LSN must be strictly higher than previous */ + /* + * Current initial LSN must be strictly higher than previous. except + * this transaction is created by XLOG_RUNNING_XACTS. If one + * XLOG_RUNNING_XACTS creates multiple transactions, they share the + * same LSN. See SnapBuildProcessRunningXacts. + */ if (prev_first_lsn != InvalidXLogRecPtr) - Assert(prev_first_lsn < cur_txn->first_lsn); + Assert(prev_first_lsn <= cur_txn->first_lsn); /* known-as-subtxn txns must not be listed */ Assert(!rbtxn_is_known_subxact(cur_txn)); diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c index a5333349a8..58859112dc 100644 --- a/src/backend/replication/logical/snapbuild.c +++ b/src/backend/replication/logical/snapbuild.c @@ -1097,6 +1097,20 @@ SnapBuildProcessRunningXacts(SnapBuild *builder, XLogRecPtr lsn, xl_running_xact */ if (builder->state < SNAPBUILD_CONSISTENT) { + /* + * At the time we passed the first XLOG_RUNNING_XACTS record, the + * transactions notified by the record may have updated + * catalogs. Register the transactions with marking them as having + * caused catalog changes. The worst misbehavior here is some spurious + * invalidation at decoding start. + */ + if (builder->state == SNAPBUILD_START) + { + for (int i = 0 ; i < running->xcnt + running->subxcnt ; i++) + ReorderBufferXidSetCatalogChanges(builder->reorder, + running->xids[i], lsn); + } + /* returns false if there's no point in performing cleanup just yet */ if (!SnapBuildFindSnapshot(builder, lsn, running)) return; ----Next_Part(Fri_Oct__8_16_50_55_2021_184)----