PostgreSQL Source Code  git master
predicate_internals.h File Reference
#include "storage/lock.h"
Include dependency graph for predicate_internals.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SERIALIZABLEXACT
 
struct  PredXactListElementData
 
struct  PredXactListData
 
struct  RWConflictData
 
struct  RWConflictPoolHeaderData
 
struct  SERIALIZABLEXIDTAG
 
struct  SERIALIZABLEXID
 
struct  PREDICATELOCKTARGETTAG
 
struct  PREDICATELOCKTARGET
 
struct  PREDICATELOCKTAG
 
struct  PREDICATELOCK
 
struct  LOCALPREDICATELOCK
 
struct  PredicateLockData
 
struct  TwoPhasePredicateXactRecord
 
struct  TwoPhasePredicateLockRecord
 
struct  TwoPhasePredicateRecord
 

Macros

#define InvalidSerCommitSeqNo   ((SerCommitSeqNo) PG_UINT64_MAX)
 
#define RecoverySerCommitSeqNo   ((SerCommitSeqNo) 1)
 
#define FirstNormalSerCommitSeqNo   ((SerCommitSeqNo) 2)
 
#define SXACT_FLAG_COMMITTED   0x00000001 /* already committed */
 
#define SXACT_FLAG_PREPARED   0x00000002 /* about to commit */
 
#define SXACT_FLAG_ROLLED_BACK   0x00000004 /* already rolled back */
 
#define SXACT_FLAG_DOOMED   0x00000008 /* will roll back */
 
#define SXACT_FLAG_CONFLICT_OUT   0x00000010
 
#define SXACT_FLAG_READ_ONLY   0x00000020
 
#define SXACT_FLAG_DEFERRABLE_WAITING   0x00000040
 
#define SXACT_FLAG_RO_SAFE   0x00000080
 
#define SXACT_FLAG_RO_UNSAFE   0x00000100
 
#define SXACT_FLAG_SUMMARY_CONFLICT_IN   0x00000200
 
#define SXACT_FLAG_SUMMARY_CONFLICT_OUT   0x00000400
 
#define PredXactListElementDataSize   ((Size)MAXALIGN(sizeof(PredXactListElementData)))
 
#define PredXactListDataSize   ((Size)MAXALIGN(sizeof(PredXactListData)))
 
#define RWConflictDataSize   ((Size)MAXALIGN(sizeof(RWConflictData)))
 
#define RWConflictPoolHeaderDataSize   ((Size)MAXALIGN(sizeof(RWConflictPoolHeaderData)))
 
#define SET_PREDICATELOCKTARGETTAG_RELATION(locktag, dboid, reloid)
 
#define SET_PREDICATELOCKTARGETTAG_PAGE(locktag, dboid, reloid, blocknum)
 
#define SET_PREDICATELOCKTARGETTAG_TUPLE(locktag, dboid, reloid, blocknum, offnum)
 
#define GET_PREDICATELOCKTARGETTAG_DB(locktag)   ((Oid) (locktag).locktag_field1)
 
#define GET_PREDICATELOCKTARGETTAG_RELATION(locktag)   ((Oid) (locktag).locktag_field2)
 
#define GET_PREDICATELOCKTARGETTAG_PAGE(locktag)   ((BlockNumber) (locktag).locktag_field3)
 
#define GET_PREDICATELOCKTARGETTAG_OFFSET(locktag)   ((OffsetNumber) (locktag).locktag_field4)
 
#define GET_PREDICATELOCKTARGETTAG_TYPE(locktag)
 
#define InvalidSerializableXact   ((SERIALIZABLEXACT *) NULL)
 

Typedefs

typedef uint64 SerCommitSeqNo
 
typedef struct SERIALIZABLEXACT SERIALIZABLEXACT
 
typedef struct PredXactListElementData PredXactListElementData
 
typedef struct PredXactListElementDataPredXactListElement
 
typedef struct PredXactListData PredXactListData
 
typedef struct PredXactListDataPredXactList
 
typedef struct RWConflictData RWConflictData
 
typedef struct RWConflictDataRWConflict
 
typedef struct RWConflictPoolHeaderData RWConflictPoolHeaderData
 
typedef struct RWConflictPoolHeaderDataRWConflictPoolHeader
 
