PostgreSQL Source Code  git master
xid.c File Reference
#include "postgres.h"
#include <limits.h>
#include "access/multixact.h"
#include "access/transam.h"
#include "access/xact.h"
#include "libpq/pqformat.h"
#include "utils/builtins.h"
Include dependency graph for xid.c:

Go to the source code of this file.

Macros

#define PG_GETARG_TRANSACTIONID(n)   DatumGetTransactionId(PG_GETARG_DATUM(n))
 
#define PG_RETURN_TRANSACTIONID(x)   return TransactionIdGetDatum(x)
 
#define PG_GETARG_COMMANDID(n)   DatumGetCommandId(PG_GETARG_DATUM(n))
 
#define PG_RETURN_COMMANDID(x)   return CommandIdGetDatum(x)
 

Functions

Datum xidin (PG_FUNCTION_ARGS)
 
Datum xidout (PG_FUNCTION_ARGS)
 
Datum xidrecv (PG_FUNCTION_ARGS)
 
Datum xidsend (PG_FUNCTION_ARGS)
 
Datum xideq (PG_FUNCTION_ARGS)
 
Datum xidneq (PG_FUNCTION_ARGS)
 
Datum xid_age (PG_FUNCTION_ARGS)
 
Datum mxid_age (PG_FUNCTION_ARGS)
 
int xidComparator (const void *arg1, const void *arg2)
 
Datum cidin (PG_FUNCTION_ARGS)
 
Datum cidout (PG_FUNCTION_ARGS)
 
Datum cidrecv (PG_FUNCTION_ARGS)
 
Datum cidsend (PG_FUNCTION_ARGS)
 
