pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix bug leading to restoring unlogged relations from empty files
10+ messages / 4 participants
[nested] [flat]

* pgsql: Fix bug leading to restoring unlogged relations from empty files
@ 2015-12-10 15:50 Andres Freund <andres@anarazel.de>
  2015-12-13 17:37 ` Re: pgsql: Fix bug leading to restoring unlogged relations from empty files Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 10+ messages in thread

From: Andres Freund @ 2015-12-10 15:50 UTC (permalink / raw)
  To: pgsql-committers

Fix bug leading to restoring unlogged relations from empty files.

At the end of crash recovery, unlogged relations are reset to the empty
state, using their init fork as the template. The init fork is copied to
the main fork without going through shared buffers. Unfortunately WAL
replay so far has not necessarily flushed writes from shared buffers to
disk at that point. In normal crash recovery, and before the
introduction of 'fast promotions' in fd4ced523 / 9.3, the
END_OF_RECOVERY checkpoint flushes the buffers out in time. But with
fast promotions that's not the case anymore.

To fix, force WAL writes targeting the init fork to be flushed
immediately (using the new FlushOneBuffer() function). In 9.5+ that
flush can centrally be triggered from the code dealing with restoring
full page writes (XLogReadBufferForRedoExtended), in earlier releases
that responsibility is in the hands of XLOG_HEAP_NEWPAGE's replay
function.

Backpatch to 9.1, even if this currently is only known to trigger in
9.3+. Flushing earlier is more robust, and it is advantageous to keep
the branches similar.

Typical symptoms of this bug are errors like
'ERROR:  index "..." contains unexpected zero page at block 0'
shortly after promoting a node.

Reported-By: Thom Brown
Author: Andres Freund and Michael Paquier
Discussion: 20150326175024.GJ451@alap3.anarazel.de
Backpatch: 9.1-

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/e3f4cfc7aa33f40b2b283676c9f0d5bf7ef08ccd

Modified Files
--------------
src/backend/access/transam/xlogutils.c |    9 +++++++++
src/backend/storage/buffer/bufmgr.c    |   21 +++++++++++++++++++++
src/include/storage/bufmgr.h           |    1 +
3 files changed, 31 insertions(+)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: pgsql: Fix bug leading to restoring unlogged relations from empty files
  2015-12-10 15:50 pgsql: Fix bug leading to restoring unlogged relations from empty files Andres Freund <andres@anarazel.de>
@ 2015-12-13 17:37 ` Tom Lane <tgl@sss.pgh.pa.us>
  2015-12-13 17:57   ` Re: pgsql: Fix bug leading to restoring unlogged relations from empty files Andres Freund <andres@anarazel.de>
  0 siblings, 1 reply; 10+ messages in thread

From: Tom Lane @ 2015-12-13 17:37 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: pgsql-committers

Andres Freund <andres@anarazel.de> writes:
> Fix bug leading to restoring unlogged relations from empty files.

Coverity thinks, quite correctly AFAICS, that this line you wrote in
FlushOneBuffer() is useless:

	LWLockHeldByMe(bufHdr->content_lock);

Perhaps you meant

	Assert(LWLockHeldByMe(bufHdr->content_lock));

?

			regards, tom lane


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: pgsql: Fix bug leading to restoring unlogged relations from empty files
  2015-12-10 15:50 pgsql: Fix bug leading to restoring unlogged relations from empty files Andres Freund <andres@anarazel.de>
  2015-12-13 17:37 ` Re: pgsql: Fix bug leading to restoring unlogged relations from empty files Tom Lane <tgl@sss.pgh.pa.us>
