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 1oDhGD-0003cd-Q4 for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Jul 2022 07:03:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oDhGC-0003Qw-AE for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Jul 2022 07:03:12 +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 1oDhGB-0003N1-VX for pgsql-hackers@lists.postgresql.org; Tue, 19 Jul 2022 07:03:12 +0000 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oDhG5-00064r-4u for pgsql-hackers@lists.postgresql.org; Tue, 19 Jul 2022 07:03:11 +0000 Received: by mail-pg1-x52c.google.com with SMTP id s27so12661570pga.13 for ; Tue, 19 Jul 2022 00:03:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=g+vUI7E8LoeQ3qE8xDdbucRGbCun2wHDWr25ToJsmwA=; b=BPyG8QGh+dQAx4FLJwDVMIzKlZwMFGs9EZt0zoZxXopoQn0RJ/p5c1nol5rum9W2uN QJbb+Hd2jEcfi7TlKl3BJWADHODg9DIt4IGsrLA2LN3wRB5eW6jS+6AbO1LUySa8ZPiD Ge5rUNQPVVPft27R/FlYjDObyYWEQ72enMiWPFEcg59v7JAIOI2gk03VKXU25a/h9VoX afadta/iKBP51b69Xm6DISBYPw+NrO+lhDgLEBbJwA1MzNjpF5TazxEh46oiC1UWTIxI mYRVrB1Fa1coTY3VoPyZYs8pkfw19NjZAoGZUojhsEM7OgQXgg6XHNwLgZffnFS+cT6u O9yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=g+vUI7E8LoeQ3qE8xDdbucRGbCun2wHDWr25ToJsmwA=; b=wjUnd9iI1Nl2cw5cPvXWgWDK7KLTw7rFGVWkeDGfJtt6e3p2B5OaDHOzXNSxZ6orlx tg8wfgOXd+1RqId5KsR9AGtpEAOse5Q+amMuCDWRTnKi0RK9Fcn54/M5JXYM/ItuPvCo RBq5NrOWRYjseIgFaRK6Hl4xr/Z1yGidxWc0Q6y/aoB9Y44yydbIH3ONrkA02twgluK/ MsuIwXhM02F4OKkMzoV0cdx+xo+/U8j2jdle7XrVmvEhJrSTOmADnJM0yoaIWEA7eoE1 xJUBxMaozPNmYqctx1eCgZQtlWg7Cj02s/qmuWAJZJsqXmj5z0R7KyN0kyjbecXYT0gy H1LQ== X-Gm-Message-State: AJIora/hNgAONYPbnP5pbMfU2sIlg80FYDbsl/pKaN/DB76om26FUAKv u8uFUXGZd6DqaurTyIQuyZ7lvgzreBucc3v/784= X-Google-Smtp-Source: AGRyM1uUAEF83UPWZm9EXlb5tqIgPSY7FmN4IQeNbyfUHQI9rqHCCLc1NI2rjVHoyT5lYJ3Cp55wZUUZHf4SsrnzVOo= X-Received: by 2002:a05:6a00:88e:b0:528:1d40:cc20 with SMTP id q14-20020a056a00088e00b005281d40cc20mr32392962pfj.64.1658214182662; Tue, 19 Jul 2022 00:03:02 -0700 (PDT) MIME-Version: 1.0 References: <20211008.165055.1621145185927268721.horikyota.ntt@gmail.com> <20220523.133323.444599955292141474.horikyota.ntt@gmail.com> In-Reply-To: From: Masahiko Sawada Date: Tue, 19 Jul 2022 16:02:26 +0900 Message-ID: Subject: Re: [BUG] Logical replication failure "ERROR: could not map filenode "base/13237/442428" to relation OID" with catalog modifying txns To: Amit Kapila Cc: "osumi.takamichi@fujitsu.com" , Kyotaro Horiguchi , "Drouvot, Bertrand" , PostgreSQL Hackers , "Oh, Mike" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Jul 19, 2022 at 1:47 PM Amit Kapila wrote= : > > On Tue, Jul 19, 2022 at 6:34 AM Masahiko Sawada w= rote: > > > > On Mon, Jul 18, 2022 at 1:12 PM Amit Kapila w= rote: > > > > > > On Fri, Jul 15, 2022 at 8:09 PM Masahiko Sawada wrote: > > > > > > > > This patch should have the fix for the issue that Shi yu reported. = Shi > > > > yu, could you please test it again with this patch? > > > > > > > > > > Can you explain the cause of the failure and your fix for the same? > > > > @@ -1694,6 +1788,8 @@ out: > > /* be tidy */ > > if (ondisk) > > pfree(ondisk); > > + if (catchange_xip) > > + pfree(catchange_xip); > > > > Regarding the above code in the previous version patch, looking at the > > generated assembler code shared by Shi yu offlist, I realized that the > > =E2=80=9Cif (catchange_xip)=E2=80=9D is removed (folded) by gcc optimiz= ation. This is > > because we dereference catchange_xip before null-pointer check as > > follow: > > > > + /* copy catalog modifying xacts */ > > + sz =3D sizeof(TransactionId) * catchange_xcnt; > > + memcpy(ondisk_c, catchange_xip, sz); > > + COMP_CRC32C(ondisk->checksum, ondisk_c, sz); > > + ondisk_c +=3D sz; > > > > Since sz is 0 in this case, memcpy doesn=E2=80=99t do anything actually= . > > > > By checking the assembler code, I=E2=80=99ve confirmed that gcc does th= e > > optimization for these code and setting > > -fno-delete-null-pointer-checks flag prevents the if statement from > > being folded. Also, I=E2=80=99ve confirmed that adding the check if > > "catchange.xcnt > 0=E2=80=9D before the null-pointer check also can pre= vent > > that. Adding a check if "catchange.xcnt > 0=E2=80=9D looks more robust= . I=E2=80=99ve > > added a similar check for builder->committed.xcnt as well for > > consistency. builder->committed.xip could have no transactions. > > > > 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); I would hesitate to add comments about preventing the particular optimization. I think we do null-pointer-check-then-pfree many place. It seems to me that checking the array length before memcpy is more natural than checking both the array length and the array existence before pfree. Regards, --=20 Masahiko Sawada EDB: https://www.enterprisedb.com/