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

Commitc01262a

Browse files
committed
Eliminate xmin from hash tag for predicate locks on heap tuples.
If a tuple was frozen while its predicate locks mattered,read-write dependencies could be missed, resulting in failure todetect conflicts which could lead to anomalies in committedserializable transactions.This field was added to the tag when we still thought that it wasnecessary to carry locks forward to a new version of an updatedrow. That was later proven to be unnecessary, which allowedsimplification of the code, but elimination of xmin from the tagwas missed at the time.Per report and analysis by Heikki Linnakangas.Backpatch to 9.1.
1 parent2e1cb73 commitc01262a

File tree

2 files changed

+14
-29
lines changed

2 files changed

+14
-29
lines changed

‎src/backend/storage/lmgr/predicate.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@
156156
*PredicateLockTuple(Relation relation, HeapTuple tuple,
157157
*Snapshot snapshot)
158158
*PredicateLockPageSplit(Relation relation, BlockNumber oldblkno,
159-
* BlockNumber newblkno);
159+
* BlockNumber newblkno)
160160
*PredicateLockPageCombine(Relation relation, BlockNumber oldblkno,
161-
* BlockNumber newblkno);
161+
* BlockNumber newblkno)
162162
*TransferPredicateLocksToHeapRelation(Relation relation)
163163
*ReleasePredicateLocks(bool isCommit)
164164
*
@@ -381,7 +381,7 @@ static SHM_QUEUE *FinishedSerializableTransactions;
381381
* this entry, you can ensure that there's enough scratch space available for
382382
* inserting one entry in the hash table. This is an otherwise-invalid tag.
383383
*/
384-
staticconstPREDICATELOCKTARGETTAGScratchTargetTag= {0,0,0,0,0};
384+
staticconstPREDICATELOCKTARGETTAGScratchTargetTag= {0,0,0,0};
385385
staticuint32ScratchTargetTagHash;
386386
staticintScratchPartitionLock;
387387

@@ -2492,8 +2492,6 @@ PredicateLockTuple(Relation relation, HeapTuple tuple, Snapshot snapshot)
24922492
}
24932493
}
24942494
}
2495-
else
2496-
targetxmin=InvalidTransactionId;
24972495

24982496
/*
24992497
* Do quick-but-not-definitive test for a relation lock first.This will
@@ -2512,8 +2510,7 @@ PredicateLockTuple(Relation relation, HeapTuple tuple, Snapshot snapshot)
25122510
relation->rd_node.dbNode,
25132511
relation->rd_id,
25142512
ItemPointerGetBlockNumber(tid),
2515-
ItemPointerGetOffsetNumber(tid),
2516-
targetxmin);
2513+
ItemPointerGetOffsetNumber(tid));
25172514
PredicateLockAcquire(&tag);
25182515
}
25192516

@@ -4283,8 +4280,7 @@ CheckForSerializableConflictIn(Relation relation, HeapTuple tuple,
42834280
relation->rd_node.dbNode,
42844281
relation->rd_id,
42854282
ItemPointerGetBlockNumber(&(tuple->t_data->t_ctid)),
4286-
ItemPointerGetOffsetNumber(&(tuple->t_data->t_ctid)),
4287-
HeapTupleHeaderGetXmin(tuple->t_data));
4283+
ItemPointerGetOffsetNumber(&(tuple->t_data->t_ctid)));
42884284
CheckTargetForConflictsIn(&targettag);
42894285
}
42904286

‎src/include/storage/predicate_internals.h

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ typedef struct SERIALIZABLEXID
254254
* be the target of predicate locks.
255255
*
256256
* Note that the hash function being used doesn't properly respect tag
257-
* length --it will go to a four byte boundary past the endofthe tag.
258-
*If you change this struct, make sure any slack space is initialized,
259-
*so that any random bytes in the middle or at the end are not included
260-
* in the hash.
257+
* length --if the length of the structure isn't a multipleoffour bytes it
258+
*will go to a four byte boundary past the end of the tag. If you change
259+
*this struct, make sure any slack space is initialized, so that any random
260+
*bytes in the middle or at the end are not includedin the hash.
261261
*
262262
* TODO SSI: If we always use the same fields for the same type of value, we
263263
* should rename these. Holding off until it's clear there are no exceptions.
@@ -272,7 +272,6 @@ typedef struct PREDICATELOCKTARGETTAG
272272
uint32locktag_field2;/* a 32-bit ID field */
273273
uint32locktag_field3;/* a 32-bit ID field */
274274
uint32locktag_field4;/* a 32-bit ID field */
275-
uint32locktag_field5;/* a 32-bit ID field */
276275
}PREDICATELOCKTARGETTAG;
277276

