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

Commit7386089

Browse files
committed
Code cleanup for heap_freeze_tuple.
It used to be case that lazy vacuum could call this function with onlya shared lock on the buffer, but neither lazy vacuum nor any othercode path does that any more. Simplify the code accordingly and cleanup some related, obsolete comments.
1 parente8476f4 commit7386089

File tree

4 files changed

+7
-55
lines changed

4 files changed

+7
-55
lines changed

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

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3947,10 +3947,8 @@ heap_inplace_update(Relation relation, HeapTuple tuple)
39473947
* because this function is applied during WAL recovery, when we don't have
39483948
* access to any such state, and can't depend on the hint bits to be set.)
39493949
*
3950-
* In lazy VACUUM, we call this while initially holding only a shared lock
3951-
* on the tuple's buffer. If any change is needed, we trade that in for an
3952-
* exclusive lock before making the change. Caller should pass the buffer ID
3953-
* if shared lock is held, InvalidBuffer if exclusive lock is already held.
3950+
* If the tuple is in a shared buffer, caller must hold an exclusive lock on
3951+
* that buffer.
39543952
*
39553953
* Note: it might seem we could make the changes without exclusive lock, since
39563954
* TransactionId read/write is assumed atomic anyway. However there is a race
@@ -3962,8 +3960,7 @@ heap_inplace_update(Relation relation, HeapTuple tuple)
39623960
* infomask bits.
39633961
*/
39643962
bool
3965-
heap_freeze_tuple(HeapTupleHeadertuple,TransactionIdcutoff_xid,
3966-
Bufferbuf)
3963+
heap_freeze_tuple(HeapTupleHeadertuple,TransactionIdcutoff_xid)
39673964
{
39683965
boolchanged= false;
39693966
TransactionIdxid;
@@ -3972,13 +3969,6 @@ heap_freeze_tuple(HeapTupleHeader tuple, TransactionId cutoff_xid,
39723969
if (TransactionIdIsNormal(xid)&&
39733970
TransactionIdPrecedes(xid,cutoff_xid))
39743971
{
3975-
if (buf!=InvalidBuffer)
3976-
{
3977-
/* trade in share lock for exclusive lock */
3978-
LockBuffer(buf,BUFFER_LOCK_UNLOCK);
3979-
LockBuffer(buf,BUFFER_LOCK_EXCLUSIVE);
3980-
buf=InvalidBuffer;
3981-
}
39823972
HeapTupleHeaderSetXmin(tuple,FrozenTransactionId);
39833973

39843974
/*
@@ -3990,28 +3980,12 @@ heap_freeze_tuple(HeapTupleHeader tuple, TransactionId cutoff_xid,
39903980
changed= true;
39913981
}
39923982

3993-
/*
3994-
* When we release shared lock, it's possible for someone else to change
3995-
* xmax before we get the lock back, so repeat the check after acquiring
3996-
* exclusive lock.(We don't need this pushup for xmin, because only
3997-
* VACUUM could be interested in changing an existing tuple's xmin, and
3998-
* there's only one VACUUM allowed on a table at a time.)
3999-
*/
4000-
recheck_xmax:
40013983
if (!(tuple->t_infomask&HEAP_XMAX_IS_MULTI))
40023984
{
40033985
xid=HeapTupleHeaderGetXmax(tuple);
40043986
if (TransactionIdIsNormal(xid)&&
40053987
TransactionIdPrecedes(xid,cutoff_xid))
40063988
{
4007-
if (buf!=InvalidBuffer)
4008-
{
4009-
/* trade in share lock for exclusive lock */
4010-
LockBuffer(buf,BUFFER_LOCK_UNLOCK);
4011-
LockBuffer(buf,BUFFER_LOCK_EXCLUSIVE);
4012-
buf=InvalidBuffer;
4013-
gotorecheck_xmax;/* see comment above */
4014-
}
40153989
HeapTupleHeaderSetXmax(tuple,InvalidTransactionId);
40163990

40173991
/*
@@ -4046,30 +4020,15 @@ heap_freeze_tuple(HeapTupleHeader tuple, TransactionId cutoff_xid,
40464020
}
40474021

40484022
/*
4049-
* Although xvac per se could only be set by old-style VACUUM FULL, it
4050-
* shares physical storage space with cmax, and so could be wiped out by
4051-
* someone setting xmax. Hence recheck after changing lock, same as for
4052-
* xmax itself.
4053-
*
40544023
* Old-style VACUUM FULL is gone, but we have to keep this code as long as
40554024
* we support having MOVED_OFF/MOVED_IN tuples in the database.
40564025
*/
4057-
recheck_xvac:
40584026
if (tuple->t_infomask&HEAP_MOVED)
40594027
{
40604028
xid=HeapTupleHeaderGetXvac(tuple);
40614029
if (TransactionIdIsNormal(xid)&&
40624030
TransactionIdPrecedes(xid,cutoff_xid))
40634031
{
4064-
if (buf!=InvalidBuffer)
4065-
{
4066-
/* trade in share lock for exclusive lock */
4067-
LockBuffer(buf,BUFFER_LOCK_UNLOCK);
4068-
LockBuffer(buf,BUFFER_LOCK_EXCLUSIVE);
4069-
buf=InvalidBuffer;
4070-
gotorecheck_xvac;/* see comment above */
4071-
}
4072-
40734032
/*
40744033
* If a MOVED_OFF tuple is not dead, the xvac transaction must
40754034
* have failed; whereas a non-dead MOVED_IN tuple must mean the
@@ -4711,7 +4670,7 @@ heap_xlog_freeze(XLogRecPtr lsn, XLogRecord *record)
47114670
ItemIdlp=PageGetItemId(page,*offsets);
47124671
HeapTupleHeadertuple= (HeapTupleHeader)PageGetItem(page,lp);
47134672

4714-
(void)heap_freeze_tuple(tuple,cutoff_xid,InvalidBuffer);
4673+
(void)heap_freeze_tuple(tuple,cutoff_xid);
47154674
offsets++;
47164675
}
47174676
}

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,8 @@ rewrite_heap_tuple(RewriteState state,
335335
/*
336336
* While we have our hands on the tuple, we may as well freeze any
337337
* very-old xmin or xmax, so that future VACUUM effort can be saved.
338-
*
339-
* Note we abuse heap_freeze_tuple() a bit here, since it's expecting to
340-
* be given a pointer to a tuple in a disk buffer.It happens though that
341-
* we can get the right things to happen by passing InvalidBuffer for the
342-
* buffer.
343338
*/
344-
heap_freeze_tuple(new_tuple->t_data,state->rs_freeze_xid,InvalidBuffer);
339+
heap_freeze_tuple(new_tuple->t_data,state->rs_freeze_xid);
345340

346341
/*
347342
* Invalid ctid means that ctid should point to the tuple itself. We'll

‎src/backend/commands/vacuumlazy.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,7 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
784784
* Each non-removable tuple must be checked to see if it needs
785785
* freezing. Note we already have exclusive buffer lock.
786786
*/
787-
if (heap_freeze_tuple(tuple.t_data,FreezeLimit,
788-
InvalidBuffer))
787+
if (heap_freeze_tuple(tuple.t_data,FreezeLimit))
789788
frozen[nfrozen++]=offnum;
790789
}
791790
}/* scan along page */

‎src/include/access/heapam.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ extern HTSU_Result heap_lock_tuple(Relation relation, HeapTuple tuple,
111111
TransactionId*update_xmax,CommandIdcid,
112112
LockTupleModemode,boolnowait);
113113
externvoidheap_inplace_update(Relationrelation,HeapTupletuple);
114-
externboolheap_freeze_tuple(HeapTupleHeadertuple,TransactionIdcutoff_xid,
115-
Bufferbuf);
114+
externboolheap_freeze_tuple(HeapTupleHeadertuple,TransactionIdcutoff_xid);
116115
externboolheap_tuple_needs_freeze(HeapTupleHeadertuple,TransactionIdcutoff_xid,
117116
Bufferbuf);
118117

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp