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 1oB943-0001bE-5S for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Jul 2022 06:08:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oB942-0006si-1X for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Jul 2022 06:08:06 +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 1oB941-0006sZ-IU for pgsql-hackers@lists.postgresql.org; Tue, 12 Jul 2022 06:08:05 +0000 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oB93y-0006ll-V7 for pgsql-hackers@lists.postgresql.org; Tue, 12 Jul 2022 06:08:04 +0000 Received: by mail-pl1-x62d.google.com with SMTP id g21so157619plh.2 for ; Mon, 11 Jul 2022 23:08:02 -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; bh=ce6HeehNOo2Z2IFnbALF6XkQSSMumYeb5wLcu8B2HP8=; b=O26xtPUorSt67GlG/5FmLVQ1/sxO01TahR3RbceqafQ6FgvCY3GHRclTf+VlcZxXuv wK3R7fVbht5N0TtSDyQyf3y075ySe+qtZwJjN4HbbLHQO0/pQ7uoDCaVRJg5B8xVOUh4 P+5OQPdIFC6K9I91l/5Uwp1qWDVpkgCgwdGIotqjOv6uy4CSY1J4xZByvfuIyBSmw21j 3zYq5/vQkwsWLCupDIcEdlZauUjlFfXdm/0TDiYXUP1wLErcZlnpYyU5zUWzyaUVgu4V xzXGmXpBJKxUWAvrGO8zfZim81sGdND9KlUGGCCW8pVIH0fZ+fT6QG1zDZZ7ubW7+rKU 5vLA== 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; bh=ce6HeehNOo2Z2IFnbALF6XkQSSMumYeb5wLcu8B2HP8=; b=yFAhSWLHjXAq7T/v1D0wxFCYiTloPDiEFEex1OIAo6RpZ5B1epNIRa5VwyVcWb0QIB AAoIdNbtYa8bjdhShABQcgVlYF9H30JCAhP/iY7NKa2cUzqPAp4KGvY5LU6Ch6/jTnPY Ema4CWPpfnZ3033LeMugWsXKQ3ZxtLSY9qoV/znlsuh3TDDsRHLlRaKO/EpOZcWSExkH e1D1902ICc8WYymeDTc+InkXnZMxj4Iwb+IoX8vmzDtOflSJn0muv4jlchDRJDagb2o/ 1DPt0oJlz2kz1wql4AaVCH7nRfd1R9orLjBiaVoBZfjD/wfMo3JyMx6jRcYnJ9BZkMPh lrfA== X-Gm-Message-State: AJIora+yMYljuC1T1ukoKsRBwTi28sfVId747HhbujgMHSk0F88X1X3N V0ggw9N1woumvYDTY86k2dQRDqTvNnbbhTeraaI= X-Google-Smtp-Source: AGRyM1uGl/Tyg2NPxHuJXjZm9r46yf3Wfnen8Wld45R/BRKuA2X+TgBFDGqsCCRNzGIMUT3GMhbvpgRfgARBDZE4VYg= X-Received: by 2002:a17:90a:7c05:b0:1ee:e40c:589b with SMTP id v5-20020a17090a7c0500b001eee40c589bmr2450590pjf.78.1657606081987; Mon, 11 Jul 2022 23:08:01 -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, 12 Jul 2022 15:07:25 +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: Kyotaro Horiguchi , "Drouvot, Bertrand" , PostgreSQL Hackers , "Oh, Mike" Content-Type: multipart/mixed; boundary="000000000000b1ec1705e3957d40" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000b1ec1705e3957d40 Content-Type: text/plain; charset="UTF-8" On Tue, Jul 12, 2022 at 10:28 AM Masahiko Sawada wrote: > > On Tue, Jul 12, 2022 at 9:48 AM Masahiko Sawada wrote: > > > > On Fri, Jul 8, 2022 at 8:20 PM Masahiko Sawada wrote: > > > > > > On Fri, Jul 8, 2022 at 5:59 PM Amit Kapila wrote: > > > > > > > > On Fri, Jul 8, 2022 at 12:46 PM Masahiko Sawada wrote: > > > > > > > > > > On Fri, Jul 8, 2022 at 3:27 PM Amit Kapila wrote: > > > > > > > > > > > > > > > > > 1. > > > > > > In ReorderBufferGetCatalogChangesXacts(), isn't it better to use the > > > > > > list length of 'catchange_txns' to allocate xids array? If we can do > > > > > > so, then we will save the need to repalloc as well. > > > > > > > > > > Since ReorderBufferGetcatalogChangesXacts() collects all ongoing > > > > > catalog modifying transactions, the length of the array could be > > > > > bigger than the one taken last time. We can start with the previous > > > > > length but I think we cannot remove the need for repalloc. > > > > > > > > > > > > > It is using the list "catchange_txns" to form xid array which > > > > shouldn't change for the duration of > > > > ReorderBufferGetCatalogChangesXacts(). Then the caller frees the xid > > > > array after its use. Next time in > > > > ReorderBufferGetCatalogChangesXacts(), the fresh allocation for xid > > > > array happens, so not sure why repalloc would be required? > > > > > > Oops, I mistook catchange_txns for catchange->xcnt. You're right. > > > Starting with the length of catchange_txns should be sufficient. > > > > > > > I've attached an updated patch. > > > > While trying this idea, I noticed there is no API to get the length of > > dlist, as we discussed offlist. Alternative idea was to use List > > (T_XidList) but I'm not sure it's a great idea since deleting an xid > > from the list is O(N), we need to implement list_delete_xid, and we > > need to make sure allocating list node in the reorder buffer context. > > So in the patch, I added a variable, catchange_ntxns, to keep track of > > the length of the dlist. Please review it. > > > > I'm doing benchmark tests and will share the results. > I've done benchmark tests to measure the overhead introduced by doing bsearch() every time when decoding a commit record. I've simulated a very intensified situation where we decode 1M commit records while keeping builder->catchange.xip array but the overhead is negilible: HEAD: 584 ms Patched: 614 ms I've attached the benchmark script I used. With increasing LOG_SNAPSHOT_INTERVAL_MS to 90000, the last decoding by pg_logicla_slot_get_changes() decodes 1M commit records while keeping catalog modifying transactions. Regards, -- Masahiko Sawada EDB: https://www.enterprisedb.com/ --000000000000b1ec1705e3957d40 Content-Type: application/octet-stream; name="bench.spec" Content-Disposition: attachment; filename="bench.spec" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_l5hrsecq0 IyBUZXN0IHRoYXQgZGVjb2Rpbmcgb25seSB0aGUgY29tbWl0IHJlY29yZCBvZiB0aGUgdHJhbnNh Y3Rpb24gdGhhdCBoYXZlCiMgY2F0YWxvZy1jaGFuZ2VkLgpzZXR1cAp7CiAgICBEUk9QIFRBQkxF IElGIEVYSVNUUyB0YmwxOwogICAgQ1JFQVRFIFRBQkxFIHRibDEgKHZhbDEgaW50ZWdlciwgdmFs MiBpbnRlZ2VyKTsKICAgIGNyZWF0ZSBwcm9jZWR1cmUgcnVuX3R4bnMoY250IGludCkgYXMgJCQK ICAgIGRlY2xhcmUKICAgICAgaSBpbnQ7CiAgICBCRUdJTgogICAgZm9yIGkgaW4gMS4uY250IGxv b3AKICAgICAgICBleGVjdXRlICdpbnNlcnQgaW50byB0YmwxIHZhbHVlcyAoMSknOwoJY29tbWl0 OwogICAgIGVuZCBsb29wOwogICAgIGVuZDsKICAgICAkJAogICAgIGxhbmd1YWdlIHBscGdzcWw7 Cn0KCnRlYXJkb3duCnsKICAgIERST1AgVEFCTEUgdGJsMTsKICAgIFNFTEVDVCAnc3RvcCcgRlJP TSBwZ19kcm9wX3JlcGxpY2F0aW9uX3Nsb3QoJ2lzb2xhdGlvbl9zbG90Jyk7Cn0KC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