Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gSkDC-0006eR-9P for pgsql-hackers@arkaria.postgresql.org; Fri, 30 Nov 2018 14:56:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gSkDA-0000Pj-UP for pgsql-hackers@arkaria.postgresql.org; Fri, 30 Nov 2018 14:56:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gSkDA-0000Pc-Jx for pgsql-hackers@lists.postgresql.org; Fri, 30 Nov 2018 14:56:08 +0000 Received: from mail-ot1-x342.google.com ([2607:f8b0:4864:20::342]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gSkD3-0007mJ-CJ for pgsql-hackers@lists.postgresql.org; Fri, 30 Nov 2018 14:56:08 +0000 Received: by mail-ot1-x342.google.com with SMTP id i20so5349250otl.0 for ; Fri, 30 Nov 2018 06:56:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=SQm26vYAahKxe6uSOBFtlWDAMJLcdye8XK4Vjma2S7Q=; b=SOnqFjCnptm+mEHerfJqASksQxCnmlVwuDVLKWDQGx1mG6K+ab/xO5QYY00aOCVaSY vkI4GHfNVr4C9QsKOFN9Qv5dzb9erEoHRUhXrLnabvGjJCa5xz05nkvbkDVOaLC385Wp /4gwHk2fLkKa30GUzxrgG4tLN+N6Id2vdVzVZDFqurIoPDZHiOfJlFgg5jy0opZ4leeL AkrEH/xswvZD5eVDZU4705OzgTDB03I+Zy+dIwuY+KS9MYcYCKYFXzpU+JU8598t8VWt 3nh9dGoJ8FMkyDhXO4BHu5QwMUwukSj8Gppvs9Hq9AnJMx0vm+Q5SlzXe04pVdFdaege TAaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=SQm26vYAahKxe6uSOBFtlWDAMJLcdye8XK4Vjma2S7Q=; b=chLnWoNrBV9omuGfL10oB8TOvUfc1/FXZhEHg//j+36VkQutIJbuj5XSHKe7+lQlYi M2xDPJzAjTwgQKIi8idhLm0vhqMlMi292/fRiqMfh3W0O3RHVRYYeH4fdhlB06yOSD3D O5OvlHhKISkrP6Uv+KE9AD1iJMU6Gtb20FLjzfwJBBHWSGtMFUJSouZTmoQTTJGBWweT 81BwvbIIpUOaYXslgIowq+A7hInB+JYCaJ3MOlFqsAnDFQwlNrnidirjegKVE5A1BZxl Vzcdd7zCVjnwAwlHI40u5lKUQRjptAwXCcD/H4oOjYZA3vKQlwAenVfpx6eRgihuDPod WDfQ== X-Gm-Message-State: AA+aEWY0sqOf1FO1h+PfnhqigyfIoNof9O1Yz3Q5cPRsNn/cLMqDu2Me DL+VKYJaMY6PwAjYbUJhgPdjs0Mz0XE0N94STFbeag== X-Google-Smtp-Source: AFSGD/U+ITgiGWpKUsmR0zVQDy+HaIpUPAwlu+tsTlGqIVniXS0ePF/FkEctsJdqB38V3DA0XDRRxG8fv9AvvSAe8Ro= X-Received: by 2002:a05:6830:1115:: with SMTP id w21mr3603355otq.316.1543589758955; Fri, 30 Nov 2018 06:55:58 -0800 (PST) MIME-Version: 1.0 References: <20181022174155.wxxu2qt3bcrbrqy5@alap3.anarazel.de> <20181022221538.d73yxdypbmmzmi2l@alvherre.pgsql> <20181023014338.GA1658@paquier.xyz> <20181101060911.GG1727@paquier.xyz> In-Reply-To: <20181101060911.GG1727@paquier.xyz> From: Simon Riggs Date: Fri, 30 Nov 2018 14:55:47 +0000 Message-ID: Subject: Re: pgsql: Avoid duplicate XIDs at recovery when building initial snapshot To: Michael Paquier Cc: Alvaro Herrera , Andres Freund , PostgreSQL Hackers Content-Type: multipart/alternative; boundary="000000000000430d51057be2ff05" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --000000000000430d51057be2ff05 Content-Type: text/plain; charset="UTF-8" On Thu, 1 Nov 2018 at 06:09, Michael Paquier wrote: > On Tue, Oct 23, 2018 at 10:43:38AM +0900, Michael Paquier wrote: > > Well, following the same kind of thoughts, txid_current_snapshot() uses > > sort_snapshot() to remove all the duplicates after fetching its data > > from GetSnapshotData(), so wouldn't we want to do something about > > removal of duplicates if dummy PGXACT entries are found while scanning > > the ProcArray also in this case? What I would think we should do is not > > only to patch GetRunningTransactionData() but also GetSnapshotData() so > > as we don't have duplicates also in this case, and do things in such a > > way that both code paths use the same logic, and that we don't need to > > have sort_snapshot() anymore. That would be more costly though... > > My apologies it took a bit longer than I thought. I got a patch on my > desk for a couple of days, and finally took the time to finish something > which would address the concerns raised here. As long as we don't reach > more than hundreds of thousands of entries, there is not going to be any > performance impact. So what I do in the attached is to revert 1df21ddb, > and then have GetRunningTransactionData() sort the XIDs in the snapshot > and remove duplicates only if at least one dummy proc entry is found > while scanning, for xids and subxids. This way, there is no need to > impact most of the instance deployments with the extra sort/removal > phase as most don't use two-phase transactions. The sorting done at > recovery when initializing the standby snapshot still needs to happen of > course. > > The patch is added to the upcoming CF for review. > 1df21ddb looks OK to me and was simple enough to backpatch safely. Seems excessive to say that the WAL record is corrupt, it just contains duplicates, just as exported snapshots do. There's a few other imprecise things around in WAL, that is why we need the RunningXact data in the first place. So we have a choice of whether to remove the duplicates eagerly or lazily. For GetRunningTransactionData(), we can do eager or lazy, since its not a foreground process. I don't object to changing it to be eager in this path, but this patch is more complex than 1df21ddb and I don't think we should backpatch this change, assuming it is acceptable. This patch doesn't do it, but the suggestion that we touch GetSnapshotData() in the same way so we de-duplicate eagerly is a different matter and would need careful performance testing to ensure we don't slow down 2PC users. -- Simon Riggs http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --000000000000430d51057be2ff05 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Thu, 1 Nov = 2018 at 06:09, Michael Paquier <m= ichael@paquier.xyz> wrote:
On Tue, Oct 23, 2018 at 10:43:38AM +0900, Michael Paquier wrote:
> Well, following the same kind of thoughts, txid_current_snapshot() use= s
> sort_snapshot() to remove all the duplicates after fetching its data > from GetSnapshotData(), so wouldn't we want to do something about<= br> > removal of duplicates if dummy PGXACT entries are found while scanning=
> the ProcArray also in this case?=C2=A0 What I would think we should do= is not
> only to patch GetRunningTransactionData() but also GetSnapshotData() s= o
> as we don't have duplicates also in this case, and do things in su= ch a
> way that both code paths use the same logic, and that we don't nee= d to
> have sort_snapshot() anymore.=C2=A0 That would be more costly though..= .

My apologies it took a bit longer than I thought.=C2=A0 I got a patch on my=
desk for a couple of days, and finally took the time to finish something which would address the concerns raised here.=C2=A0 As long as we don't= reach
more than hundreds of thousands of entries, there is not going to be any performance impact.=C2=A0 So what I do in the attached is to revert 1df21dd= b,
and then have GetRunningTransactionData() sort the XIDs in the snapshot
and remove duplicates only if at least one dummy proc entry is found
while scanning, for xids and subxids.=C2=A0 This way, there is no need to impact most of the instance deployments with the extra sort/removal
phase as most don't use two-phase transactions.=C2=A0 The sorting done = at
recovery when initializing the standby snapshot still needs to happen of course.

The patch is added to the upcoming CF for review.

=
1df21ddb looks OK to me and was simple enough to backpatch safel= y.

Seems excessive to say that the WAL record is c= orrupt, it just contains duplicates, just as exported snapshots do. There&#= 39;s a few other imprecise things around in WAL, that is why we need the Ru= nningXact data in the first place. So we have a choice of whether to remove= the duplicates eagerly or lazily.

For GetRunningT= ransactionData(), we can do eager or lazy, since its not a foreground proce= ss. I don't object to changing it to be eager in this path, but this pa= tch is more complex than 1df21ddb and I don't think=C2=A0we should back= patch this change, assuming it is acceptable.

This= patch doesn't do it, but the suggestion that we touch GetSnapshotData(= ) in the same way so we de-duplicate eagerly is a different matter and woul= d need careful performance testing to ensure we don't slow down 2PC use= rs.

--
Simon Riggs = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0http://www.2ndQuadrant.com/
= PostgreSQL Development, 24x7 Support= , Remote DBA, Training & Services
--000000000000430d51057be2ff05--