PostgreSQL Source Code  git master
xid8funcs.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  * xid8funcs.c
3  *
4  * Export internal transaction IDs to user level.
5  *
6  * Note that only top-level transaction IDs are exposed to user sessions.
7  * This is important because xid8s frequently persist beyond the global
8  * xmin horizon, or may even be shipped to other machines, so we cannot
9  * rely on being able to correlate subtransaction IDs with their parents
10  * via functions such as SubTransGetTopmostTransaction().
11  *
12  * These functions are used to support the txid_XXX functions and the newer
13  * pg_current_xact_id, pg_current_snapshot and related fmgr functions, since
14  * the only difference between them is whether they expose xid8 or int8 values
15  * to users. The txid_XXX variants should eventually be dropped.
16  *
17  *
18  * Copyright (c) 2003-2023, PostgreSQL Global Development Group
19  * Author: Jan Wieck, Afilias USA INC.
20  * 64-bit txids: Marko Kreen, Skype Technologies
21  *
22  * src/backend/utils/adt/xid8funcs.c
23  *
24  *-------------------------------------------------------------------------
25  */
26 
27 #include "postgres.h"
28 
29 #include "access/clog.h"
30 #include "access/transam.h"
31 #include "access/xact.h"
32 #include "access/xlog.h"
33 #include "funcapi.h"
34 #include "lib/qunique.h"
35 #include "libpq/pqformat.h"
36 #include "miscadmin.h"
37 #include "postmaster/postmaster.h"
38 #include "storage/lwlock.h"
39 #include "storage/procarray.h"
40 #include "utils/builtins.h"
41 #include "utils/memutils.h"
42 #include "utils/snapmgr.h"
43 #include "utils/xid8.h"
44 
45 
46 /*
47  * If defined, use bsearch() function for searching for xid8s in snapshots
48  * that have more than the specified number of values.
49  */
50 #define USE_BSEARCH_IF_NXIP_GREATER 30
51 
52 
53 /*
54  * Snapshot containing FullTransactionIds.
55  */
56 typedef struct
57 {
58  /*
59  * 4-byte length hdr, should not be touched directly.
60  *
61  * Explicit embedding is ok as we want always correct alignment anyway.
62  */
64 
65  uint32 nxip; /* number of fxids in xip array */
68  /* in-progress fxids, xmin <= xip[i] < xmax: */
70 } pg_snapshot;
71 
72 #define PG_SNAPSHOT_SIZE(nxip) \
73  (offsetof(pg_snapshot, xip) + sizeof(FullTransactionId) * (nxip))
74 #define PG_SNAPSHOT_MAX_NXIP \
75  ((MaxAllocSize - offsetof(pg_snapshot, xip)) / sizeof(FullTransactionId))
76 
77 /*
78  * Compile-time limits on the procarray (MAX_BACKENDS processes plus
79  * MAX_BACKENDS prepared transactions) guarantee nxip won't be too large.
80  */
82  "possible overflow in pg_current_snapshot()");
83 
84 
85 /*
86  * Helper to get a TransactionId from a 64-bit xid with wraparound detection.
87  *
88  * It is an ERROR if the xid is in the future. Otherwise, returns true if
89  * the transaction is still new enough that we can determine whether it
90  * committed and false otherwise. If *extracted_xid is not NULL, it is set
91  * to the low 32 bits of the transaction ID (i.e. the actual XID, without the
92  * epoch).
93  *
94  * The caller must hold XactTruncationLock since it's dealing with arbitrary
95  * XIDs, and must continue to hold it until it's done with any clog lookups
96  * relating to those XIDs.
97  */
98 static bool
100 {
101  uint32 xid_epoch = EpochFromFullTransactionId(fxid);
103  uint32 now_epoch;
104  TransactionId now_epoch_next_xid;
105  FullTransactionId now_fullxid;
106 
107  now_fullxid = ReadNextFullTransactionId();
108  now_epoch_next_xid = XidFromFullTransactionId(now_fullxid);
109  now_epoch = EpochFromFullTransactionId(now_fullxid);
110 
111  if (extracted_xid != NULL)
112  *extracted_xid = xid;
113 
114  if (!TransactionIdIsValid(xid))
115  return false;
116 
117  /* For non-normal transaction IDs, we can ignore the epoch. */
118  if (!TransactionIdIsNormal(xid))
119  return true;
120 
121  /* If the transaction ID is in the future, throw an error. */
122  if (!FullTransactionIdPrecedes(fxid, now_fullxid))
123  ereport(ERROR,
124  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
125  errmsg("transaction ID %llu is in the future",
126  (unsigned long long) U64FromFullTransactionId(fxid))));
127 
128  /*
129  * ShmemVariableCache->oldestClogXid is protected by XactTruncationLock,
130  * but we don't acquire that lock here. Instead, we require the caller to
131  * acquire it, because the caller is presumably going to look up the
132  * returned XID. If we took and released the lock within this function, a
133  * CLOG truncation could occur before the caller finished with the XID.
134  */
135  Assert(LWLockHeldByMe(XactTruncationLock));
136 
137  /*
138  * If the transaction ID has wrapped around, it's definitely too old to
139  * determine the commit status. Otherwise, we can compare it to
140  * ShmemVariableCache->oldestClogXid to determine whether the relevant
141  * CLOG entry is guaranteed to still exist.
142  */
143  if (xid_epoch + 1 < now_epoch
144  || (xid_epoch + 1 == now_epoch && xid < now_epoch_next_xid)
146  return false;
147 
148  return true;
149 }
150 
151 /*
152  * Convert a TransactionId obtained from a snapshot held by the caller to a
153  * FullTransactionId. Use next_fxid as a reference FullTransactionId, so that
154  * we can compute the high order bits. It must have been obtained by the
155  * caller with ReadNextFullTransactionId() after the snapshot was created.
156  */
157 static FullTransactionId
159 {
160  TransactionId next_xid = XidFromFullTransactionId(next_fxid);
162 
163  /* Special transaction ID. */
164  if (!TransactionIdIsNormal(xid))
165  return FullTransactionIdFromEpochAndXid(0, xid);
166 
167  /*
168  * The 64 bit result must be <= next_fxid, since next_fxid hadn't been
169  * issued yet when the snapshot was created. Every TransactionId in the
170  * snapshot must therefore be from the same epoch as next_fxid, or the
171  * epoch before. We know this because next_fxid is never allow to get
172  * more than one epoch ahead of the TransactionIds in any snapshot.
173  */
174  if (xid > next_xid)
175  epoch--;
176 
178 }
179 
180 /*
181  * txid comparator for qsort/bsearch
182  */
183 static int
184 cmp_fxid(const void *aa, const void *bb)
185 {
186  FullTransactionId a = *(const FullTransactionId *) aa;
187  FullTransactionId b = *(const FullTransactionId *) bb;
188 
190  return -1;
192  return 1;
193  return 0;
194 }
195 
196 /*
197  * Sort a snapshot's txids, so we can use bsearch() later. Also remove
198  * any duplicates.
199  *
200  * For consistency of on-disk representation, we always sort even if bsearch
201  * will not be used.
202  */
203 static void
205 {
206  if (snap->nxip > 1)
207  {
208  qsort(snap->xip, snap->nxip, sizeof(FullTransactionId), cmp_fxid);
209  snap->nxip = qunique(snap->xip, snap->nxip, sizeof(FullTransactionId),
210  cmp_fxid);
211  }
212 }
213 
214 /*
215  * check fxid visibility.
216  */
217 static bool
219 {
221  return true;
222  else if (!FullTransactionIdPrecedes(value, snap->xmax))
223  return false;
224 #ifdef USE_BSEARCH_IF_NXIP_GREATER
225  else if (snap->nxip > USE_BSEARCH_IF_NXIP_GREATER)
226  {
227  void *res;
228 
229  res = bsearch(&value, snap->xip, snap->nxip, sizeof(FullTransactionId),
230  cmp_fxid);
231  /* if found, transaction is still in progress */
232  return (res) ? false : true;
233  }
234 #endif
235  else
236  {
237  uint32 i;
238 
239  for (i = 0; i < snap->nxip; i++)
240  {
241  if (FullTransactionIdEquals(value, snap->xip[i]))
242  return false;
243  }
244  return true;
245  }
246 }
247 
248 /*
249  * helper functions to use StringInfo for pg_snapshot creation.
250  */
251 
252 static StringInfo
254 {
255  pg_snapshot snap;
256  StringInfo buf;
257 
258  snap.xmin = xmin;
259  snap.xmax = xmax;
260  snap.nxip = 0;
261 
262  buf = makeStringInfo();
264  return buf;
265 }
266 
267 static void
269 {
270  pg_snapshot *snap = (pg_snapshot *) buf->data;
271 
272  /* do this before possible realloc */
273  snap->nxip++;
274 
275  appendBinaryStringInfo(buf, &fxid, sizeof(fxid));
276 }
277 
278 static pg_snapshot *
280 {
281  pg_snapshot *snap = (pg_snapshot *) buf->data;
282 
283  SET_VARSIZE(snap, buf->len);
284 
285  /* buf is not needed anymore */
286  buf->data = NULL;
287  pfree(buf);
288 
289  return snap;
290 }
291 
292 /*
293  * parse snapshot from cstring
294  */
295 static pg_snapshot *
296 parse_snapshot(const char *str, Node *escontext)
297 {
298  FullTransactionId xmin;
299  FullTransactionId xmax;
302  const char *str_start = str;
303  char *endp;
304  StringInfo buf;
305 
306  xmin = FullTransactionIdFromU64(strtou64(str, &endp, 10));
307  if (*endp != ':')
308  goto bad_format;
309  str = endp + 1;
310 
311  xmax = FullTransactionIdFromU64(strtou64(str, &endp, 10));
312  if (*endp != ':')
313  goto bad_format;
314  str = endp + 1;
315 
316  /* it should look sane */
317  if (!FullTransactionIdIsValid(xmin) ||
318  !FullTransactionIdIsValid(xmax) ||
319  FullTransactionIdPrecedes(xmax, xmin))
320  goto bad_format;
321 
322  /* allocate buffer */
323  buf = buf_init(xmin, xmax);
324 
325  /* loop over values */
326  while (*str != '\0')
327  {
328  /* read next value */
329  val = FullTransactionIdFromU64(strtou64(str, &endp, 10));
330  str = endp;
331 
332  /* require the input to be in order */
333  if (FullTransactionIdPrecedes(val, xmin) ||
335  FullTransactionIdPrecedes(val, last_val))
336  goto bad_format;
337 
338  /* skip duplicates */
339  if (!FullTransactionIdEquals(val, last_val))
340  buf_add_txid(buf, val);
341  last_val = val;
342 
343  if (*str == ',')
344  str++;
345  else if (*str != '\0')
346  goto bad_format;
347  }
348 
349  return buf_finalize(buf);
350 
351 bad_format:
352  ereturn(escontext, NULL,
353  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
354  errmsg("invalid input syntax for type %s: \"%s\"",
355  "pg_snapshot", str_start)));
356 }
357 
358 /*
359  * pg_current_xact_id() returns xid8
360  *
361  * Return the current toplevel full transaction ID.
362  * If the current transaction does not have one, one is assigned.
363  */
364 Datum
366 {
367  /*
368  * Must prevent during recovery because if an xid is not assigned we try
369  * to assign one, which would fail. Programs already rely on this function
370  * to always return a valid current xid, so we should not change this to
371  * return NULL or similar invalid xid.
372  */
373  PreventCommandDuringRecovery("pg_current_xact_id()");
374 
376 }
377 
378 /*
379  * Same as pg_current_xact_id() but doesn't assign a new xid if there
380  * isn't one yet.
381  */
382 Datum
384 {
386 
387  if (!FullTransactionIdIsValid(topfxid))
388  PG_RETURN_NULL();
389 
391 }
392 
393 /*
394  * pg_current_snapshot() returns pg_snapshot
395  *
396  * Return current snapshot
397  *
398  * Note that only top-transaction XIDs are included in the snapshot.
399  */
400 Datum
402 {
403  pg_snapshot *snap;
404  uint32 nxip,
405  i;
406  Snapshot cur;
408 
410  if (cur == NULL)
411  elog(ERROR, "no active snapshot set");
412 
413  /* allocate */
414  nxip = cur->xcnt;
415  snap = palloc(PG_SNAPSHOT_SIZE(nxip));
416 
417  /* fill */
418  snap->xmin = widen_snapshot_xid(cur->xmin, next_fxid);
419  snap->xmax = widen_snapshot_xid(cur->xmax, next_fxid);
420  snap->nxip = nxip;
421  for (i = 0; i < nxip; i++)
422  snap->xip[i] = widen_snapshot_xid(cur->xip[i], next_fxid);
423 
424  /*
425  * We want them guaranteed to be in ascending order. This also removes
426  * any duplicate xids. Normally, an XID can only be assigned to one
427  * backend, but when preparing a transaction for two-phase commit, there
428  * is a transient state when both the original backend and the dummy
429  * PGPROC entry reserved for the prepared transaction hold the same XID.
430  */
431  sort_snapshot(snap);
432 
433  /* set size after sorting, because it may have removed duplicate xips */
434  SET_VARSIZE(snap, PG_SNAPSHOT_SIZE(snap->nxip));
435 
436  PG_RETURN_POINTER(snap);
437 }
438 
439 /*
440  * pg_snapshot_in(cstring) returns pg_snapshot
441  *
442  * input function for type pg_snapshot
443  */
444 Datum
446 {
447  char *str = PG_GETARG_CSTRING(0);
448  pg_snapshot *snap;
449 
450  snap = parse_snapshot(str, fcinfo->context);
451 
452  PG_RETURN_POINTER(snap);
453 }
454 
455 /*
456  * pg_snapshot_out(pg_snapshot) returns cstring
457  *
458  * output function for type pg_snapshot
459  */
460 Datum
462 {
465  uint32 i;
466 
468 
473 
474  for (i = 0; i < snap->nxip; i++)
475  {
476  if (i > 0)
477  appendStringInfoChar(&str, ',');
479  U64FromFullTransactionId(snap->xip[i]));
480  }
481 
482  PG_RETURN_CSTRING(str.data);
483 }
484 
485 /*
486  * pg_snapshot_recv(internal) returns pg_snapshot
487  *
488  * binary input function for type pg_snapshot
489  *
490  * format: int4 nxip, int8 xmin, int8 xmax, int8 xip
491  */
492 Datum
494 {
496  pg_snapshot *snap;
498  int nxip;
499  int i;
500  FullTransactionId xmin;
501  FullTransactionId xmax;
502 
503  /* load and validate nxip */
504  nxip = pq_getmsgint(buf, 4);
505  if (nxip < 0 || nxip > PG_SNAPSHOT_MAX_NXIP)
506  goto bad_format;
507 
508  xmin = FullTransactionIdFromU64((uint64) pq_getmsgint64(buf));
509  xmax = FullTransactionIdFromU64((uint64) pq_getmsgint64(buf));
510  if (!FullTransactionIdIsValid(xmin) ||
511  !FullTransactionIdIsValid(xmax) ||
512  FullTransactionIdPrecedes(xmax, xmin))
513  goto bad_format;
514 
515  snap = palloc(PG_SNAPSHOT_SIZE(nxip));
516  snap->xmin = xmin;
517  snap->xmax = xmax;
518 
519  for (i = 0; i < nxip; i++)
520  {
523 
524  if (FullTransactionIdPrecedes(cur, last) ||
527  goto bad_format;
528 
529  /* skip duplicate xips */
530  if (FullTransactionIdEquals(cur, last))
531  {
532  i--;
533  nxip--;
534  continue;
535  }
536 
537  snap->xip[i] = cur;
538  last = cur;
539  }
540  snap->nxip = nxip;
541  SET_VARSIZE(snap, PG_SNAPSHOT_SIZE(nxip));
542  PG_RETURN_POINTER(snap);
543 
544 bad_format:
545  ereport(ERROR,
546  (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
547  errmsg("invalid external pg_snapshot data")));
548  PG_RETURN_POINTER(NULL); /* keep compiler quiet */
549 }
550 
551 /*
552  * pg_snapshot_send(pg_snapshot) returns bytea
553  *
554  * binary output function for type pg_snapshot
555  *
556  * format: int4 nxip, u64 xmin, u64 xmax, u64 xip...
557  */
558 Datum
560 {
563  uint32 i;
564 
566  pq_sendint32(&buf, snap->nxip);
567  pq_sendint64(&buf, (int64) U64FromFullTransactionId(snap->xmin));
568  pq_sendint64(&buf, (int64) U64FromFullTransactionId(snap->xmax));
569  for (i = 0; i < snap->nxip; i++)
570  pq_sendint64(&buf, (int64) U64FromFullTransactionId(snap->xip[i]));
572 }
573 
574 /*
575  * pg_visible_in_snapshot(xid8, pg_snapshot) returns bool
576  *
577  * is txid visible in snapshot ?
578  */
579 Datum
581 {
584 
586 }
587 
588 /*
589  * pg_snapshot_xmin(pg_snapshot) returns xid8
590  *
591  * return snapshot's xmin
592  */
593 Datum
595 {
597 
599 }
600 
601 /*
602  * pg_snapshot_xmax(pg_snapshot) returns xid8
603  *
604  * return snapshot's xmax
605  */
606 Datum
608 {
610 
612 }
613 
614 /*
615  * pg_snapshot_xip(pg_snapshot) returns setof xid8
616  *
617  * return in-progress xid8s in snapshot.
618  */
619 Datum
621 {
622  FuncCallContext *fctx;
623  pg_snapshot *snap;
625 
626  /* on first call initialize fctx and get copy of snapshot */
627  if (SRF_IS_FIRSTCALL())
628  {
630 
631  fctx = SRF_FIRSTCALL_INIT();
632 
633  /* make a copy of user snapshot */
635  memcpy(snap, arg, VARSIZE(arg));
636 
637  fctx->user_fctx = snap;
638  }
639 
640  /* return values one-by-one */
641  fctx = SRF_PERCALL_SETUP();
642  snap = fctx->user_fctx;
643  if (fctx->call_cntr < snap->nxip)
644  {
645  value = snap->xip[fctx->call_cntr];
647  }
648  else
649  {
650  SRF_RETURN_DONE(fctx);
651  }
652 }
653 
654 /*
655  * Report the status of a recent transaction ID, or null for wrapped,
656  * truncated away or otherwise too old XIDs.
657  *
658  * The passed epoch-qualified xid is treated as a normal xid, not a
659  * multixact id.
660  *
661  * If it points to a committed subxact the result is the subxact status even
662  * though the parent xact may still be in progress or may have aborted.
663  */
664 Datum
666 {
667  const char *status;
669  TransactionId xid;
670 
671  /*
672  * We must protect against concurrent truncation of clog entries to avoid
673  * an I/O error on SLRU lookup.
674  */
675  LWLockAcquire(XactTruncationLock, LW_SHARED);
676  if (TransactionIdInRecentPast(fxid, &xid))
677  {
679 
680  /*
681  * Like when doing visibility checks on a row, check whether the
682  * transaction is still in progress before looking into the CLOG.
683  * Otherwise we would incorrectly return "committed" for a transaction
684  * that is committing and has already updated the CLOG, but hasn't
685  * removed its XID from the proc array yet. (See comment on that race
686  * condition at the top of heapam_visibility.c)
687  */
688  if (TransactionIdIsInProgress(xid))
689  status = "in progress";
690  else if (TransactionIdDidCommit(xid))
691  status = "committed";
692  else
693  {
694  /* it must have aborted or crashed */
695  status = "aborted";
696  }
697  }
698  else
699  {
700  status = NULL;
701  }
702  LWLockRelease(XactTruncationLock);
703 
704  if (status == NULL)
705  PG_RETURN_NULL();
706  else
708 }
unsigned int uint32
Definition: c.h:495
signed int int32
Definition: c.h:483
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:387
#define UINT64_FORMAT
Definition: c.h:538
#define strtou64(str, endptr, base)
Definition: c.h:1308
uint32 TransactionId
Definition: c.h:641
struct cursor * cur
Definition: ecpg.c:28
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define ereturn(context, dummy_value,...)
Definition: elog.h:276
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
#define PG_GETARG_VARLENA_P(n)
Definition: fmgr.h:287
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:371
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:362
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
#define PG_RETURN_NULL()
Definition: fmgr.h:345
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:372
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:304
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:308
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:310
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:306
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:328
long val
Definition: informix.c:664
static struct @148 value
int b
Definition: isn.c:70
return false
Definition: isn.c:131
int a
Definition: isn.c:69
int i
Definition: isn.c:73
Assert(fmt[strlen(fmt) - 1] !='\n')
bool LWLockHeldByMe(LWLock *lock)
Definition: lwlock.c:1920
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1195
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1808
@ LW_SHARED
Definition: lwlock.h:117
void pfree(void *pointer)
Definition: mcxt.c:1456
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1021
void * palloc(Size size)
Definition: mcxt.c:1226
void * arg
static char * buf
Definition: pg_test_fsync.c:73
#define qsort(a, b, c, d)
Definition: port.h:445
uintptr_t Datum
Definition: postgres.h:64
#define MAX_BACKENDS
Definition: postmaster.h:78
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:418
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:329
int64 pq_getmsgint64(StringInfo msg)
Definition: pqformat.c:456
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:349
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:145
static void pq_sendint64(StringInfo buf, uint64 i)
Definition: pqformat.h:153
bool TransactionIdIsInProgress(TransactionId xid)
Definition: procarray.c:1383
static size_t qunique(void *array, size_t elements, size_t width, int(*compare)(const void *, const void *))
Definition: qunique.h:21
Snapshot GetActiveSnapshot(void)
Definition: snapmgr.c:777
StringInfo makeStringInfo(void)
Definition: stringinfo.c:41
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:97
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
Definition: stringinfo.c:233
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:194
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
StringInfoData * StringInfo
Definition: stringinfo.h:54
void * user_fctx
Definition: funcapi.h:82
uint64 call_cntr
Definition: funcapi.h:65
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:101
Definition: nodes.h:129
TransactionId oldestClogXid
Definition: transam.h:253
FullTransactionId xip[FLEXIBLE_ARRAY_MEMBER]
Definition: xid8funcs.c:69
int32 __varsz
Definition: xid8funcs.c:63
FullTransactionId xmax
Definition: xid8funcs.c:67
uint32 nxip
Definition: xid8funcs.c:65
FullTransactionId xmin
Definition: xid8funcs.c:66
bool TransactionIdDidCommit(TransactionId transactionId)
Definition: transam.c:126
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:280
#define FullTransactionIdEquals(a, b)
Definition: transam.h:50
#define EpochFromFullTransactionId(x)
Definition: transam.h:47
#define U64FromFullTransactionId(x)
Definition: transam.h:49
static FullTransactionId FullTransactionIdFromU64(uint64 value)
Definition: transam.h:81
#define FullTransactionIdFollowsOrEquals(a, b)
Definition: transam.h:54
#define XidFromFullTransactionId(x)
Definition: transam.h:48
#define TransactionIdIsValid(xid)
Definition: transam.h:41
static FullTransactionId FullTransactionIdFromEpochAndXid(uint32 epoch, TransactionId xid)
Definition: transam.h:71
#define TransactionIdIsNormal(xid)
Definition: transam.h:42
#define InvalidFullTransactionId
Definition: transam.h:56
#define FullTransactionIdPrecedes(a, b)
Definition: transam.h:51
#define FullTransactionIdIsValid(x)
Definition: transam.h:55
void PreventCommandDuringRecovery(const char *cmdname)
Definition: utility.c:448
#define SET_VARSIZE(PTR, len)
Definition: varatt.h:305
#define VARSIZE(PTR)
Definition: varatt.h:279
text * cstring_to_text(const char *s)
Definition: varlena.c:184
FullTransactionId ReadNextFullTransactionId(void)
Definition: varsup.c:261
VariableCache ShmemVariableCache
Definition: varsup.c:34
static const unsigned __int64 epoch
FullTransactionId GetTopFullTransactionId(void)
Definition: xact.c:474
FullTransactionId GetTopFullTransactionIdIfAny(void)
Definition: xact.c:490
#define PG_GETARG_FULLTRANSACTIONID(X)
Definition: xid8.h:29
static Datum FullTransactionIdGetDatum(FullTransactionId X)
Definition: xid8.h:24
#define PG_RETURN_FULLTRANSACTIONID(X)
Definition: xid8.h:30
static bool TransactionIdInRecentPast(FullTransactionId fxid, TransactionId *extracted_xid)
Definition: xid8funcs.c:99
Datum pg_snapshot_send(PG_FUNCTION_ARGS)
Definition: xid8funcs.c:559
Datum pg_current_xact_id_if_assigned(PG_FUNCTION_ARGS)
Definition: xid8funcs.c:383
static StringInfo buf_init(FullTransactionId xmin, FullTransactionId xmax)
Definition: xid8funcs.c:253
static bool is_visible_fxid(FullTransactionId value, const pg_snapshot *snap)
Definition: xid8funcs.c:218
static int cmp_fxid(const void *aa, const void *bb)
Definition: xid8funcs.c:184
#define USE_BSEARCH_IF_NXIP_GREATER
Definition: xid8funcs.c:50
Datum pg_snapshot_out(PG_FUNCTION_ARGS)
Definition: xid8funcs.c:461
#define PG_SNAPSHOT_SIZE(nxip)
Definition: xid8funcs.c:72
#define PG_SNAPSHOT_MAX_NXIP
Definition: xid8funcs.c:74
Datum pg_current_xact_id(PG_FUNCTION_ARGS)
Definition: xid8funcs.c:365
Datum pg_snapshot_recv(PG_FUNCTION_ARGS)
Definition: xid8funcs.c:493
static pg_snapshot * parse_snapshot(const char *str, Node *escontext)
Definition: xid8funcs.c:296
Datum pg_snapshot_in(PG_FUNCTION_ARGS)
Definition: xid8funcs.c:445
static pg_snapshot * buf_finalize(StringInfo buf)
Definition: xid8funcs.c:279
Datum pg_xact_status(PG_FUNCTION_ARGS)
Definition: xid8funcs.c:665
Datum pg_current_snapshot(PG_FUNCTION_ARGS)
Definition: xid8funcs.c:401
static void buf_add_txid(StringInfo buf, FullTransactionId fxid)
Definition: xid8funcs.c:268
Datum pg_snapshot_xmin(PG_FUNCTION_ARGS)
Definition: xid8funcs.c:594
Datum pg_snapshot_xip(PG_FUNCTION_ARGS)
Definition: xid8funcs.c:620
static void sort_snapshot(pg_snapshot *snap)
Definition: xid8funcs.c:204
Datum pg_visible_in_snapshot(PG_FUNCTION_ARGS)
Definition: xid8funcs.c:580
StaticAssertDecl(MAX_BACKENDS *2<=PG_SNAPSHOT_MAX_NXIP, "possible overflow in pg_current_snapshot()")
static FullTransactionId widen_snapshot_xid(TransactionId xid, FullTransactionId next_fxid)
Definition: xid8funcs.c:158
Datum pg_snapshot_xmax(PG_FUNCTION_ARGS)
Definition: xid8funcs.c:607