typedef struct SERIALIZABLEXIDTAG SERIALIZABLEXIDTAG
 
typedef struct SERIALIZABLEXID SERIALIZABLEXID
 
typedef struct PREDICATELOCKTARGETTAG PREDICATELOCKTARGETTAG
 
typedef struct PREDICATELOCKTARGET PREDICATELOCKTARGET
 
typedef struct PREDICATELOCKTAG PREDICATELOCKTAG
 
typedef struct PREDICATELOCK PREDICATELOCK
 
typedef struct LOCALPREDICATELOCK LOCALPREDICATELOCK
 
typedef enum PredicateLockTargetType PredicateLockTargetType
 
typedef struct PredicateLockData PredicateLockData
 
typedef enum TwoPhasePredicateRecordType TwoPhasePredicateRecordType
 
typedef struct TwoPhasePredicateXactRecord TwoPhasePredicateXactRecord
 
typedef struct TwoPhasePredicateLockRecord TwoPhasePredicateLockRecord
 
typedef struct TwoPhasePredicateRecord TwoPhasePredicateRecord
 

Enumerations

enum  PredicateLockTargetType { PREDLOCKTAG_RELATION, PREDLOCKTAG_PAGE, PREDLOCKTAG_TUPLE }
 
enum  TwoPhasePredicateRecordType { TWOPHASEPREDICATERECORD_XACT, TWOPHASEPREDICATERECORD_LOCK }
 

Functions

PredicateLockDataGetPredicateLockStatusData (void)
 
int GetSafeSnapshotBlockingPids (int blocked_pid, int *output, int output_size)
 

Macro Definition Documentation

◆ FirstNormalSerCommitSeqNo

#define FirstNormalSerCommitSeqNo   ((SerCommitSeqNo) 2)

Definition at line 38 of file predicate_internals.h.

Referenced by InitPredicateLocks(), and ReleasePredicateLocks().

◆ GET_PREDICATELOCKTARGETTAG_DB

#define GET_PREDICATELOCKTARGETTAG_DB (   locktag)    ((Oid) (locktag).locktag_field1)

◆ GET_PREDICATELOCKTARGETTAG_OFFSET

#define GET_PREDICATELOCKTARGETTAG_OFFSET (   locktag)    ((OffsetNumber) (locktag).locktag_field4)

Definition at line 413 of file predicate_internals.h.

Referenced by CheckTargetForConflictsIn(), and pg_lock_status().

◆ GET_PREDICATELOCKTARGETTAG_PAGE

#define GET_PREDICATELOCKTARGETTAG_PAGE (   locktag)    ((BlockNumber) (locktag).locktag_field3)

Definition at line 411 of file predicate_internals.h.

Referenced by GetParentPredicateLockTag(), and pg_lock_status().

◆ GET_PREDICATELOCKTARGETTAG_RELATION

#define GET_PREDICATELOCKTARGETTAG_RELATION (   locktag)    ((Oid) (locktag).locktag_field2)

◆ GET_PREDICATELOCKTARGETTAG_TYPE

#define GET_PREDICATELOCKTARGETTAG_TYPE (   locktag)
Value:
(((locktag).locktag_field4 != InvalidOffsetNumber) ? PREDLOCKTAG_TUPLE : \
(((locktag).locktag_field3 != InvalidBlockNumber) ? PREDLOCKTAG_PAGE : \
PREDLOCKTAG_RELATION))
#define InvalidOffsetNumber
Definition: off.h:26
#define InvalidBlockNumber
Definition: block.h:33

Definition at line 415 of file predicate_internals.h.

Referenced by DropAllPredicateLocksFromTable(), GetParentPredicateLockTag(), MaxPredicateChildLocks(), pg_lock_status(), and PredicateLockAcquire().

◆ InvalidSerCommitSeqNo

◆ InvalidSerializableXact

◆ PredXactListDataSize

#define PredXactListDataSize   ((Size)MAXALIGN(sizeof(PredXactListData)))

Definition at line 180 of file predicate_internals.h.

Referenced by InitPredicateLocks(), and PredicateLockShmemSize().

◆ PredXactListElementDataSize

#define PredXactListElementDataSize   ((Size)MAXALIGN(sizeof(PredXactListElementData)))

Definition at line 142 of file predicate_internals.h.

Referenced by InitPredicateLocks(), and PredicateLockShmemSize().

◆ RecoverySerCommitSeqNo

#define RecoverySerCommitSeqNo   ((SerCommitSeqNo) 1)

Definition at line 37 of file predicate_internals.h.

Referenced by predicatelock_twophase_recover().

◆ RWConflictDataSize

#define RWConflictDataSize   ((Size)MAXALIGN(sizeof(RWConflictData)))

Definition at line 204 of file predicate_internals.h.

Referenced by InitPredicateLocks(), and PredicateLockShmemSize().

◆ RWConflictPoolHeaderDataSize

#define RWConflictPoolHeaderDataSize   ((Size)MAXALIGN(sizeof(RWConflictPoolHeaderData)))

Definition at line 215 of file predicate_internals.h.

Referenced by InitPredicateLocks(), and PredicateLockShmemSize().

◆ SET_PREDICATELOCKTARGETTAG_PAGE

#define SET_PREDICATELOCKTARGETTAG_PAGE (   locktag,
  dboid,
  reloid,
  blocknum 
)
Value:
((locktag).locktag_field1 = (dboid), \
(locktag).locktag_field2 = (reloid), \
(locktag).locktag_field3 = (blocknum), \
(locktag).locktag_field4 = InvalidOffsetNumber)
#define InvalidOffsetNumber
Definition: off.h:26

Definition at line 395 of file predicate_internals.h.

Referenced by CheckForSerializableConflictIn(), GetParentPredicateLockTag(), PageIsPredicateLocked(), PredicateLockPage(), and PredicateLockPageSplit().

◆ SET_PREDICATELOCKTARGETTAG_RELATION

#define SET_PREDICATELOCKTARGETTAG_RELATION (   locktag,
  dboid,
  reloid 
)
Value:
((locktag).locktag_field1 = (dboid), \
(locktag).locktag_field2 = (reloid), \
(locktag).locktag_field3 = InvalidBlockNumber, \
(locktag).locktag_field4 = InvalidOffsetNumber)
#define InvalidOffsetNumber
Definition: off.h:26
#define InvalidBlockNumber
Definition: block.h:33

Definition at line 389 of file predicate_internals.h.

Referenced by CheckForSerializableConflictIn(), DropAllPredicateLocksFromTable(), GetParentPredicateLockTag(), PredicateLockRelation(), and PredicateLockTuple().

◆ SET_PREDICATELOCKTARGETTAG_TUPLE

#define SET_PREDICATELOCKTARGETTAG_TUPLE (   locktag,
  dboid,
  reloid,
  blocknum,
  offnum 
)
Value:
((locktag).locktag_field1 = (dboid), \
(locktag).locktag_field2 = (reloid), \
(locktag).locktag_field3 = (blocknum), \
(locktag).locktag_field4 = (offnum))

Definition at line 401 of file predicate_internals.h.

Referenced by CheckForSerializableConflictIn(), and PredicateLockTuple().

◆ SXACT_FLAG_COMMITTED

#define SXACT_FLAG_COMMITTED   0x00000001 /* already committed */

Definition at line 110 of file predicate_internals.h.

Referenced by InitPredicateLocks(), and ReleasePredicateLocks().

◆ SXACT_FLAG_CONFLICT_OUT

#define SXACT_FLAG_CONFLICT_OUT   0x00000010

Definition at line 119 of file predicate_internals.h.

Referenced by ReleasePredicateLocks().

◆ SXACT_FLAG_DEFERRABLE_WAITING

#define SXACT_FLAG_DEFERRABLE_WAITING   0x00000040

Definition at line 121 of file predicate_internals.h.

Referenced by GetSafeSnapshot().

◆ SXACT_FLAG_DOOMED

#define SXACT_FLAG_DOOMED   0x00000008 /* will roll back */

◆ SXACT_FLAG_PREPARED

#define SXACT_FLAG_PREPARED   0x00000002 /* about to commit */

◆ SXACT_FLAG_READ_ONLY

#define SXACT_FLAG_READ_ONLY   0x00000020

◆ SXACT_FLAG_RO_SAFE

#define SXACT_FLAG_RO_SAFE   0x00000080

Definition at line 122 of file predicate_internals.h.

Referenced by ReleasePredicateLocks().

◆ SXACT_FLAG_RO_UNSAFE

#define SXACT_FLAG_RO_UNSAFE   0x00000100

Definition at line 123 of file predicate_internals.h.

Referenced by FlagSxactUnsafe().

◆ SXACT_FLAG_ROLLED_BACK

#define SXACT_FLAG_ROLLED_BACK   0x00000004 /* already rolled back */

Definition at line 112 of file predicate_internals.h.

Referenced by ReleasePredicateLocks().

◆ SXACT_FLAG_SUMMARY_CONFLICT_IN

#define SXACT_FLAG_SUMMARY_CONFLICT_IN   0x00000200

◆ SXACT_FLAG_SUMMARY_CONFLICT_OUT

#define SXACT_FLAG_SUMMARY_CONFLICT_OUT   0x00000400

Typedef Documentation

◆ LOCALPREDICATELOCK

◆ PREDICATELOCK

◆ PredicateLockData

◆ PREDICATELOCKTAG

◆ PREDICATELOCKTARGET

◆ PREDICATELOCKTARGETTAG

◆ PredicateLockTargetType

◆ PredXactList

Definition at line 178 of file predicate_internals.h.

◆ PredXactListData

◆ PredXactListElement

◆ PredXactListElementData

◆ RWConflict

Definition at line 202 of file predicate_internals.h.

◆ RWConflictData

◆ RWConflictPoolHeader

◆ RWConflictPoolHeaderData

◆ SerCommitSeqNo

Definition at line 22 of file predicate_internals.h.

◆ SERIALIZABLEXACT

◆ SERIALIZABLEXID

◆ SERIALIZABLEXIDTAG

◆ TwoPhasePredicateLockRecord

◆ TwoPhasePredicateRecord

◆ TwoPhasePredicateRecordType

◆ TwoPhasePredicateXactRecord

Enumeration Type Documentation

◆ PredicateLockTargetType

Enumerator
PREDLOCKTAG_RELATION 
PREDLOCKTAG_PAGE 
PREDLOCKTAG_TUPLE 

Definition at line 362 of file predicate_internals.h.

