PostgreSQL Source Code  git master
predicate_internals.h File Reference
#include "lib/ilist.h"
#include "storage/lock.h"
#include "storage/lwlock.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  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 SXACT_FLAG_PARTIALLY_RELEASED   0x00000800
 
#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 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 40 of file predicate_internals.h.

◆ GET_PREDICATELOCKTARGETTAG_DB

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

Definition at line 406 of file predicate_internals.h.

◆ GET_PREDICATELOCKTARGETTAG_OFFSET

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

Definition at line 412 of file predicate_internals.h.

◆ GET_PREDICATELOCKTARGETTAG_PAGE

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

Definition at line 410 of file predicate_internals.h.

◆ GET_PREDICATELOCKTARGETTAG_RELATION

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

Definition at line 408 of file predicate_internals.h.

◆ GET_PREDICATELOCKTARGETTAG_TYPE

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

Definition at line 414 of file predicate_internals.h.

◆ InvalidSerCommitSeqNo

#define InvalidSerCommitSeqNo   ((SerCommitSeqNo) PG_UINT64_MAX)

Definition at line 38 of file predicate_internals.h.

◆ InvalidSerializableXact

#define InvalidSerializableXact   ((SERIALIZABLEXACT *) NULL)

Definition at line 467 of file predicate_internals.h.

◆ PredXactListDataSize

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

Definition at line 179 of file predicate_internals.h.

◆ RecoverySerCommitSeqNo

#define RecoverySerCommitSeqNo   ((SerCommitSeqNo) 1)

Definition at line 39 of file predicate_internals.h.

◆ RWConflictDataSize

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

Definition at line 203 of file predicate_internals.h.

◆ RWConflictPoolHeaderDataSize

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

Definition at line 214 of file predicate_internals.h.

◆ 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)

Definition at line 394 of file predicate_internals.h.

◆ 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)

Definition at line 388 of file predicate_internals.h.

◆ 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 400 of file predicate_internals.h.

◆ SXACT_FLAG_COMMITTED

#define SXACT_FLAG_COMMITTED   0x00000001 /* already committed */

Definition at line 121 of file predicate_internals.h.

◆ SXACT_FLAG_CONFLICT_OUT

#define SXACT_FLAG_CONFLICT_OUT   0x00000010

Definition at line 130 of file predicate_internals.h.

◆ SXACT_FLAG_DEFERRABLE_WAITING

#define SXACT_FLAG_DEFERRABLE_WAITING   0x00000040

Definition at line 132 of file predicate_internals.h.

◆ SXACT_FLAG_DOOMED

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

Definition at line 124 of file predicate_internals.h.

◆ SXACT_FLAG_PARTIALLY_RELEASED

#define SXACT_FLAG_PARTIALLY_RELEASED   0x00000800

Definition at line 142 of file predicate_internals.h.

◆ SXACT_FLAG_PREPARED

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

Definition at line 122 of file predicate_internals.h.

◆ SXACT_FLAG_READ_ONLY

#define SXACT_FLAG_READ_ONLY   0x00000020

Definition at line 131 of file predicate_internals.h.

◆ SXACT_FLAG_RO_SAFE

#define SXACT_FLAG_RO_SAFE   0x00000080

Definition at line 133 of file predicate_internals.h.

◆ SXACT_FLAG_RO_UNSAFE

#define SXACT_FLAG_RO_UNSAFE   0x00000100

Definition at line 134 of file predicate_internals.h.

◆ SXACT_FLAG_ROLLED_BACK

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

Definition at line 123 of file predicate_internals.h.

◆ SXACT_FLAG_SUMMARY_CONFLICT_IN

#define SXACT_FLAG_SUMMARY_CONFLICT_IN   0x00000200

Definition at line 135 of file predicate_internals.h.

◆ SXACT_FLAG_SUMMARY_CONFLICT_OUT

#define SXACT_FLAG_SUMMARY_CONFLICT_OUT   0x00000400

Definition at line 136 of file predicate_internals.h.

Typedef Documentation

◆ LOCALPREDICATELOCK

◆ PREDICATELOCK

typedef struct PREDICATELOCK PREDICATELOCK

◆ PredicateLockData

◆ PREDICATELOCKTAG

◆ PREDICATELOCKTARGET

◆ PREDICATELOCKTARGETTAG

◆ PredicateLockTargetType

◆ PredXactList

typedef struct PredXactListData* PredXactList

Definition at line 177 of file predicate_internals.h.

◆ PredXactListData

◆ RWConflict

typedef struct RWConflictData* RWConflict

Definition at line 201 of file predicate_internals.h.

◆ RWConflictData

◆ RWConflictPoolHeader

Definition at line 212 of file predicate_internals.h.

◆ RWConflictPoolHeaderData

◆ SerCommitSeqNo

typedef uint64 SerCommitSeqNo

Definition at line 24 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 361 of file predicate_internals.h.