@ 2015-12-13 17:57   ` Andres Freund <andres@anarazel.de>
  0 siblings, 0 replies; 10+ messages in thread

From: Andres Freund @ 2015-12-13 17:57 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-committers

On 2015-12-13 12:37:18 -0500, Tom Lane wrote:
> Andres Freund <andres@anarazel.de> writes:
> > Fix bug leading to restoring unlogged relations from empty files.
> 
> Coverity thinks, quite correctly AFAICS, that this line you wrote in
> FlushOneBuffer() is useless:
> 
> 	LWLockHeldByMe(bufHdr->content_lock);
> 
> Perhaps you meant
> 
> 	Assert(LWLockHeldByMe(bufHdr->content_lock));
> 

Yes :(. I'll be back at my computer in a couple hours and will fix it
then or tomorrow morning.

Andres


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* pgsql: Fix bug leading to restoring unlogged relations from empty files
@ 2015-12-10 15:50 Andres Freund <andres@anarazel.de>
  2015-12-14 05:26 ` Re: pgsql: Fix bug leading to restoring unlogged relations from empty files Peter Eisentraut <peter_e@gmx.net>
  0 siblings, 1 reply; 10+ messages in thread

From: Andres Freund @ 2015-12-10 15:50 UTC (permalink / raw)
  To: pgsql-committers

Fix bug leading to restoring unlogged relations from empty files.

At the end of crash recovery, unlogged relations are reset to the empty
state, using their init fork as the template. The init fork is copied to
the main fork without going through shared buffers. Unfortunately WAL
replay so far has not necessarily flushed writes from shared buffers to
disk at that point. In normal crash recovery, and before the
introduction of 'fast promotions' in fd4ced523 / 9.3, the
END_OF_RECOVERY checkpoint flushes the buffers out in time. But with
fast promotions that's not the case anymore.

To fix, force WAL writes targeting the init fork to be flushed
immediately (using the new FlushOneBuffer() function). In 9.5+ that
flush can centrally be triggered from the code dealing with restoring
full page writes (XLogReadBufferForRedoExtended), in earlier releases
that responsibility is in the hands of XLOG_HEAP_NEWPAGE's replay
function.

Backpatch to 9.1, even if this currently is only known to trigger in
9.3+. Flushing earlier is more robust, and it is advantageous to keep
the branches similar.

Typical symptoms of this bug are errors like
'ERROR:  index "..." contains unexpected zero page at block 0'
shortly after promoting a node.

Reported-By: Thom Brown
Author: Andres Freund and Michael Paquier
Discussion: 20150326175024.GJ451@alap3.anarazel.de
Backpatch: 9.1-

Branch
------
REL9_5_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/5b51805fe4b9fec95274924c5733093a5f685a58

Modified Files
--------------
src/backend/access/transam/xlogutils.c |    9 +++++++++
src/backend/storage/buffer/bufmgr.c    |   21 +++++++++++++++++++++
src/include/storage/bufmgr.h           |    1 +
3 files changed, 31 insertions(+)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: pgsql: Fix bug leading to restoring unlogged relations from empty files
  2015-12-10 15:50 pgsql: Fix bug leading to restoring unlogged relations from empty files Andres Freund <andres@anarazel.de>
@ 2015-12-14 05:26 ` Peter Eisentraut <peter_e@gmx.net>
  2015-12-14 05:43   ` Re: pgsql: Fix bug leading to restoring unlogged relations from empty files Michael Paquier <michael.paquier@gmail.com>
  0 siblings, 1 reply; 10+ messages in thread

From: Peter Eisentraut @ 2015-12-14 05:26 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; pgsql-committers

Coverity is complaining that in

void
FlushOneBuffer(Buffer buffer)
{
    BufferDesc *bufHdr;

    /* currently not needed, but no fundamental reason not to support */
    Assert(!BufferIsLocal(buffer));

    Assert(BufferIsPinned(buffer));

    bufHdr = GetBufferDescriptor(buffer - 1);

    LWLockHeldByMe(bufHdr->content_lock);

    FlushBuffer(bufHdr, NULL);
}

the call to LWLockHeldByMe() is useless.