363 {
367  /* TODO SSI: Other types may be needed for index locking */
PredicateLockTargetType

◆ TwoPhasePredicateRecordType

Enumerator
TWOPHASEPREDICATERECORD_XACT 
TWOPHASEPREDICATERECORD_LOCK 

Definition at line 425 of file predicate_internals.h.

Function Documentation

◆ GetPredicateLockStatusData()

PredicateLockData* GetPredicateLockStatusData ( void  )

Definition at line 1353 of file predicate.c.

References Assert, hash_get_num_entries(), hash_seq_init(), hash_seq_search(), i, PredicateLockData::locktags, LW_SHARED, LWLockAcquire(), LWLockRelease(), PREDICATELOCKTAG::myTarget, PREDICATELOCKTAG::myXact, PredicateLockData::nelements, NUM_PREDICATELOCK_PARTITIONS, palloc(), PredicateLockHashPartitionLockByIndex, PREDICATELOCKTARGET::tag, PREDICATELOCK::tag, and PredicateLockData::xacts.

Referenced by pg_lock_status().

1354 {
1355  PredicateLockData *data;
1356  int i;
1357  int els,
1358  el;
1359  HASH_SEQ_STATUS seqstat;
1360  PREDICATELOCK *predlock;
1361 
1362  data = (PredicateLockData *) palloc(sizeof(PredicateLockData));
1363 
1364  /*
1365  * To ensure consistency, take simultaneous locks on all partition locks
1366  * in ascending order, then SerializableXactHashLock.
1367  */
1368  for (i = 0; i < NUM_PREDICATELOCK_PARTITIONS; i++)
1370  LWLockAcquire(SerializableXactHashLock, LW_SHARED);
1371 
1372  /* Get number of locks and allocate appropriately-sized arrays. */
1374  data->nelements = els;
1375  data->locktags = (PREDICATELOCKTARGETTAG *)
1376  palloc(sizeof(PREDICATELOCKTARGETTAG) * els);
1377  data->xacts = (SERIALIZABLEXACT *)
1378  palloc(sizeof(SERIALIZABLEXACT) * els);
1379 
1380 
1381  /* Scan through PredicateLockHash and copy contents */
1382  hash_seq_init(&seqstat, PredicateLockHash);
1383 
1384  el = 0;
1385 
1386  while ((predlock = (PREDICATELOCK *) hash_seq_search(&seqstat)))
1387  {
1388  data->locktags[el] = predlock->tag.myTarget->tag;
1389  data->xacts[el] = *predlock->tag.myXact;
1390  el++;
1391  }
1392 
1393  Assert(el == els);
1394 
1395  /* Release locks in reverse order */
1396  LWLockRelease(SerializableXactHashLock);
1397  for (i = NUM_PREDICATELOCK_PARTITIONS - 1; i >= 0; i--)
1399 
1400  return data;
1401 }
long hash_get_num_entries(HTAB *hashp)
Definition: dynahash.c:1335
SERIALIZABLEXACT * xacts
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1725
static HTAB * PredicateLockHash
Definition: predicate.c:386
PREDICATELOCKTARGETTAG * locktags
PREDICATELOCKTAG tag
PREDICATELOCKTARGETTAG tag
#define Assert(condition)
Definition: c.h:699
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1121
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1389
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1379
#define PredicateLockHashPartitionLockByIndex(i)
Definition: predicate.c:250
void * palloc(Size size)
Definition: mcxt.c:924
int i
SERIALIZABLEXACT * myXact
PREDICATELOCKTARGET * myTarget
#define NUM_PREDICATELOCK_PARTITIONS
Definition: lwlock.h:121

◆ GetSafeSnapshotBlockingPids()

int GetSafeSnapshotBlockingPids ( int  blocked_pid,
int *  output,
int  output_size 
)

Definition at line 1538 of file predicate.c.

References FirstPredXact(), RWConflictData::inLink, LW_SHARED, LWLockAcquire(), LWLockRelease(), NextPredXact(), offsetof, SERIALIZABLEXACT::pid, SERIALIZABLEXACT::possibleUnsafeConflicts, SHMQueueNext(), SxactIsDeferrableWaiting, and RWConflictData::sxactOut.

Referenced by pg_isolation_test_session_is_blocked(), and pg_safe_snapshot_blocking_pids().

1539 {
1540  int num_written = 0;
1541  SERIALIZABLEXACT *sxact;
1542 
1543  LWLockAcquire(SerializableXactHashLock, LW_SHARED);
1544 
1545  /* Find blocked_pid's SERIALIZABLEXACT by linear search. */
1546  for (sxact = FirstPredXact(); sxact != NULL; sxact = NextPredXact(sxact))
1547  {
1548  if (sxact->pid == blocked_pid)
1549  break;
1550  }
1551 
1552  /* Did we find it, and is it currently waiting in GetSafeSnapshot? */
1553  if (sxact != NULL && SxactIsDeferrableWaiting(sxact))
1554  {
1555  RWConflict possibleUnsafeConflict;
1556 
1557  /* Traverse the list of possible unsafe conflicts collecting PIDs. */
1558  possibleUnsafeConflict = (RWConflict)
1560  &sxact->possibleUnsafeConflicts,
1561  offsetof(RWConflictData, inLink));
1562 
1563  while (possibleUnsafeConflict != NULL && num_written < output_size)
1564  {
1565  output[num_written++] = possibleUnsafeConflict->sxactOut->pid;
1566  possibleUnsafeConflict = (RWConflict)
1568  &possibleUnsafeConflict->inLink,
1569  offsetof(RWConflictData, inLink));
1570  }
1571  }
1572 
1573  LWLockRelease(SerializableXactHashLock);
1574 
1575  return num_written;
1576 }
static void output(uint64 loop_count)
struct RWConflictData * RWConflict
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1725
SHM_QUEUE possibleUnsafeConflicts
static SERIALIZABLEXACT * NextPredXact(SERIALIZABLEXACT *sxact)
Definition: predicate.c:609
static SERIALIZABLEXACT * FirstPredXact(void)
Definition: predicate.c:594
Pointer SHMQueueNext(const SHM_QUEUE *queue, const SHM_QUEUE *curElem, Size linkOffset)
Definition: shmqueue.c:145
#define SxactIsDeferrableWaiting(sxact)
Definition: predicate.c:279
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1121
#define offsetof(type, field)
Definition: c.h:622
SERIALIZABLEXACT * sxactOut