278277
/*
@@ -283,12 +282,6 @@ typedef struct PREDICATELOCKTARGETTAG
283282
* added when a predicate lock is requested on an object which doesn't
284283
* already have one. An entry is removed when the last lock is removed from
285284
* its list.
286-
*
287-
* Because a particular target might become obsolete, due to update to a new
288-
* version, before the reading transaction is obsolete, we need some way to
289-
* prevent errors from reuse of a tuple ID. Rather than attempting to clean
290-
* up the targets as the related tuples are pruned or vacuumed, we check the
291-
* xmin on access.This should be far less costly.
292285
*/
293286
typedefstructPREDICATELOCKTARGET
294287
{
@@ -398,22 +391,19 @@ typedef struct PredicateLockData
398391
((locktag).locktag_field1 = (dboid), \
399392
(locktag).locktag_field2 = (reloid), \
400393
(locktag).locktag_field3 = InvalidBlockNumber, \
401-
(locktag).locktag_field4 = InvalidOffsetNumber, \
402-
(locktag).locktag_field5 = InvalidTransactionId)
394+
(locktag).locktag_field4 = InvalidOffsetNumber)
403395

404396
#defineSET_PREDICATELOCKTARGETTAG_PAGE(locktag,dboid,reloid,blocknum) \
405397
((locktag).locktag_field1 = (dboid), \
406398
(locktag).locktag_field2 = (reloid), \
407399
(locktag).locktag_field3 = (blocknum), \
408-
(locktag).locktag_field4 = InvalidOffsetNumber, \
409-
(locktag).locktag_field5 = InvalidTransactionId)
400+
(locktag).locktag_field4 = InvalidOffsetNumber)
410401

411-
#defineSET_PREDICATELOCKTARGETTAG_TUPLE(locktag,dboid,reloid,blocknum,offnum,xmin) \
402+
#defineSET_PREDICATELOCKTARGETTAG_TUPLE(locktag,dboid,reloid,blocknum,offnum) \
412403
((locktag).locktag_field1 = (dboid), \
413404
(locktag).locktag_field2 = (reloid), \
414405
(locktag).locktag_field3 = (blocknum), \
415-
(locktag).locktag_field4 = (offnum), \
416-
(locktag).locktag_field5 = (xmin))
406+
(locktag).locktag_field4 = (offnum))
417407

418408
#defineGET_PREDICATELOCKTARGETTAG_DB(locktag) \
419409
((Oid) (locktag).locktag_field1)
@@ -423,8 +413,6 @@ typedef struct PredicateLockData
423413
((BlockNumber) (locktag).locktag_field3)
424414
#defineGET_PREDICATELOCKTARGETTAG_OFFSET(locktag) \
425415
((OffsetNumber) (locktag).locktag_field4)
426-
#defineGET_PREDICATELOCKTARGETTAG_XMIN(locktag) \
427-
((TransactionId) (locktag).locktag_field5)
428416
#defineGET_PREDICATELOCKTARGETTAG_TYPE(locktag) \
429417
(((locktag).locktag_field4 != InvalidOffsetNumber) ? PREDLOCKTAG_TUPLE : \
430418
(((locktag).locktag_field3 != InvalidBlockNumber) ? PREDLOCKTAG_PAGE : \
@@ -462,6 +450,7 @@ typedef struct TwoPhasePredicateXactRecord
462450
typedefstructTwoPhasePredicateLockRecord
463451
{
464452
PREDICATELOCKTARGETTAGtarget;
453+
uint32filler;/* to avoid length change in back-patched fix */
465454
}TwoPhasePredicateLockRecord;
466455

467456
typedefstructTwoPhasePredicateRecord

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp