1/*-------------------------------------------------------------------------
2 *
3 * predicate.h
4 * POSTGRES public predicate locking definitions.
5 *
6 *
7 * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
9 *
10 * src/include/storage/predicate.h
11 *
12 *-------------------------------------------------------------------------
13 */
14#ifndef PREDICATE_H
15#define PREDICATE_H
16
17#include "storage/lock.h"
18#include "utils/relcache.h"
19#include "utils/snapshot.h"
20
21
22/*
23 * GUC variables
24 */
25extern int max_predicate_locks_per_xact;
26extern int max_predicate_locks_per_relation;
27extern int max_predicate_locks_per_page;
28
29
30/* Number of SLRU buffers to use for predicate locking */
31#define NUM_OLDSERXID_BUFFERS 16
32
33/*
34 * A handle used for sharing SERIALIZABLEXACT objects between the participants
35 * in a parallel query.
36 */
37typedef void *SerializableXactHandle;
38
39/*
40 * function prototypes
41 */
42
43/* housekeeping for shared memory predicate lock structures */
44extern void InitPredicateLocks(void);
45extern Size PredicateLockShmemSize(void);
46
47extern void CheckPointPredicate(void);
48
49/* predicate lock reporting */
50extern bool PageIsPredicateLocked(Relation relation, BlockNumber blkno);
51
52/* predicate lock maintenance */
53extern Snapshot GetSerializableTransactionSnapshot(Snapshot snapshot);
54extern void SetSerializableTransactionSnapshot(Snapshot snapshot,
55 VirtualTransactionId *sourcevxid,
56 int sourcepid);
57extern void RegisterPredicateLockingXid(TransactionId xid);
58extern void PredicateLockRelation(Relation relation, Snapshot snapshot);
59extern void PredicateLockPage(Relation relation, BlockNumber blkno, Snapshot snapshot);
60extern void PredicateLockTuple(Relation relation, HeapTuple tuple, Snapshot snapshot);
61extern void PredicateLockPageSplit(Relation relation, BlockNumber oldblkno, BlockNumber newblkno);
62extern void PredicateLockPageCombine(Relation relation, BlockNumber oldblkno, BlockNumber newblkno);
63extern void TransferPredicateLocksToHeapRelation(Relation relation);
64extern void ReleasePredicateLocks(bool isCommit, bool isReadOnlySafe);
65
66/* conflict detection (may also trigger rollback) */
67extern void CheckForSerializableConflictOut(bool valid, Relation relation, HeapTuple tuple,
68 Buffer buffer, Snapshot snapshot);
69extern void CheckForSerializableConflictIn(Relation relation, HeapTuple tuple, Buffer buffer);
70extern void CheckTableForSerializableConflictIn(Relation relation);
71
72/* final rollback checking */
73extern void PreCommit_CheckForSerializationFailure(void);
74
75/* two-phase commit support */
76extern void AtPrepare_PredicateLocks(void);
77extern void PostPrepare_PredicateLocks(TransactionId xid);
78extern void PredicateLockTwoPhaseFinish(TransactionId xid, bool isCommit);
79extern void predicatelock_twophase_recover(TransactionId xid, uint16 info,
80 void *recdata, uint32 len);
81
82/* parallel query support */
83extern SerializableXactHandle ShareSerializableXact(void);
84extern void AttachSerializableXact(SerializableXactHandle handle);
85
86#endif /* PREDICATE_H */
87