mirror of
https://github.com/postgres/postgres.git
synced 2025-06-29 10:41:53 +03:00
Rework tuple freezing protocol
Tuple freezing was broken in connection to MultiXactIds; commit
8e53ae025d
tried to fix it, but didn't go far enough. As noted by
Noah Misch, freezing a tuple whose Xmax is a multi containing an aborted
update might cause locks in the multi to go ignored by later
transactions. This is because the code depended on a multixact above
their cutoff point not having any lock-only member older than the cutoff
point for Xids, which is easily defeated in READ COMMITTED transactions.
The fix for this involves creating a new MultiXactId when necessary.
But this cannot be done during WAL replay, and moreover multixact
examination requires using CLOG access routines which are not supposed
to be used during WAL replay either; so tuple freezing cannot be done
with the old freeze WAL record. Therefore, separate the freezing
computation from its execution, and change the WAL record to carry all
necessary information. At WAL replay time, it's easy to re-execute
freezing because we don't need to re-compute the new infomask/Xmax
values but just take them from the WAL record.
While at it, restructure the coding to ensure all page changes occur in
a single critical section without much room for failures. The previous
coding wasn't using a critical section, without any explanation as to
why this was acceptable.
In replication scenarios using the 9.3 branch, standby servers must be
upgraded before their master, so that they are prepared to deal with the
new WAL record once the master is upgraded; failure to do so will cause
WAL replay to die with a PANIC message. Later upgrade of the standby
will allow the process to continue where it left off, so there's no
disruption of the data in the standby in any case. Standbys know how to
deal with the old WAL record, so it's okay to keep the master running
the old code for a while.
In master, the old freeze WAL record is gone, for cleanliness' sake;
there's no compatibility concern there.
Backpatch to 9.3, where the original bug was introduced and where the
previous fix was backpatched.
Álvaro Herrera and Andres Freund
This commit is contained in:
@ -48,9 +48,9 @@
|
||||
* the ones above associated with RM_HEAP_ID. XLOG_HEAP_OPMASK applies to
|
||||
* these, too.
|
||||
*/
|
||||
#define XLOG_HEAP2_FREEZE 0x00
|
||||
/* 0x00 is free, was XLOG_HEAP2_FREEZE */
|
||||
#define XLOG_HEAP2_CLEAN 0x10
|
||||
/* 0x20 is free, was XLOG_HEAP2_CLEAN_MOVE */
|
||||
#define XLOG_HEAP2_FREEZE_PAGE 0x20
|
||||
#define XLOG_HEAP2_CLEANUP_INFO 0x30
|
||||
#define XLOG_HEAP2_VISIBLE 0x40
|
||||
#define XLOG_HEAP2_MULTI_INSERT 0x50
|
||||
@ -270,17 +270,36 @@ typedef struct xl_heap_inplace
|
||||
|
||||
#define SizeOfHeapInplace (offsetof(xl_heap_inplace, target) + SizeOfHeapTid)
|
||||
|
||||
/* This is what we need to know about tuple freezing during vacuum */
|
||||
typedef struct xl_heap_freeze
|
||||
/*
|
||||
* This struct represents a 'freeze plan', which is what we need to know about
|
||||
* a single tuple being frozen during vacuum.
|
||||
*/
|
||||
#define XLH_FREEZE_XMIN 0x01
|
||||
#define XLH_FREEZE_XVAC 0x02
|
||||
#define XLH_INVALID_XVAC 0x04
|
||||
|
||||
typedef struct xl_heap_freeze_tuple
|
||||
{
|
||||
TransactionId xmax;
|
||||
OffsetNumber offset;
|
||||
uint16 t_infomask2;
|
||||
uint16 t_infomask;
|
||||
uint8 frzflags;
|
||||
} xl_heap_freeze_tuple;
|
||||
|
||||
/*
|
||||
* This is what we need to know about a block being frozen during vacuum
|
||||
*/
|
||||
typedef struct xl_heap_freeze_page
|
||||
{
|
||||
RelFileNode node;
|
||||
BlockNumber block;
|
||||
TransactionId cutoff_xid;
|
||||
MultiXactId cutoff_multi;
|
||||
/* TUPLE OFFSET NUMBERS FOLLOW AT THE END */
|
||||
} xl_heap_freeze;
|
||||
uint16 ntuples;
|
||||
xl_heap_freeze_tuple tuples[FLEXIBLE_ARRAY_MEMBER];
|
||||
} xl_heap_freeze_page;
|
||||
|
||||
#define SizeOfHeapFreeze (offsetof(xl_heap_freeze, cutoff_multi) + sizeof(MultiXactId))
|
||||
#define SizeOfHeapFreezePage offsetof(xl_heap_freeze_page, tuples)
|
||||
|
||||
/* This is what we need to know about setting a visibility map bit */
|
||||
typedef struct xl_heap_visible
|
||||
@ -331,8 +350,14 @@ extern XLogRecPtr log_heap_clean(Relation reln, Buffer buffer,
|
||||
OffsetNumber *nowunused, int nunused,
|
||||
TransactionId latestRemovedXid);
|
||||
extern XLogRecPtr log_heap_freeze(Relation reln, Buffer buffer,
|
||||
TransactionId cutoff_xid, MultiXactId cutoff_multi,
|
||||
OffsetNumber *offsets, int offcnt);
|
||||
TransactionId cutoff_xid, xl_heap_freeze_tuple *tuples,
|
||||
int ntuples);
|
||||
extern bool heap_prepare_freeze_tuple(HeapTupleHeader tuple,
|
||||
TransactionId cutoff_xid,
|
||||
TransactionId cutoff_multi,
|
||||
xl_heap_freeze_tuple *frz);
|
||||
extern void heap_execute_freeze_tuple(HeapTupleHeader tuple,
|
||||
xl_heap_freeze_tuple *xlrec_tp);
|
||||
extern XLogRecPtr log_heap_visible(RelFileNode rnode, Buffer heap_buffer,
|
||||
Buffer vm_buffer, TransactionId cutoff_xid);
|
||||
extern XLogRecPtr log_newpage(RelFileNode *rnode, ForkNumber forkNum,
|
||||
|
Reference in New Issue
Block a user