mirror of
https://github.com/postgres/postgres.git
synced 2026-03-13 06:06:25 -04:00
In REPEATABLE READ (nee SERIALIZABLE) mode, an attempt to do GetTransactionSnapshot() between AbortTransaction and CleanupTransaction failed, because GetTransactionSnapshot would recompute the transaction snapshot (which is already wrong, given the isolation mode) and then re-register it in the TopTransactionResourceOwner, leading to an Assert because the TopTransactionResourceOwner should be empty of resources after AbortTransaction. This is the root cause of bug #6218 from Yamamoto Takashi. While changing plancache.c to avoid requesting a snapshot when handling a ROLLBACK masks the problem, I think this is really a snapmgr.c bug: it's lower-level than the resource manager mechanism and should not be shutting itself down before we unwind resource manager resources. However, just postponing the release of the transaction snapshot until cleanup time didn't work because of the circular dependency with TopTransactionResourceOwner. Fix by managing the internal reference to that snapshot manually instead of depending on TopTransactionResourceOwner. This saves a few cycles as well as making the module layering more straightforward. predicate.c's dependencies on TopTransactionResourceOwner go away too. I think this is a longstanding bug, but there's no evidence that it's more than a latent bug, so it doesn't seem worth any risk of back-patching.
71 lines
2.5 KiB
C
71 lines
2.5 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* predicate.h
|
|
* POSTGRES public predicate locking definitions.
|
|
*
|
|
*
|
|
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* src/include/storage/predicate.h
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#ifndef PREDICATE_H
|
|
#define PREDICATE_H
|
|
|
|
#include "utils/relcache.h"
|
|
#include "utils/snapshot.h"
|
|
|
|
|
|
/*
|
|
* GUC variables
|
|
*/
|
|
extern int max_predicate_locks_per_xact;
|
|
|
|
|
|
/* Number of SLRU buffers to use for predicate locking */
|
|
#define NUM_OLDSERXID_BUFFERS 16
|
|
|
|
|
|
/*
|
|
* function prototypes
|
|
*/
|
|
|
|
/* housekeeping for shared memory predicate lock structures */
|
|
extern void InitPredicateLocks(void);
|
|
extern Size PredicateLockShmemSize(void);
|
|
|
|
extern void CheckPointPredicate(void);
|
|
|
|
/* predicate lock reporting */
|
|
extern bool PageIsPredicateLocked(Relation relation, BlockNumber blkno);
|
|
|
|
/* predicate lock maintenance */
|
|
extern Snapshot GetSerializableTransactionSnapshot(Snapshot snapshot);
|
|
extern void RegisterPredicateLockingXid(TransactionId xid);
|
|
extern void PredicateLockRelation(Relation relation, Snapshot snapshot);
|
|
extern void PredicateLockPage(Relation relation, BlockNumber blkno, Snapshot snapshot);
|
|
extern void PredicateLockTuple(Relation relation, HeapTuple tuple, Snapshot snapshot);
|
|
extern void PredicateLockPageSplit(Relation relation, BlockNumber oldblkno, BlockNumber newblkno);
|
|
extern void PredicateLockPageCombine(Relation relation, BlockNumber oldblkno, BlockNumber newblkno);
|
|
extern void TransferPredicateLocksToHeapRelation(Relation relation);
|
|
extern void ReleasePredicateLocks(bool isCommit);
|
|
|
|
/* conflict detection (may also trigger rollback) */
|
|
extern void CheckForSerializableConflictOut(bool valid, Relation relation, HeapTuple tuple,
|
|
Buffer buffer, Snapshot snapshot);
|
|
extern void CheckForSerializableConflictIn(Relation relation, HeapTuple tuple, Buffer buffer);
|
|
extern void CheckTableForSerializableConflictIn(Relation relation);
|
|
|
|
/* final rollback checking */
|
|
extern void PreCommit_CheckForSerializationFailure(void);
|
|
|
|
/* two-phase commit support */
|
|
extern void AtPrepare_PredicateLocks(void);
|
|
extern void PostPrepare_PredicateLocks(TransactionId xid);
|
|
extern void PredicateLockTwoPhaseFinish(TransactionId xid, bool isCommit);
|
|
extern void predicatelock_twophase_recover(TransactionId xid, uint16 info,
|
|
void *recdata, uint32 len);
|
|
|
|
#endif /* PREDICATE_H */
|