On 12/10/15 10:50 AM, Andres Freund wrote:
> Fix bug leading to restoring unlogged relations from empty files.
> 
> At the end of crash recovery, unlogged relations are reset to the empty
> state, using their init fork as the template. The init fork is copied to
> the main fork without going through shared buffers. Unfortunately WAL
> replay so far has not necessarily flushed writes from shared buffers to
> disk at that point. In normal crash recovery, and before the
> introduction of 'fast promotions' in fd4ced523 / 9.3, the
> END_OF_RECOVERY checkpoint flushes the buffers out in time. But with
> fast promotions that's not the case anymore.
> 
> To fix, force WAL writes targeting the init fork to be flushed
> immediately (using the new FlushOneBuffer() function). In 9.5+ that
> flush can centrally be triggered from the code dealing with restoring
> full page writes (XLogReadBufferForRedoExtended), in earlier releases
> that responsibility is in the hands of XLOG_HEAP_NEWPAGE's replay
> function.
> 
> Backpatch to 9.1, even if this currently is only known to trigger in
> 9.3+. Flushing earlier is more robust, and it is advantageous to keep
> the branches similar.
> 
> Typical symptoms of this bug are errors like
> 'ERROR:  index "..." contains unexpected zero page at block 0'
> shortly after promoting a node.
> 
> Reported-By: Thom Brown
> Author: Andres Freund and Michael Paquier
> Discussion: 20150326175024.GJ451@alap3.anarazel.de
> Backpatch: 9.1-
> 
> Branch
> ------
> REL9_5_STABLE
> 
> Details
> -------
> http://git.postgresql.org/pg/commitdiff/5b51805fe4b9fec95274924c5733093a5f685a58
> 
> Modified Files
> --------------
> src/backend/access/transam/xlogutils.c |    9 +++++++++
> src/backend/storage/buffer/bufmgr.c    |   21 +++++++++++++++++++++
> src/include/storage/bufmgr.h           |    1 +
> 3 files changed, 31 insertions(+)
> 
> 



-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: pgsql: Fix bug leading to restoring unlogged relations from empty files
  2015-12-10 15:50 pgsql: Fix bug leading to restoring unlogged relations from empty files Andres Freund <andres@anarazel.de>
  2015-12-14 05:26 ` Re: pgsql: Fix bug leading to restoring unlogged relations from empty files Peter Eisentraut <peter_e@gmx.net>
@ 2015-12-14 05:43   ` Michael Paquier <michael.paquier@gmail.com>
  0 siblings, 0 replies; 10+ messages in thread

From: Michael Paquier @ 2015-12-14 05:43 UTC (permalink / raw)
  To: Peter Eisentraut <peter_e@gmx.net>; +Cc: Andres Freund <andres@anarazel.de>; pgsql-committers

On Mon, Dec 14, 2015 at 2:26 PM, Peter Eisentraut <peter_e@gmx.net> wrote:
> the call to LWLockHeldByMe() is useless.

Yes, but it should be an Assert. I guess that Andres is on it..
-- 
Michael


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* pgsql: Fix bug leading to restoring unlogged relations from empty files
@ 2015-12-10 15:50 Andres Freund <andres@anarazel.de>
  0 siblings, 0 replies; 10+ messages in thread

From: Andres Freund @ 2015-12-10 15:50 UTC (permalink / raw)
  To: pgsql-committers

Fix bug leading to restoring unlogged relations from empty files.

At the end of crash recovery, unlogged relations are reset to the empty
state, using their init fork as the template. The init fork is copied to
the main fork without going through shared buffers. Unfortunately WAL
replay so far has not necessarily flushed writes from shared buffers to
disk at that point. In normal crash recovery, and before the
introduction of 'fast promotions' in fd4ced523 / 9.3, the
END_OF_RECOVERY checkpoint flushes the buffers out in time. But with
fast promotions that's not the case anymore.

To fix, force WAL writes targeting the init fork to be flushed
immediately (using the new FlushOneBuffer() function). In 9.5+ that
flush can centrally be triggered from the code dealing with restoring
full page writes (XLogReadBufferForRedoExtended), in earlier releases
that responsibility is in the hands of XLOG_HEAP_NEWPAGE's replay
function.

Backpatch to 9.1, even if this currently is only known to trigger in
9.3+. Flushing earlier is more robust, and it is advantageous to keep
the branches similar.

Typical symptoms of this bug are errors like
'ERROR:  index "..." contains unexpected zero page at block 0'
shortly after promoting a node.

Reported-By: Thom Brown
Author: Andres Freund and Michael Paquier
Discussion: 20150326175024.GJ451@alap3.anarazel.de
Backpatch: 9.1-

Branch
------
REL9_4_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/c6a67bbc7077f652b59c79c2dd5bf9774755db48

Modified Files
--------------
src/backend/access/heap/heapam.c    |   10 ++++++++++
src/backend/storage/buffer/bufmgr.c |   21 +++++++++++++++++++++
src/include/storage/bufmgr.h        |    1 +
3 files changed, 32 insertions(+)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* pgsql: Fix bug leading to restoring unlogged relations from empty files
@ 2015-12-10 15:50 Andres Freund <andres@anarazel.de>
  0 siblings, 0 replies; 10+ messages in thread

From: Andres Freund @ 2015-12-10 15:50 UTC (permalink / raw)
  To: pgsql-committers

Fix bug leading to restoring unlogged relations from empty files.

At the end of crash recovery, unlogged relations are reset to the empty
state, using their init fork as the template. The init fork is copied to
the main fork without going through shared buffers. Unfortunately WAL
replay so far has not necessarily flushed writes from shared buffers to
disk at that point. In normal crash recovery, and before the
introduction of 'fast promotions' in fd4ced523 / 9.3, the
END_OF_RECOVERY checkpoint flushes the buffers out in time. But with
fast promotions that's not the case anymore.

To fix, force WAL writes targeting the init fork to be flushed
immediately (using the new FlushOneBuffer() function). In 9.5+ that
flush can centrally be triggered from the code dealing with restoring
full page writes (XLogReadBufferForRedoExtended), in earlier releases
that responsibility is in the hands of XLOG_HEAP_NEWPAGE's replay
function.

Backpatch to 9.1, even if this currently is only known to trigger in
9.3+. Flushing earlier is more robust, and it is advantageous to keep
the branches similar.

Typical symptoms of this bug are errors like
'ERROR:  index "..." contains unexpected zero page at block 0'
shortly after promoting a node.

Reported-By: Thom Brown
Author: Andres Freund and Michael Paquier
Discussion: 20150326175024.GJ451@alap3.anarazel.de
Backpatch: 9.1-

Branch
------
REL9_3_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/b19405a44b1e5d5c59f00763d2f2d8da0ea32368

Modified Files
--------------
src/backend/access/heap/heapam.c    |   10 ++++++++++
src/backend/storage/buffer/bufmgr.c |   21 +++++++++++++++++++++
src/include/storage/bufmgr.h        |    1 +
3 files changed, 32 insertions(+)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* pgsql: Fix bug leading to restoring unlogged relations from empty files
@ 2015-12-10 15:50 Andres Freund <andres@anarazel.de>
  0 siblings, 0 replies; 10+ messages in thread

From: Andres Freund @ 2015-12-10 15:50 UTC (permalink / raw)
  To: pgsql-committers

Fix bug leading to restoring unlogged relations from empty files.

At the end of crash recovery, unlogged relations are reset to the empty
state, using their init fork as the template. The init fork is copied to
the main fork without going through shared buffers. Unfortunately WAL
replay so far has not necessarily flushed writes from shared buffers to
disk at that point. In normal crash recovery, and before the
introduction of 'fast promotions' in fd4ced523 / 9.3, the
END_OF_RECOVERY checkpoint flushes the buffers out in time. But with
fast promotions that's not the case anymore.

To fix, force WAL writes targeting the init fork to be flushed
immediately (using the new FlushOneBuffer() function). In 9.5+ that
flush can centrally be triggered from the code dealing with restoring
full page writes (XLogReadBufferForRedoExtended), in earlier releases
that responsibility is in the hands of XLOG_HEAP_NEWPAGE's replay
function.

Backpatch to 9.1, even if this currently is only known to trigger in
9.3+. Flushing earlier is more robust, and it is advantageous to keep
the branches similar.

Typical symptoms of this bug are errors like
'ERROR:  index "..." contains unexpected zero page at block 0'
shortly after promoting a node.

Reported-By: Thom Brown
Author: Andres Freund and Michael Paquier
Discussion: 20150326175024.GJ451@alap3.anarazel.de
Backpatch: 9.1-

Branch
------
REL9_2_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/2de281da212e16ea198f0c8e3165a4d67fe5e7a4

Modified Files
--------------
src/backend/access/heap/heapam.c    |   10 ++++++++++
src/backend/storage/buffer/bufmgr.c |   21 +++++++++++++++++++++
src/include/storage/bufmgr.h        |    1 +
3 files changed, 32 insertions(+)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* pgsql: Fix bug leading to restoring unlogged relations from empty files
@ 2015-12-10 15:50 Andres Freund <andres@anarazel.de>
  0 siblings, 0 replies; 10+ messages in thread

From: Andres Freund @ 2015-12-10 15:50 UTC (permalink / raw)
  To: pgsql-committers

Fix bug leading to restoring unlogged relations from empty files.

At the end of crash recovery, unlogged relations are reset to the empty
state, using their init fork as the template. The init fork is copied to
the main fork without going through shared buffers. Unfortunately WAL
replay so far has not necessarily flushed writes from shared buffers to
disk at that point. In normal crash recovery, and before the
introduction of 'fast promotions' in fd4ced523 / 9.3, the
END_OF_RECOVERY checkpoint flushes the buffers out in time. But with
fast promotions that's not the case anymore.

To fix, force WAL writes targeting the init fork to be flushed
immediately (using the new FlushOneBuffer() function). In 9.5+ that
flush can centrally be triggered from the code dealing with restoring
full page writes (XLogReadBufferForRedoExtended), in earlier releases
that responsibility is in the hands of XLOG_HEAP_NEWPAGE's replay
function.

Backpatch to 9.1, even if this currently is only known to trigger in
9.3+. Flushing earlier is more robust, and it is advantageous to keep
the branches similar.

Typical symptoms of this bug are errors like
'ERROR:  index "..." contains unexpected zero page at block 0'
shortly after promoting a node.

Reported-By: Thom Brown
Author: Andres Freund and Michael Paquier
Discussion: 20150326175024.GJ451@alap3.anarazel.de
Backpatch: 9.1-

Branch
------
REL9_1_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/3199c13fcc34ee79bc26cac17204e93cdc4a756f

Modified Files
--------------
src/backend/access/heap/heapam.c    |   10 ++++++++++
src/backend/storage/buffer/bufmgr.c |   21 +++++++++++++++++++++
src/include/storage/bufmgr.h        |    1 +
3 files changed, 32 insertions(+)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 10+ messages in thread


end of thread, other threads:[~2015-12-14 05:43 UTC | newest]

Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-12-10 15:50 pgsql: Fix bug leading to restoring unlogged relations from empty files Andres Freund <andres@anarazel.de>
2015-12-13 17:37 ` Tom Lane <tgl@sss.pgh.pa.us>
2015-12-13 17:57   ` Andres Freund <andres@anarazel.de>
2015-12-10 15:50 pgsql: Fix bug leading to restoring unlogged relations from empty files Andres Freund <andres@anarazel.de>
2015-12-14 05:26 ` Peter Eisentraut <peter_e@gmx.net>
2015-12-14 05:43   ` Michael Paquier <michael.paquier@gmail.com>
2015-12-10 15:50 pgsql: Fix bug leading to restoring unlogged relations from empty files Andres Freund <andres@anarazel.de>
2015-12-10 15:50 pgsql: Fix bug leading to restoring unlogged relations from empty files Andres Freund <andres@anarazel.de>
2015-12-10 15:50 pgsql: Fix bug leading to restoring unlogged relations from empty files Andres Freund <andres@anarazel.de>
2015-12-10 15:50 pgsql: Fix bug leading to restoring unlogged relations from empty files Andres Freund <andres@anarazel.de>

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