Re: updateMinRecoveryPoint bug?

Lists: pgsql-hackers
From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>, Simon Riggs <simon(at)2ndquadrant(dot)com>
Subject: updateMinRecoveryPoint bug?
Date: 2009-12-24 04:34:58
Message-ID: 3f0b79eb0912232034v2bac975bu5999aa54ed4fa0b1@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

In UpdateMinRecoveryPoint() and XLogNeedsFlush(), updateMinRecoveryPoint
is used for us to short-circuit future checks only during a crash recovery.
But it doesn't seem to play its role in a crash recovery that follows an
archive recovery. Because such crash recovery always starts from *valid*
minRecoveryPoint, i.e., updateMinRecoveryPoint is never set to FALSE.

How about always resetting ControlFile->minRecoveryPoint to {0, 0} at the
beginning of a crash recovery, to fix the bug?

Regards,

--
Fujii Masao
NIPPON TELEGRAPH AND TELEPHONE CORPORATION
NTT Open Source Software Center


From: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Simon Riggs <simon(at)2ndquadrant(dot)com>
Subject: Re: updateMinRecoveryPoint bug?
Date: 2009-12-28 12:40:56
Message-ID: 4B38A758.8020708@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Fujii Masao wrote:
> In UpdateMinRecoveryPoint() and XLogNeedsFlush(), updateMinRecoveryPoint
> is used for us to short-circuit future checks only during a crash recovery.
> But it doesn't seem to play its role in a crash recovery that follows an
> archive recovery. Because such crash recovery always starts from *valid*
> minRecoveryPoint, i.e., updateMinRecoveryPoint is never set to FALSE.

Hmm, so the problem is:

1. Restore from archive. End archive recovery, creating a new
checkpoint. But we still write the old minRecoveryPoint value to pg_control

2. Crash. minRecoveryPoint is still set in crash recovery

Yeah, that should be fixed. Otherwise we will merrily start up after
crash, even if we don't reach the end of WAL. Although that shouldn't
happen, it's a bit disconcerting.

> How about always resetting ControlFile->minRecoveryPoint to {0, 0} at the
> beginning of a crash recovery, to fix the bug?

Yeah, that would work. I think it would be better to clear it in
CreateCheckPoint(), though, when we set the pointer to the new
checkpoint. That includes the shutdown checkpoint created at the end of
archive recovery. minRecoveryPoint should never be set during normal
operation, after all.

--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -6882,6 +6882,7 @@ CreateCheckPoint(int flags)
ControlFile->checkPoint = ProcLastRecPtr;
ControlFile->checkPointCopy = checkPoint;
ControlFile->time = (pg_time_t) time(NULL);
+ MemSet(&ControlFile->minRecoveryPoint, 0, sizeof(XLogRecPtr));
UpdateControlFile();
LWLockRelease(ControlFileLock);

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com


From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
Cc: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: updateMinRecoveryPoint bug?
Date: 2009-12-28 16:14:12
Message-ID: 1262016852.18116.4384.camel@ebony
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, 2009-12-28 at 14:40 +0200, Heikki Linnakangas wrote:
> Fujii Masao wrote:

> > How about always resetting ControlFile->minRecoveryPoint to {0, 0} at the
> > beginning of a crash recovery, to fix the bug?
>
> Yeah, that would work. I think it would be better to clear it in
> CreateCheckPoint(), though, when we set the pointer to the new
> checkpoint. That includes the shutdown checkpoint created at the end of
> archive recovery. minRecoveryPoint should never be set during normal
> operation, after all.

Sounds better.

--
Simon Riggs www.2ndQuadrant.com


From: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
To: Simon Riggs <simon(at)2ndQuadrant(dot)com>
Cc: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: updateMinRecoveryPoint bug?
Date: 2009-12-30 08:37:39
Message-ID: 4B3B1153.50601@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Simon Riggs wrote:
> On Mon, 2009-12-28 at 14:40 +0200, Heikki Linnakangas wrote:
>> Fujii Masao wrote:
>
>>> How about always resetting ControlFile->minRecoveryPoint to {0, 0} at the
>>> beginning of a crash recovery, to fix the bug?
>> Yeah, that would work. I think it would be better to clear it in
>> CreateCheckPoint(), though, when we set the pointer to the new
>> checkpoint. That includes the shutdown checkpoint created at the end of
>> archive recovery. minRecoveryPoint should never be set during normal
>> operation, after all.
>
> Sounds better.

Committed.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com