Skip to content

Commit 3fd7a45

Browse files
knizhnikKonstantin Knizhnik
andauthored
Correctly handle COMBCID flag in WAL (#459)
* Correctly handle COMBCID flag in WAL * Fix bug in storing CID to oldrecord in heap_update * Fix retstorig cid in heap redo --------- Co-authored-by: Konstantin Knizhnik <[email protected]>
1 parent a48faca commit 3fd7a45

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/backend/access/heap/heapam.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2820,6 +2820,7 @@ compute_infobits(uint16 infomask, uint16 infomask2)
28202820
((infomask & HEAP_XMAX_IS_MULTI) != 0 ? XLHL_XMAX_IS_MULTI : 0) |
28212821
((infomask & HEAP_XMAX_LOCK_ONLY) != 0 ? XLHL_XMAX_LOCK_ONLY : 0) |
28222822
((infomask & HEAP_XMAX_EXCL_LOCK) != 0 ? XLHL_XMAX_EXCL_LOCK : 0) |
2823+
((infomask & HEAP_COMBOCID) != 0 ? XLHL_COMBOCID : 0) |
28232824
/* note we ignore HEAP_XMAX_SHR_LOCK here */
28242825
((infomask & HEAP_XMAX_KEYSHR_LOCK) != 0 ? XLHL_XMAX_KEYSHR_LOCK : 0) |
28252826
((infomask2 & HEAP_KEYS_UPDATED) != 0 ?
@@ -8369,11 +8370,12 @@ log_heap_update(Relation reln, Buffer oldbuf,
83698370
xlrec.old_xmax = HeapTupleHeaderGetRawXmax(oldtup->t_data);
83708371
xlrec.old_infobits_set = compute_infobits(oldtup->t_data->t_infomask,
83718372
oldtup->t_data->t_infomask2);
8373+
xlrec.t_cid = HeapTupleHeaderGetRawCommandId(oldtup->t_data);
83728374

83738375
/* Prepare WAL data for the new page */
83748376
xlrec.new_offnum = ItemPointerGetOffsetNumber(&newtup->t_self);
83758377
xlrec.new_xmax = HeapTupleHeaderGetRawXmax(newtup->t_data);
8376-
xlrec.t_cid = HeapTupleHeaderGetRawCommandId(newtup->t_data);
8378+
83778379
bufflags = REGBUF_STANDARD;
83788380
if (init)
83798381
bufflags |= REGBUF_WILL_INIT;
@@ -9024,7 +9026,7 @@ static void
90249026
fix_infomask_from_infobits(uint8 infobits, uint16 *infomask, uint16 *infomask2)
90259027
{
90269028
*infomask &= ~(HEAP_XMAX_IS_MULTI | HEAP_XMAX_LOCK_ONLY |
9027-
HEAP_XMAX_KEYSHR_LOCK | HEAP_XMAX_EXCL_LOCK);
9029+
HEAP_XMAX_KEYSHR_LOCK | HEAP_XMAX_EXCL_LOCK | HEAP_COMBOCID);
90289030
*infomask2 &= ~HEAP_KEYS_UPDATED;
90299031

90309032
if (infobits & XLHL_XMAX_IS_MULTI)
@@ -9033,6 +9035,8 @@ fix_infomask_from_infobits(uint8 infobits, uint16 *infomask, uint16 *infomask2)
90339035
*infomask |= HEAP_XMAX_LOCK_ONLY;
90349036
if (infobits & XLHL_XMAX_EXCL_LOCK)
90359037
*infomask |= HEAP_XMAX_EXCL_LOCK;
9038+
if (infobits & XLHL_COMBOCID)
9039+
*infomask |= HEAP_COMBOCID;
90369040
/* note HEAP_XMAX_SHR_LOCK isn't considered here */
90379041
if (infobits & XLHL_XMAX_KEYSHR_LOCK)
90389042
*infomask |= HEAP_XMAX_KEYSHR_LOCK;
@@ -9094,7 +9098,7 @@ heap_xlog_delete(XLogReaderState *record)
90949098
HeapTupleHeaderSetXmax(htup, xlrec->xmax);
90959099
else
90969100
HeapTupleHeaderSetXmin(htup, InvalidTransactionId);
9097-
HeapTupleHeaderSetCmax(htup, xlrec->t_cid, false);
9101+
htup->t_choice.t_heap.t_field3.t_cid = xlrec->t_cid;
90989102

90999103
/* Mark the page as a candidate for pruning */
91009104
PageSetPrunable(page, XLogRecGetXid(record));
@@ -9195,7 +9199,7 @@ heap_xlog_insert(XLogReaderState *record)
91959199
htup->t_infomask = xlhdr.t_infomask;
91969200
htup->t_hoff = xlhdr.t_hoff;
91979201
HeapTupleHeaderSetXmin(htup, XLogRecGetXid(record));
9198-
HeapTupleHeaderSetCmin(htup, xlhdr.t_cid);
9202+
htup->t_choice.t_heap.t_field3.t_cid = xlhdr.t_cid;
91999203
htup->t_ctid = target_tid;
92009204

92019205
if (PageAddItem(page, (Item) htup, newlen, xlrec->offnum,
@@ -9338,7 +9342,7 @@ heap_xlog_multi_insert(XLogReaderState *record)
93389342
htup->t_infomask = xlhdr->t_infomask;
93399343
htup->t_hoff = xlhdr->t_hoff;
93409344
HeapTupleHeaderSetXmin(htup, XLogRecGetXid(record));
9341-
HeapTupleHeaderSetCmin(htup, xlhdr->t_cid);
9345+
htup->t_choice.t_heap.t_field3.t_cid = xlhdr->t_cid;
93429346
ItemPointerSetBlockNumber(&htup->t_ctid, blkno);
93439347
ItemPointerSetOffsetNumber(&htup->t_ctid, offnum);
93449348

@@ -9478,7 +9482,7 @@ heap_xlog_update(XLogReaderState *record, bool hot_update)
94789482
fix_infomask_from_infobits(xlrec->old_infobits_set, &htup->t_infomask,
94799483
&htup->t_infomask2);
94809484
HeapTupleHeaderSetXmax(htup, xlrec->old_xmax);
9481-
HeapTupleHeaderSetCmax(htup, xlrec->t_cid, false);
9485+
htup->t_choice.t_heap.t_field3.t_cid = xlrec->t_cid;
94829486
/* Set forward chain link in t_ctid */
94839487
htup->t_ctid = newtid;
94849488

@@ -9611,7 +9615,7 @@ heap_xlog_update(XLogReaderState *record, bool hot_update)
96119615
htup->t_hoff = xlhdr.t_hoff;
96129616

96139617
HeapTupleHeaderSetXmin(htup, XLogRecGetXid(record));
9614-
HeapTupleHeaderSetCmin(htup, xlhdr.t_cid);
9618+
htup->t_choice.t_heap.t_field3.t_cid = xlhdr.t_cid;
96159619
HeapTupleHeaderSetXmax(htup, xlrec->new_xmax);
96169620
/* Make sure there is no forward chain link in t_ctid */
96179621
htup->t_ctid = newtid;
@@ -9752,7 +9756,7 @@ heap_xlog_lock(XLogReaderState *record)
97529756
offnum);
97539757
}
97549758
HeapTupleHeaderSetXmax(htup, xlrec->locking_xid);
9755-
HeapTupleHeaderSetCmax(htup, xlrec->t_cid, false);
9759+
htup->t_choice.t_heap.t_field3.t_cid = xlrec->t_cid;
97569760
PageSetLSN(page, lsn);
97579761
MarkBufferDirty(buffer);
97589762
}

src/include/access/heapam_xlog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ typedef struct xl_heap_vacuum
273273
#define XLHL_XMAX_EXCL_LOCK 0x04
274274
#define XLHL_XMAX_KEYSHR_LOCK 0x08
275275
#define XLHL_KEYS_UPDATED 0x10
276+
#define XLHL_COMBOCID 0x20
276277

277278
/* flag bits for xl_heap_lock / xl_heap_lock_updated's flag field */
278279
#define XLH_LOCK_ALL_FROZEN_CLEARED 0x01

0 commit comments

Comments
 (0)