PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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

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

Definition at line 28 of file xid.c.

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

#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().

#define PG_RETURN_COMMANDID (   x)    return CommandIdGetDatum(x)

Definition at line 29 of file xid.c.

Referenced by cidin(), and cidrecv().

#define PG_RETURN_TRANSACTIONID (   x)    return TransactionIdGetDatum(x)

Definition at line 26 of file xid.c.

Referenced by xidin(), and xidrecv().

Function Documentation

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:411
#define PG_GETARG_COMMANDID(n)
Definition: xid.c:28
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Datum cidin ( PG_FUNCTION_ARGS  )

Definition at line 158 of file xid.c.

References NULL, PG_GETARG_CSTRING, and PG_RETURN_COMMANDID.

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

Definition at line 169 of file xid.c.

References palloc(), PG_GETARG_COMMANDID, PG_RETURN_CSTRING, result, 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:411
#define PG_GETARG_COMMANDID(n)
Definition: xid.c:28
return result
Definition: formatting.c:1632
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:849
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:411
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:66
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:448
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_sendint().

194 {
195  CommandId arg1 = PG_GETARG_COMMANDID(0);
197 
198  pq_begintypsend(&buf);
199  pq_sendint(&buf, arg1, sizeof(arg1));
201 }
uint32 CommandId
Definition: c.h:411
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:359
#define PG_GETARG_COMMANDID(n)
Definition: xid.c:28
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:329
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:379
static char * buf
Definition: pg_test_fsync.c:66
void pq_sendint(StringInfo buf, int i, int b)
Definition: pqformat.c:236
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:397
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
signed int int32
Definition: c.h:256
#define MultiXactIdIsValid(multi)
Definition: multixact.h:27
TransactionId MultiXactId
Definition: c.h:407
#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
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:397
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
signed int int32
Definition: c.h:256
TransactionId GetStableLatestTransactionId(void)
Definition: xact.c:461
#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
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:397
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:397
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_TRANSACTIONID(n)
Definition: xid.c:25
Datum xidin ( PG_FUNCTION_ARGS  )

Definition at line 33 of file xid.c.

References NULL, PG_GETARG_CSTRING, and PG_RETURN_TRANSACTIONID.

34 {
35  char *str = PG_GETARG_CSTRING(0);
36 
37  PG_RETURN_TRANSACTIONID((TransactionId) strtoul(str, NULL, 0));
38 }
uint32 TransactionId
Definition: c.h:397
#define NULL
Definition: c.h:229
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
#define PG_RETURN_TRANSACTIONID(x)
Definition: xid.c:26
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:397
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_TRANSACTIONID(n)
Definition: xid.c:25
Datum xidout ( PG_FUNCTION_ARGS  )

Definition at line 41 of file xid.c.

References palloc(), PG_GETARG_TRANSACTIONID, PG_RETURN_CSTRING, result, 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:397
return result
Definition: formatting.c:1632
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:849
#define PG_GETARG_TRANSACTIONID(n)
Definition: xid.c:25
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:397
StringInfoData * StringInfo
Definition: stringinfo.h:43
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static char * buf
Definition: pg_test_fsync.c:66
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:448
#define PG_RETURN_TRANSACTIONID(x)
Definition: xid.c:26
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_sendint().

66 {
69 
70  pq_begintypsend(&buf);
71  pq_sendint(&buf, arg1, sizeof(arg1));
73 }
uint32 TransactionId
Definition: c.h:397
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:359
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:329
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:379
static char * buf
Definition: pg_test_fsync.c:66
void pq_sendint(StringInfo buf, int i, int b)
Definition: pqformat.c:236
#define PG_GETARG_TRANSACTIONID(n)
Definition: xid.c:25