Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb9075a6

Browse files
Reduce spurious Hot Standby conflicts from never-visible records.
Hot Standby conflicts only with tuples that were visible atsome point. So ignore tuples from aborted transactions or fortuples updated/deleted during the inserting transaction whengenerating the conflict transaction ids.Following detailed analysis and test case by Noah Misch.Original report covered btree delete records, correctly observedby Heikki Linnakangas that this applies to other cases also.Fix covers all sources of cleanup records via common code.
1 parent576477e commitb9075a6

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

‎src/backend/access/heap/heapam.c

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3776,8 +3776,11 @@ heap_restrpos(HeapScanDesc scan)
37763776
}
37773777

37783778
/*
3779-
* If 'tuple' contains any XID greater than latestRemovedXid, update
3780-
* latestRemovedXid to the greatest one found.
3779+
* If 'tuple' contains any visible XID greater than latestRemovedXid,
3780+
* ratchet forwards latestRemovedXid to the greatest one found.
3781+
* This is used as the basis for generating Hot Standby conflicts, so
3782+
* if a tuple was never visible then removing it should not conflict
3783+
* with queries.
37813784
*/
37823785
void
37833786
HeapTupleHeaderAdvanceLatestRemovedXid(HeapTupleHeadertuple,
@@ -3793,13 +3796,27 @@ HeapTupleHeaderAdvanceLatestRemovedXid(HeapTupleHeader tuple,
37933796
*latestRemovedXid=xvac;
37943797
}
37953798

3796-
if (TransactionIdPrecedes(*latestRemovedXid,xmax))
3797-
*latestRemovedXid=xmax;
3798-
3799-
if (TransactionIdPrecedes(*latestRemovedXid,xmin))
3800-
*latestRemovedXid=xmin;
3799+
/*
3800+
* Ignore tuples inserted by an aborted transaction or
3801+
* if the tuple was updated/deleted by the inserting transaction.
3802+
*
3803+
* Look for a committed hint bit, or if no xmin bit is set, check clog.
3804+
* This needs to work on both master and standby, where it is used
3805+
* to assess btree delete records.
3806+
*/
3807+
if ((tuple->t_infomask&HEAP_XMIN_COMMITTED)||
3808+
(!(tuple->t_infomask&HEAP_XMIN_COMMITTED)&&
3809+
!(tuple->t_infomask&HEAP_XMIN_INVALID)&&
3810+
TransactionIdDidCommit(xmin)))
3811+
{
3812+
if (TransactionIdFollows(xmax,xmin))
3813+
{
3814+
if (TransactionIdFollows(xmax,*latestRemovedXid))
3815+
*latestRemovedXid=xmax;
3816+
}
3817+
}
38013818

3802-
Assert(TransactionIdIsValid(*latestRemovedXid));
3819+
/* *latestRemovedXid may still be invalid at end */
38033820
}
38043821

38053822
/*

‎src/backend/access/heap/pruneheap.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ heap_page_prune(Relation relation, Buffer buffer, TransactionId OldestXmin,
237237
{
238238
XLogRecPtrrecptr;
239239

240-
Assert(TransactionIdIsValid(prstate.latestRemovedXid));
241240
recptr=log_heap_clean(relation,buffer,
242241
prstate.redirected,prstate.nredirected,
243242
prstate.nowdead,prstate.ndead,

‎src/backend/access/nbtree/nbtxlog.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,6 @@ btree_xlog_delete_get_latestRemovedXid(XLogRecord *record)
580580
BlockNumberhblkno;
581581
OffsetNumberhoffnum;
582582
TransactionIdlatestRemovedXid=InvalidTransactionId;
583-
TransactionIdhtupxid=InvalidTransactionId;
584583
inti;
585584

586585
/*
@@ -646,24 +645,16 @@ btree_xlog_delete_get_latestRemovedXid(XLogRecord *record)
646645
}
647646

648647
/*
649-
* If the heap item has storage, then read the header. Some LP_DEAD
650-
* items may not be accessible, so we ignore them.
648+
* If the heap item has storage, then read the header and use that to
649+
* set latestRemovedXid.
650+
*
651+
* Some LP_DEAD items may not be accessible, so we ignore them.
651652
*/
652653
if (ItemIdHasStorage(hitemid))
653654
{
654655
htuphdr= (HeapTupleHeader)PageGetItem(hpage,hitemid);
655656

656-
/*
657-
* Get the heap tuple's xmin/xmax and ratchet up the
658-
* latestRemovedXid. No need to consider xvac values here.
659-
*/
660-
htupxid=HeapTupleHeaderGetXmin(htuphdr);
661-
if (TransactionIdFollows(htupxid,latestRemovedXid))
662-
latestRemovedXid=htupxid;
663-
664-
htupxid=HeapTupleHeaderGetXmax(htuphdr);
665-
if (TransactionIdFollows(htupxid,latestRemovedXid))
666-
latestRemovedXid=htupxid;
657+
HeapTupleHeaderAdvanceLatestRemovedXid(htuphdr,&latestRemovedXid);
667658
}
668659
elseif (ItemIdIsDead(hitemid))
669660
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp