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 1oDy2a-0004yC-HB for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Jul 2022 00:58:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oDy2Z-0007J4-Dm for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Jul 2022 00:58:15 +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 1oDy2Z-00078h-2C for pgsql-hackers@lists.postgresql.org; Wed, 20 Jul 2022 00:58:15 +0000 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oDy2W-0000Jm-RM for pgsql-hackers@lists.postgresql.org; Wed, 20 Jul 2022 00:58:14 +0000 Received: by mail-pj1-x102e.google.com with SMTP id b7-20020a17090a12c700b001f20eb82a08so562905pjg.3 for ; Tue, 19 Jul 2022 17:58:12 -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=N+6jqhImrUp+nlliW2bCMfq0EJsE6LrjGno2xIN23us=; b=G+bk4Gni34KMt6GtJEKJehSp8ehRcCax+bkrv4mZotCUAzDOSFfUoWkZYntQeTNOeG TOC/fKsr4t1PYJ/eTDQVz6ivo5OEGJ98+Ih8sNGwNvg1zgl1o0OR797kUcTFQ/0Wujry ukOZ84IiuaquiSVUJshO+q1mHgwFkUuQLgvhpt2xkqsKDCW47u6QyETF1hDhaHlOeUSD b5FypAQAjj466+8G0C0mcF+CLKFhfQ64tCPsXRYKE1eWrJWweVZNboVVVmaIjkUqYPAm nEjGYucyP3+8kMLDC/0PrQuuCJCXU4tnGNqUs2BcZ8wvEzZrk9vfGpZ49Pst6lPKL9Ga 9elw== 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=N+6jqhImrUp+nlliW2bCMfq0EJsE6LrjGno2xIN23us=; b=8SB9hIV6pjMLNFjSYDQQkcKisN5sd9sU9reiiPr5RGiZSMVJANkn4hOlONiFMfRoIR G9ub42FfPrAIcxMQo4LhvUvX6/P/+UK6pyLbFQ5i7anHZZpJ3fe44Hwu/FmHXPq3aUqN ZL/9PCCkdy2ORF5VASpzqET/JCh0qs8YlbGKnkRxXKVn3YcvvAhf+lmsHFqR98c6H+Rf h3TJkEdS9Dxov7V7iUvDGXKUN42fyN5goGHQT6WbFERqtMrlcX4dw884CBYj9HP0ym41 DQorW081RdxmyhX96PKi90vbRVW70SZwOsQCWq6zIVZ0kcYvFmS7S1MC7Sj4iVqp/HZ6 WyRQ== X-Gm-Message-State: AJIora8RkDSaHvgeEMZpkahXzxyxu3xxtPHBzmwu4PV9RbmATOMGtxQA EZq3Hr5W0dWp5zWdqOYLCDQ= X-Google-Smtp-Source: AGRyM1uB87zw4BJAcpzSaXQTvCye5B5//6mzirJAzhojf7P3eQFBS/ij2ct43jLNjQPkCuG/fthujA== X-Received: by 2002:a17:902:f608:b0:16d:20a0:5339 with SMTP id n8-20020a170902f60800b0016d20a05339mr527882plg.133.1658278691731; Tue, 19 Jul 2022 17:58:11 -0700 (PDT) Received: from localhost (KD036014041111.ppp-bb.dion.ne.jp. [36.14.41.111]) by smtp.gmail.com with ESMTPSA id s15-20020a170902ea0f00b0016bf803341asm10226418plg.146.2022.07.19.17.58.09 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 19 Jul 2022 17:58:11 -0700 (PDT) Date: Wed, 20 Jul 2022 09:58:08 +0900 (JST) Message-Id: <20220720.095808.772209644652657995.horikyota.ntt@gmail.com> To: sawada.mshk@gmail.com Cc: amit.kapila16@gmail.com, osumi.takamichi@fujitsu.com, 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: <20220719.163544.1139566326103773644.horikyota.ntt@gmail.com> User-Agent: Mew version 6.8 on Emacs 26.1 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk At Tue, 19 Jul 2022 17:31:07 +0900, Masahiko Sawada wrote in > On Tue, Jul 19, 2022 at 4:35 PM Kyotaro Horiguchi > wrote: > > At Tue, 19 Jul 2022 10:17:15 +0530, Amit Kapila wrote in > > > Good work. I wonder without comments this may create a problem in the > > > future. OTOH, I don't see adding a check "catchange.xcnt > 0" before > > > freeing the memory any less robust. Also, for consistency, we can use > > > a similar check based on xcnt in the SnapBuildRestore to free the > > > memory in the below code: > > > + /* set catalog modifying transactions */ > > > + if (builder->catchange.xip) > > > + pfree(builder->catchange.xip); > > > > But xip must be positive there. We can add a comment explains that. > > > > Yes, if we add the comment for it, probably we need to explain a gcc's > optimization but it seems to be too much to me. Ah, sorry. I confused with other place in SnapBuildPurgeCommitedTxn. I agree to you, that we don't need additional comment *there*. > > + catchange_xip = ReorderBufferGetCatalogChangesXacts(builder->reorder); > > > > catchange_xip is allocated in the current context, but ondisk is > > allocated in builder->context. I see it kind of inconsistent (even if > > the current context is same with build->context). > > Right. I thought that since the lifetime of catchange_xip is short, > until the end of SnapBuildSerialize() function we didn't need to > allocate it in builder->context. But given ondisk, we need to do that > for catchange_xip as well. Will fix it. Thanks. > > + if (builder->committed.xcnt > 0) > > + { > > > > It seems to me comitted.xip is always non-null, so we don't need this. > > I don't strongly object to do that, though. > > But committed.xcnt could be 0, right? We don't need to copy anything > by calling memcpy with size = 0 in this case. Also, it looks more > consistent with what we do for catchange_xcnt. Mmm. the patch changed that behavior. AllocateSnapshotBuilder always allocate the array with a fixed size. SnapBuildAddCommittedTxn still assumes builder->committed.xip is non-NULL. SnapBuildRestore *kept* ondisk.builder.commited.xip populated with a valid array pointer. But the patch allows committed.xip be NULL, thus in that case, SnapBuildAddCommitedTxn calls repalloc(NULL) which triggers assertion failure. > > + Assert((xcnt > 0) && (xcnt == rb->catchange_ntxns)); > > > > (xcnt > 0) is obvious here (otherwise means dlist_foreach is broken..). > > (xcnt == rb->catchange_ntxns) is not what should be checked here. The > > assert just requires that catchange_txns and catchange_ntxns are > > consistent so it should be checked just after dlist_empty.. I think. > > > > If we want to check if catchange_txns and catchange_ntxns are > consistent, should we check (xcnt == rb->catchange_ntxns) as well, no? > This function requires the caller to use rb->catchange_ntxns as the > length of the returned array. I think this assertion ensures that the > actual length of the array is consistent with the length we > pre-calculated. Sorry again. Please forget the comment about xcnt == rb->catchange_ntxns.. regards. -- Kyotaro Horiguchi NTT Open Source Software Center