Datum cideq (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

◆ PG_GETARG_COMMANDID

#define PG_GETARG_COMMANDID (   n)    DatumGetCommandId(PG_GETARG_DATUM(n))

Definition at line 28 of file xid.c.

Referenced by cideq(), cidout(), and cidsend().

◆ PG_GETARG_TRANSACTIONID

#define PG_GETARG_TRANSACTIONID (   n)    DatumGetTransactionId(PG_GETARG_DATUM(n))

Definition at line 25 of file xid.c.

Referenced by mxid_age(), xid_age(), xideq(), xidneq(), xidout(), and xidsend().

◆ PG_RETURN_COMMANDID

#define PG_RETURN_COMMANDID (   x)    return CommandIdGetDatum(x)

Definition at line 29 of file xid.c.

Referenced by cidin(), and cidrecv().

◆ PG_RETURN_TRANSACTIONID

#define PG_RETURN_TRANSACTIONID (   x)    return TransactionIdGetDatum(x)

Definition at line 26 of file xid.c.

Referenced by xidin(), and xidrecv().

Function Documentation

◆ cideq()

Datum cideq ( PG_FUNCTION_ARGS  )

Definition at line 204 of file xid.c.

References PG_GETARG_COMMANDID, and PG_RETURN_BOOL.

205 {
206  CommandId arg1 = PG_GETARG_COMMANDID(0);
207  CommandId arg2 = PG_GETARG_COMMANDID(1);
208 
209  PG_RETURN_BOOL(arg1 == arg2);
210 }
uint32 CommandId
Definition: c.h:459
#define PG_GETARG_COMMANDID(n)
Definition: xid.c:28
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ cidin()

Datum cidin ( PG_FUNCTION_ARGS  )

Definition at line 158 of file xid.c.

References PG_GETARG_CSTRING, PG_RETURN_COMMANDID, and generate_unaccent_rules::str.

159 {
160  char *str = PG_GETARG_CSTRING(0);
161 
162  PG_RETURN_COMMANDID((CommandId) strtoul(str, NULL, 0));
163 }
uint32 CommandId
Definition: c.h:459
#define PG_RETURN_COMMANDID(x)
Definition: xid.c:29
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242

◆ cidout()

Datum cidout ( PG_FUNCTION_ARGS  )

Definition at line 169 of file xid.c.

References palloc(), PG_GETARG_COMMANDID, PG_RETURN_CSTRING, and snprintf().

170 {
172  char *result = (char *) palloc(16);
173 
174  snprintf(result, 16, "%lu", (unsigned long) c);
175  PG_RETURN_CSTRING(result);
176 }
uint32 CommandId
Definition: c.h:459
#define PG_GETARG_COMMANDID(n)
Definition: xid.c:28
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
char * c
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
void * palloc(Size size)
Definition: mcxt.c:848

◆ cidrecv()

Datum cidrecv ( PG_FUNCTION_ARGS  )

Definition at line 182 of file xid.c.

References buf, PG_GETARG_POINTER, PG_RETURN_COMMANDID, and pq_getmsgint().

183 {
185 
187 }
uint32 CommandId
Definition: c.h:459
StringInfoData * StringInfo
Definition: stringinfo.h:43
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define PG_RETURN_COMMANDID(x)
Definition: xid.c:29
static char * buf
Definition: pg_test_fsync.c:67
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417

◆ cidsend()

Datum cidsend ( PG_FUNCTION_ARGS  )

Definition at line 193 of file xid.c.

References buf, PG_GETARG_COMMANDID, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint32().

194 {
195  CommandId arg1 = PG_GETARG_COMMANDID(0);
197 
198  pq_begintypsend(&buf);
199  pq_sendint32(&buf, arg1);
201 }
uint32 CommandId
Definition: c.h:459
static void pq_sendint32(StringInfo buf, int32 i)
Definition: pqformat.h:148
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
#define PG_GETARG_COMMANDID(n)
Definition: xid.c:28
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:330
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
static char * buf
Definition: pg_test_fsync.c:67

◆ mxid_age()

Datum mxid_age ( PG_FUNCTION_ARGS  )

Definition at line 119 of file xid.c.

References MultiXactIdIsValid, now(), PG_GETARG_TRANSACTIONID, PG_RETURN_INT32, and ReadNextMultiXactId().

120 {
123 
124  if (!MultiXactIdIsValid(xid))
125  PG_RETURN_INT32(INT_MAX);
126 
127  PG_RETURN_INT32((int32) (now - xid));
128 }
uint32 TransactionId
Definition: c.h:445
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
signed int int32
Definition: c.h:284
#define MultiXactIdIsValid(multi)
Definition: multixact.h:27
TransactionId MultiXactId
Definition: c.h:455
#define PG_GETARG_TRANSACTIONID(n)
Definition: xid.c:25
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1534
MultiXactId ReadNextMultiXactId(void)
Definition: multixact.c:721

◆ xid_age()

Datum xid_age ( PG_FUNCTION_ARGS  )

Definition at line 103 of file xid.c.

References GetStableLatestTransactionId(), now(), PG_GETARG_TRANSACTIONID, PG_RETURN_INT32, and TransactionIdIsNormal.

104 {
107 
108  /* Permanent XIDs are always infinitely old */
109  if (!TransactionIdIsNormal(xid))
110  PG_RETURN_INT32(INT_MAX);
111 
112  PG_RETURN_INT32((int32) (now - xid));
113 }
uint32 TransactionId
Definition: c.h:445
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
signed int int32
Definition: c.h:284
TransactionId GetStableLatestTransactionId(void)
Definition: xact.c:462
#define PG_GETARG_TRANSACTIONID(n)
Definition: xid.c:25
#define TransactionIdIsNormal(xid)
Definition: transam.h:42
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1534

◆ xidComparator()

int xidComparator ( const void *  arg1,
const void *  arg2 
)

Definition at line 138 of file xid.c.

Referenced by ProcArrayApplyRecoveryInfo(), ReorderBufferCopySnap(), SerializeTransactionState(), SnapBuildBuildSnapshot(), SnapBuildInitialSnapshot(), and TransactionIdInArray().

139 {
140  TransactionId xid1 = *(const TransactionId *) arg1;
141  TransactionId xid2 = *(const TransactionId *) arg2;
142 
143  if (xid1 > xid2)
144  return 1;
145  if (xid1 < xid2)
146  return -1;
147  return 0;
148 }
uint32 TransactionId
Definition: c.h:445

◆ xideq()

Datum xideq ( PG_FUNCTION_ARGS  )

Definition at line 79 of file xid.c.

References PG_GETARG_TRANSACTIONID, PG_RETURN_BOOL, and TransactionIdEquals.

80 {
83 
85 }
#define TransactionIdEquals(id1, id2)
Definition: transam.h:43
uint32 TransactionId
Definition: c.h:445
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_TRANSACTIONID(n)
Definition: xid.c:25

◆ xidin()

Datum xidin ( PG_FUNCTION_ARGS  )

Definition at line 33 of file xid.c.

References PG_GETARG_CSTRING, PG_RETURN_TRANSACTIONID, and generate_unaccent_rules::str.

34 {
35  char *str = PG_GETARG_CSTRING(0);
36 
37  PG_RETURN_TRANSACTIONID((TransactionId) strtoul(str, NULL, 0));
38 }
uint32 TransactionId
Definition: c.h:445
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
#define PG_RETURN_TRANSACTIONID(x)
Definition: xid.c:26

◆ xidneq()

Datum xidneq ( PG_FUNCTION_ARGS  )

Definition at line 91 of file xid.c.

References PG_GETARG_TRANSACTIONID, PG_RETURN_BOOL, and TransactionIdEquals.

92 {
95 
96  PG_RETURN_BOOL(!TransactionIdEquals(xid1, xid2));
97 }
#define TransactionIdEquals(id1, id2)
Definition: transam.h:43
uint32 TransactionId
Definition: c.h:445
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_TRANSACTIONID(n)
Definition: xid.c:25

◆ xidout()

Datum xidout ( PG_FUNCTION_ARGS  )

Definition at line 41 of file xid.c.

References palloc(), PG_GETARG_TRANSACTIONID, PG_RETURN_CSTRING, and snprintf().

42 {
43  TransactionId transactionId = PG_GETARG_TRANSACTIONID(0);
44  char *result = (char *) palloc(16);
45 
46  snprintf(result, 16, "%lu", (unsigned long) transactionId);
47  PG_RETURN_CSTRING(result);
48 }
uint32 TransactionId
Definition: c.h:445
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
void * palloc(Size size)
Definition: mcxt.c:848
#define PG_GETARG_TRANSACTIONID(n)
Definition: xid.c:25

◆ xidrecv()

Datum xidrecv ( PG_FUNCTION_ARGS  )

Definition at line 54 of file xid.c.

References buf, PG_GETARG_POINTER, PG_RETURN_TRANSACTIONID, and pq_getmsgint().

55 {
57 
59 }
uint32 TransactionId
Definition: c.h:445
StringInfoData * StringInfo
Definition: stringinfo.h:43
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static char * buf
Definition: pg_test_fsync.c:67
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417
#define PG_RETURN_TRANSACTIONID(x)
Definition: xid.c:26

◆ xidsend()

Datum xidsend ( PG_FUNCTION_ARGS  )

Definition at line 65 of file xid.c.

References buf, PG_GETARG_TRANSACTIONID, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint32().

66 {
69 
70  pq_begintypsend(&buf);
71  pq_sendint32(&buf, arg1);
73 }
uint32 TransactionId
Definition: c.h:445
static void pq_sendint32(StringInfo buf, int32 i)
Definition: pqformat.h:148
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:330
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
static char * buf
Definition: pg_test_fsync.c:67
#define PG_GETARG_TRANSACTIONID(n)
Definition: xid.c:25