362 {
366  /* TODO SSI: Other types may be needed for index locking */
PredicateLockTargetType
@ PREDLOCKTAG_RELATION

◆ TwoPhasePredicateRecordType

Enumerator
TWOPHASEPREDICATERECORD_XACT 
TWOPHASEPREDICATERECORD_LOCK 

Definition at line 424 of file predicate_internals.h.

Function Documentation

◆ GetPredicateLockStatusData()

PredicateLockData* GetPredicateLockStatusData ( void  )

Definition at line 1396 of file predicate.c.

1397 {
1399  int i;
1400  int els,
1401  el;
1402  HASH_SEQ_STATUS seqstat;
1403  PREDICATELOCK *predlock;
1404 
1406 
1407  /*
1408  * To ensure consistency, take simultaneous locks on all partition locks
1409  * in ascending order, then SerializableXactHashLock.
1410  */
1411  for (i = 0; i < NUM_PREDICATELOCK_PARTITIONS; i++)
1413  LWLockAcquire(SerializableXactHashLock, LW_SHARED);
1414 
1415  /* Get number of locks and allocate appropriately-sized arrays. */
1417  data->nelements = els;
1418  data->locktags = (PREDICATELOCKTARGETTAG *)
1419  palloc(sizeof(PREDICATELOCKTARGETTAG) * els);
1420  data->xacts = (SERIALIZABLEXACT *)
1421  palloc(sizeof(SERIALIZABLEXACT) * els);
1422 
1423 
1424  /* Scan through PredicateLockHash and copy contents */
1425  hash_seq_init(&seqstat, PredicateLockHash);
1426 
1427  el = 0;
1428 
1429  while ((predlock = (PREDICATELOCK *) hash_seq_search(&seqstat)))
1430  {
1431  data->locktags[el] = predlock->tag.myTarget->tag;
1432  data->xacts[el] = *predlock->tag.myXact;
1433  el++;
1434  }
1435 
1436  Assert(el == els);
1437 
1438  /* Release locks in reverse order */
1439  LWLockRelease(SerializableXactHashLock);
1440  for (i = NUM_PREDICATELOCK_PARTITIONS - 1; i >= 0; i--)
1442 
1443  return data;
1444 }
long hash_get_num_entries(HTAB *hashp)
Definition: dynahash.c:1377
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1431
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1421
int i
Definition: isn.c:73
Assert(fmt[strlen(fmt) - 1] !='\n')
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1195
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1808
@ LW_SHARED
Definition: lwlock.h:117
#define NUM_PREDICATELOCK_PARTITIONS
Definition: lwlock.h:103
void * palloc(Size size)
Definition: mcxt.c:1226
const void * data
static HTAB * PredicateLockHash
Definition: predicate.c:394
#define PredicateLockHashPartitionLockByIndex(i)
Definition: predicate.c:257
SERIALIZABLEXACT * myXact
PREDICATELOCKTARGET * myTarget
PREDICATELOCKTARGETTAG tag
PREDICATELOCKTAG tag

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

Referenced by pg_lock_status().

◆ GetSafeSnapshotBlockingPids()

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

Definition at line 1579 of file predicate.c.

1580 {
1581  int num_written = 0;
1582  dlist_iter iter;
1583  SERIALIZABLEXACT *blocking_sxact = NULL;
1584 
1585  LWLockAcquire(SerializableXactHashLock, LW_SHARED);
1586 
1587  /* Find blocked_pid's SERIALIZABLEXACT by linear search. */
1589  {
1590  SERIALIZABLEXACT *sxact =
1591  dlist_container(SERIALIZABLEXACT, xactLink, iter.cur);
1592 
1593  if (sxact->pid == blocked_pid)
1594  {
1595  blocking_sxact = sxact;
1596  break;
1597  }
1598  }
1599 
1600  /* Did we find it, and is it currently waiting in GetSafeSnapshot? */
1601  if (blocking_sxact != NULL && SxactIsDeferrableWaiting(blocking_sxact))
1602  {
1603  /* Traverse the list of possible unsafe conflicts collecting PIDs. */
1604  dlist_foreach(iter, &blocking_sxact->possibleUnsafeConflicts)
1605  {
1606  RWConflict possibleUnsafeConflict =
1607  dlist_container(RWConflictData, inLink, iter.cur);
1608 
1609  output[num_written++] = possibleUnsafeConflict->sxactOut->pid;
1610 
1611  if (num_written >= output_size)
1612  break;
1613  }
1614  }
1615 
1616  LWLockRelease(SerializableXactHashLock);
1617 
1618  return num_written;
1619 }
#define dlist_foreach(iter, lhead)
Definition: ilist.h:623
#define dlist_container(type, membername, ptr)
Definition: ilist.h:593
FILE * output
#define SxactIsDeferrableWaiting(sxact)
Definition: predicate.c:286
static PredXactList PredXact
Definition: predicate.c:380
SERIALIZABLEXACT * sxactOut
dlist_head possibleUnsafeConflicts
dlist_node * cur
Definition: ilist.h:179

References PredXactListData::activeList, dlist_iter::cur, dlist_container, dlist_foreach, LW_SHARED, LWLockAcquire(), LWLockRelease(), output, SERIALIZABLEXACT::pid, SERIALIZABLEXACT::possibleUnsafeConflicts, PredXact, SxactIsDeferrableWaiting, and RWConflictData::sxactOut.

Referenced by pg_isolation_test_session_is_blocked(), and pg_safe_snapshot_blocking_pids().