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 1ma9vj-0004lS-OW for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Oct 2021 05:02:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ma9vi-0006Kp-NA for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Oct 2021 05:02:22 +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 1ma9tY-0001Ec-GO for pgsql-hackers@lists.postgresql.org; Tue, 12 Oct 2021 05:00:08 +0000 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ma9tT-0001Lf-2b for pgsql-hackers@lists.postgresql.org; Tue, 12 Oct 2021 05:00:07 +0000 Received: by mail-pf1-x433.google.com with SMTP id k26so16596964pfi.5 for ; Mon, 11 Oct 2021 22:00:02 -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=24FxYx+oe29HsB5VJDBkL167F9F89QMMH8rm5SswUMw=; b=lrS1dFp5rPfRp314zl2LXu8uiZV1Qj7VFSJBtnfCbkrWj/gFX5niWJ53FTMh9ZvEoA mCHiwkj57+l4chU0Itx4QLQ3wQ786IFKUSpb9qp2bufNXnWGn4uiYaFvskno+OaRFJGT 2W9OQquiilXK249GslevH9YVhkgZ0F4tnJW9M83kn58hsmd4DMT1KXB8gu5q3wNq6U2j 2ANNJtNxPS+oOliGDMiZ+XKwD3KESs9s1EMLq/V8HTcX+AhKw3LoVQlumEEwn17KWPtF s4DiW9jWmL3IonKtDU/OknHUKfpPx3hkq6Xvscb0S1F75RCzP3ZW5qdKsyk7H3xzXsoh uERw== 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=24FxYx+oe29HsB5VJDBkL167F9F89QMMH8rm5SswUMw=; b=nE3XsVoR7qIH4sxWdDfinH4K4f4J94Dz+KcoF1QfCdrB5Bu//9Di13QaS6mndtk8js 6VSA58knFy/qjzavrG/AxEwoWRvdhZkeWFytofkxYrgUbJpXvI36qjMTR2BY0mVNBwME eGHxUQuIGvkOWhsXJXNY2HZsTO8AJqn6FvEy9h3jkL+I0PKqjqFc1nrjXmwvctxEMogV b09PqWVZLlG4aplHGF0ynS1q6OdKPUqM2np+lF7LS71ZGD2EJOLvCPOJbsbFtASvb61u RrE/SLgbCJUf6IChabSZWsdF74pOX7FJQdAI9Uh4BMQW06uqS9AGe1uDH63UohKuKEzr R5fw== X-Gm-Message-State: AOAM5309zC0Y/JE7pJQj6Eex3KeGuieh6uDniGKPBELFvs5BsGEMISBd qf1ooCgQeuhJbV/54axJ8Y1P7L96gZs= X-Google-Smtp-Source: ABdhPJxGy0OnZVVUkCdWzPkgzCmG9rKqEdaj0SXy7d/2WLJU9B99lhRP6RHJcR237hs8EmA5J4ziIA== X-Received: by 2002:a63:8f4c:: with SMTP id r12mr318294pgn.0.1634014802016; Mon, 11 Oct 2021 22:00:02 -0700 (PDT) Received: from localhost (KD036014041111.ppp-bb.dion.ne.jp. [36.14.41.111]) by smtp.gmail.com with ESMTPSA id p9sm10256864pfh.162.2021.10.11.22.00.00 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 11 Oct 2021 22:00:01 -0700 (PDT) Date: Tue, 12 Oct 2021 13:59:59 +0900 (JST) Message-Id: <20211012.135959.877910916353346602.horikyota.ntt@gmail.com> To: dilipbalaut@gmail.com Cc: pgsql-hackers@lists.postgresql.org Subject: Re: Error "initial slot snapshot too large" in create replication slot From: Kyotaro Horiguchi In-Reply-To: References: <20211011.195937.2061830189397708214.horikyota.ntt@gmail.com> User-Agent: Mew version 6.8 on Emacs 26.1 Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Tue_Oct_12_13_59_59_2021_346)--" Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ----Next_Part(Tue_Oct_12_13_59_59_2021_346)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit At Mon, 11 Oct 2021 16:48:10 +0530, Dilip Kumar wrote in > On Mon, Oct 11, 2021 at 4:29 PM Kyotaro Horiguchi > wrote: > > > > At Mon, 11 Oct 2021 11:49:41 +0530, Dilip Kumar wrote in > > > While creating an "export snapshot" I don't see any protection why the > > > number of xids in the snapshot can not cross the > > > "GetMaxSnapshotXidCount()"?. > > > > > > Basically, while converting the HISTORIC snapshot to the MVCC snapshot > > > in "SnapBuildInitialSnapshot()", we add all the xids between > > > snap->xmin to snap->xmax to the MVCC snap->xip array (xids for which > > > commit were not recorded). The problem is that we add both topxids as > > > well as the subxids into the same array and expect that the "xid" > > > count does not cross the "GetMaxSnapshotXidCount()". So it seems like > > > an issue but I am not sure what is the fix for this, some options are > > > > It seems to me that it is a compromise between the restriction of the > > legitimate snapshot and snapshots created by snapbuild. If the xids > > overflow, the resulting snapshot may lose a siginificant xid, i.e, a > > top-level xid. > > > > > a) Don't limit the xid count in the exported snapshot and dynamically > > > resize the array b) Increase the limit to GetMaxSnapshotXidCount() + > > > GetMaxSnapshotSubxidCount(). But in option b) there would still be a > > > problem that how do we handle the overflowed subtransaction? > > > > I'm afraid that we shouldn't expand the size limits. If I understand > > it correctly, we only need the top-level xids in the exported snapshot > > But since we are using this as an MVCC snapshot, if we don't have the > subxid and if we also don't mark the "suboverflowed" flag then IMHO > the sub-transaction visibility might be wrong, Am I missing something? Sorry I should have set suboverflowed in the generated snapshot. However, we can store subxid list as well when the snapshot (or running_xact) is not overflown. These (should) works the same way. On physical standby, snapshot is created just filling up only subxip with all top and sub xids (procrray.c:2400). It would be better we do the same thing here. > > and reorder buffer knows whether a xid is a top-level or not after > > establishing a consistent snapshot. > > > > The attached diff tries to make SnapBuildInitialSnapshot exclude > > subtransaction from generated snapshots. It seems working fine for > > you repro. (Of course, I'm not confident that it is the correct thing, > > though..) > > > > What do you think about this? > > If your statement that we only need top-xids in the exported snapshot, > is true then this fix looks fine to me. If not then we might need to > add the sub-xids in the snapshot->subxip array and if it crosses the > limit of GetMaxSnapshotSubxidCount(), then we can mark "suboverflowed" > flag. So I came up with the attached version. regards. -- Kyotaro Horiguchi NTT Open Source Software Center ----Next_Part(Tue_Oct_12_13_59_59_2021_346)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="0001-Allow-overflowed-snapshot-when-creating-logical-repl.patch"