From: Peter Eisentraut <peter_e@gmx.net>
To: Michael Paquier <michael.paquier@gmail.com>
Cc: PostgreSQL mailing lists <pgsql-bugs@postgresql.org>
Cc: Heikki Linnakangas <hlinnaka@iki.fi>
Subject: Re: pg_rewind exiting with error code 1 when source and target are on the same timeline
Date: Thu, 3 Dec 2015 22:22:31 -0500
Message-ID: <566106F7.4000404@gmx.net> (raw)
In-Reply-To: <CAB7nPqTZ2gnBKmNn+hzUry5Xi9=bYBoTAcMYASBnwNYH884u+A@mail.gmail.com>
References: <CAB7nPqSyLo4Jzp7-2hJh24YEU99tspkWj7vtj7NYTGcXasw2hg@mail.gmail.com>
<5627E2A4.4000402@gmx.net>
<CAB7nPqTZ2gnBKmNn+hzUry5Xi9=bYBoTAcMYASBnwNYH884u+A@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
On 10/22/15 1:42 AM, Michael Paquier wrote:
> I am not sure that I am not getting completely your point, why would
> it be a win to remove this safety check? We surely do not want to look
> for the common ancestor timeline if the target and source nodes have
> the same timeline, so we should not remove this check and just set
> rewind_needed to false to fallback to the same exit(0) for all those
> code paths. Per se the attached for example.
After playing with this a bit, I think your patch is correct. The code
has drifted a bit in the meantime, so attached is an updated patch.
Your patch added variable initializations for divergerec and
lastcommontli. Was that to avoid compiler warnings about uninitialized
variables? I didn't get these here. If that's the issue, maybe these
initializations should be moved to the if (same timeline) branch, to get
it a bit closer to the action.
I also added a test for this case. (It would currently fail.)
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugsAttachments:0001-pg_rewind-Don-t-error-if-the-two-clusters-are-alread.patch (application/x-patch, 3.8K) download
From fc481dd3310782061f1b4cb638ce1a7286b66728 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 3 Dec 2015 22:21:16 -0500
Subject: [PATCH] pg_rewind: Don't error if the two clusters are already on the
same timeline
This previously resulted in an error and a nonzero exit status, but
after discussion this should rather be a noop with a zero exit status.
---
src/bin/pg_rewind/pg_rewind.c | 59 +++++++++++++++++---------------
src/bin/pg_rewind/t/005_same_timeline.pl | 14 ++++++++
2 files changed, 46 insertions(+), 27 deletions(-)
create mode 100644 src/bin/pg_rewind/t/005_same_timeline.pl
diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.cindex 1ab82f0..635a3ab 100644--- a/src/bin/pg_rewind/pg_rewind.c+++ b/src/bin/pg_rewind/pg_rewind.c@@ -216,41 +216,46 @@ main(int argc, char **argv)
* do.
*/
if (ControlFile_target.checkPointCopy.ThisTimeLineID == ControlFile_source.checkPointCopy.ThisTimeLineID)
- pg_fatal("source and target cluster are on the same timeline\n");-- findCommonAncestorTimeline(&divergerec, &lastcommontliIndex);- printf(_("servers diverged at WAL position %X/%X on timeline %u\n"),- (uint32) (divergerec >> 32), (uint32) divergerec,- targetHistory[lastcommontliIndex].tli);-- /*- * Check for the possibility that the target is in fact a direct ancestor- * of the source. In that case, there is no divergent history in the- * target that needs rewinding.- */- if (ControlFile_target.checkPoint >= divergerec)
{
- rewind_needed = true;+ printf(_("source and target cluster are on the same timeline\n"));+ rewind_needed = false;
}
else
{
- XLogRecPtr chkptendrec;-- /* Read the checkpoint record on the target to see where it ends. */- chkptendrec = readOneRecord(datadir_target,- ControlFile_target.checkPoint,- targetNentries - 1);+ findCommonAncestorTimeline(&divergerec, &lastcommontliIndex);+ printf(_("servers diverged at WAL position %X/%X on timeline %u\n"),+ (uint32) (divergerec >> 32), (uint32) divergerec,+ targetHistory[lastcommontliIndex].tli);
/*
- * If the histories diverged exactly at the end of the shutdown- * checkpoint record on the target, there are no WAL records in the- * target that don't belong in the source's history, and no rewind is- * needed.+ * Check for the possibility that the target is in fact a direct ancestor+ * of the source. In that case, there is no divergent history in the+ * target that needs rewinding.
*/
- if (chkptendrec == divergerec)- rewind_needed = false;- else+ if (ControlFile_target.checkPoint >= divergerec)+ {
rewind_needed = true;
+ }+ else+ {+ XLogRecPtr chkptendrec;++ /* Read the checkpoint record on the target to see where it ends. */+ chkptendrec = readOneRecord(datadir_target,+ ControlFile_target.checkPoint,+ targetNentries - 1);++ /*+ * If the histories diverged exactly at the end of the shutdown+ * checkpoint record on the target, there are no WAL records in the+ * target that don't belong in the source's history, and no rewind is+ * needed.+ */+ if (chkptendrec == divergerec)+ rewind_needed = false;+ else+ rewind_needed = true;+ }
}
if (!rewind_needed)
diff --git a/src/bin/pg_rewind/t/005_same_timeline.pl b/src/bin/pg_rewind/t/005_same_timeline.plnew file mode 100644index 0000000..8ca4426--- /dev/null+++ b/src/bin/pg_rewind/t/005_same_timeline.pl@@ -0,0 +1,14 @@+use strict;+use warnings;+use TestLib;+use Test::More tests => 1;++use RewindTest;++# Test that running pg_rewind if the two clusters are on the same+# timeline runs successfully.++RewindTest::setup_cluster();+RewindTest::start_master();+RewindTest::create_standby();+RewindTest::run_pg_rewind('local');--
2.6.3
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: peter_e@gmx.net, michael.paquier@gmail.com, hlinnaka@iki.fi
Subject: Re: pg_rewind exiting with error code 1 when source and target are on the same timeline
In-Reply-To: <566106F7.4000404@gmx.net>
References: <CAB7nPqSyLo4Jzp7-2hJh24YEU99tspkWj7vtj7NYTGcXasw2hg@mail.gmail.com> <5627E2A4.4000402@gmx.net> <CAB7nPqTZ2gnBKmNn+hzUry5Xi9=bYBoTAcMYASBnwNYH884u+A@mail.gmail.com> <566106F7.4000404@gmx.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox