OSDN Git Service

Make the visibility map crash-safe.
authorRobert Haas <rhaas@postgresql.org>
Wed, 22 Jun 2011 03:04:40 +0000 (23:04 -0400)
committerRobert Haas <rhaas@postgresql.org>
Wed, 22 Jun 2011 03:04:40 +0000 (23:04 -0400)
commit503c7305a1e379f95649eef1a694d0c1dbdc674a
tree39bb67975f3419f76d6973e86d5517c8e55f9853
parent431ab0e82819b31fcd1e33ecb52c2cd3b4b41da7
Make the visibility map crash-safe.

This involves two main changes from the previous behavior.  First,
when we set a bit in the visibility map, emit a new WAL record of type
XLOG_HEAP2_VISIBLE.  Replay sets the page-level PD_ALL_VISIBLE bit and
the visibility map bit.  Second, when inserting, updating, or deleting
a tuple, we can no longer get away with clearing the visibility map
bit after releasing the lock on the corresponding heap page, because
an intervening crash might leave the visibility map bit set and the
page-level bit clear.  Making this work requires a bit of interface
refactoring.

In passing, a few minor but related cleanups: change the test in
visibilitymap_set and visibilitymap_clear to throw an error if the
wrong page (or no page) is pinned, rather than silently doing nothing;
this case should never occur.  Also, remove duplicate definitions of
InvalidXLogRecPtr.

Patch by me, review by Noah Misch.
12 files changed:
src/backend/access/heap/heapam.c
src/backend/access/heap/hio.c
src/backend/access/heap/visibilitymap.c
src/backend/access/transam/transam.c
src/backend/access/transam/xlog.c
src/backend/commands/vacuumlazy.c
src/include/access/heapam.h
src/include/access/hio.h
src/include/access/htup.h
src/include/access/transam.h
src/include/access/visibilitymap.h
src/include/access/xlog_internal.h