PostgreSQL Source Code  git master
pg_logicalinspect.c File Reference
#include "postgres.h"
#include "funcapi.h"
#include "replication/snapbuild_internal.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/pg_lsn.h"
Include dependency graph for pg_logicalinspect.c:

Go to the source code of this file.

Macros

#define PG_GET_LOGICAL_SNAPSHOT_META_COLS   3
 
#define PG_GET_LOGICAL_SNAPSHOT_INFO_COLS   14
 

Functions

 PG_FUNCTION_INFO_V1 (pg_get_logical_snapshot_meta)
 
 PG_FUNCTION_INFO_V1 (pg_get_logical_snapshot_info)
 
static const char * get_snapbuild_state_desc (SnapBuildState state)
 
Datum pg_get_logical_snapshot_meta (PG_FUNCTION_ARGS)
 
Datum pg_get_logical_snapshot_info (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 

Macro Definition Documentation

◆ PG_GET_LOGICAL_SNAPSHOT_INFO_COLS

#define PG_GET_LOGICAL_SNAPSHOT_INFO_COLS   14

◆ PG_GET_LOGICAL_SNAPSHOT_META_COLS

#define PG_GET_LOGICAL_SNAPSHOT_META_COLS   3

Function Documentation

◆ get_snapbuild_state_desc()

static const char* get_snapbuild_state_desc ( SnapBuildState  state)
static

Definition at line 28 of file pg_logicalinspect.c.

29 {
30  const char *stateDesc = "unknown state";
31 
32  switch (state)
33  {
34  case SNAPBUILD_START:
35  stateDesc = "start";
36  break;
38  stateDesc = "building";
39  break;
41  stateDesc = "full";
42  break;
44  stateDesc = "consistent";
45  break;
46  }
47 
48  return stateDesc;
49 }
@ SNAPBUILD_START
Definition: snapbuild.h:27
@ SNAPBUILD_BUILDING_SNAPSHOT
Definition: snapbuild.h:33
@ SNAPBUILD_FULL_SNAPSHOT
Definition: snapbuild.h:43
@ SNAPBUILD_CONSISTENT
Definition: snapbuild.h:50
Definition: regguts.h:323

References SNAPBUILD_BUILDING_SNAPSHOT, SNAPBUILD_CONSISTENT, SNAPBUILD_FULL_SNAPSHOT, and SNAPBUILD_START.

Referenced by pg_get_logical_snapshot_info().

◆ PG_FUNCTION_INFO_V1() [1/2]

PG_FUNCTION_INFO_V1 ( pg_get_logical_snapshot_info  )

◆ PG_FUNCTION_INFO_V1() [2/2]

PG_FUNCTION_INFO_V1 ( pg_get_logical_snapshot_meta  )

◆ pg_get_logical_snapshot_info()

Datum pg_get_logical_snapshot_info ( PG_FUNCTION_ARGS  )

Definition at line 92 of file pg_logicalinspect.c.

93 {
94 #define PG_GET_LOGICAL_SNAPSHOT_INFO_COLS 14
95  SnapBuildOnDisk ondisk;
96  HeapTuple tuple;
98  bool nulls[PG_GET_LOGICAL_SNAPSHOT_INFO_COLS] = {0};
99  TupleDesc tupdesc;
100  char path[MAXPGPATH];
101  int i = 0;
102  text *filename_t = PG_GETARG_TEXT_PP(0);
103 
104  /* Build a tuple descriptor for our result type */
105  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
106  elog(ERROR, "return type must be a row type");
107 
108  sprintf(path, "%s/%s",
110  text_to_cstring(filename_t));
111 
112  /* Validate and restore the snapshot to 'ondisk' */
113  SnapBuildRestoreSnapshot(&ondisk, path, CurrentMemoryContext, false);
114 
119  values[i++] = LSNGetDatum(ondisk.builder.two_phase_at);
125 
127  if (ondisk.builder.committed.xcnt > 0)
128  {
129  Datum *arrayelems;
130 
131  arrayelems = (Datum *) palloc(ondisk.builder.committed.xcnt * sizeof(Datum));
132 
133  for (int j = 0; j < ondisk.builder.committed.xcnt; j++)
134  arrayelems[j] = TransactionIdGetDatum(ondisk.builder.committed.xip[j]);
135 
137  ondisk.builder.committed.xcnt,
138  XIDOID));
139  }
140  else
141  nulls[i++] = true;
142 
144  if (ondisk.builder.catchange.xcnt > 0)
145  {
146  Datum *arrayelems;
147 
148  arrayelems = (Datum *) palloc(ondisk.builder.catchange.xcnt * sizeof(Datum));
149 
150  for (int j = 0; j < ondisk.builder.catchange.xcnt; j++)
151  arrayelems[j] = TransactionIdGetDatum(ondisk.builder.catchange.xip[j]);
152 
154  ondisk.builder.catchange.xcnt,
155  XIDOID));
156  }
157  else
158  nulls[i++] = true;
159 
161 
162  tuple = heap_form_tuple(tupdesc, values, nulls);
163 
165 
166 #undef PG_GET_LOGICAL_SNAPSHOT_INFO_COLS
167 }
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
Definition: arrayfuncs.c:3381
static Datum values[MAXATTR]
Definition: bootstrap.c:151
#define CStringGetTextDatum(s)
Definition: builtins.h:97
#define Assert(condition)
Definition: c.h:812
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:276
@ TYPEFUNC_COMPOSITE
Definition: funcapi.h:149
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition: funcapi.h:230
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1116
int j
Definition: isn.c:73
int i
Definition: isn.c:72
MemoryContext CurrentMemoryContext
Definition: mcxt.c:143
void * palloc(Size size)
Definition: mcxt.c:1317
#define MAXPGPATH
#define PG_GET_LOGICAL_SNAPSHOT_INFO_COLS
static const char * get_snapbuild_state_desc(SnapBuildState state)
static Datum LSNGetDatum(XLogRecPtr X)
Definition: pg_lsn.h:28
#define sprintf
Definition: port.h:240
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
static Datum TransactionIdGetDatum(TransactionId X)
Definition: postgres.h:272
uintptr_t Datum
Definition: postgres.h:64
static Datum BoolGetDatum(bool X)
Definition: postgres.h:102
static Datum UInt32GetDatum(uint32 X)
Definition: postgres.h:232
#define PG_LOGICAL_SNAPSHOTS_DIR
Definition: reorderbuffer.h:24
bool SnapBuildRestoreSnapshot(SnapBuildOnDisk *ondisk, const char *path, MemoryContext context, bool missing_ok)
Definition: snapbuild.c:1694
XLogRecPtr start_decoding_at
SnapBuildState state
TransactionId xmin
TransactionId initial_xmin_horizon
struct SnapBuild::@116 catchange
TransactionId xmax
TransactionId * xip
XLogRecPtr two_phase_at
bool building_full_snapshot
TransactionId next_phase_at
struct SnapBuild::@115 committed
XLogRecPtr last_serialized_snapshot
Definition: c.h:641
char * text_to_cstring(const text *t)
Definition: varlena.c:217

References Assert, BoolGetDatum(), SnapBuildOnDisk::builder, SnapBuild::building_full_snapshot, SnapBuild::catchange, SnapBuild::committed, construct_array_builtin(), CStringGetTextDatum, CurrentMemoryContext, elog, ERROR, get_call_result_type(), get_snapbuild_state_desc(), heap_form_tuple(), HeapTupleGetDatum(), i, SnapBuild::in_slot_creation, SnapBuild::initial_xmin_horizon, j, SnapBuild::last_serialized_snapshot, LSNGetDatum(), MAXPGPATH, SnapBuild::next_phase_at, palloc(), PG_GET_LOGICAL_SNAPSHOT_INFO_COLS, PG_GETARG_TEXT_PP, PG_LOGICAL_SNAPSHOTS_DIR, PG_RETURN_DATUM, PointerGetDatum(), SnapBuildRestoreSnapshot(), sprintf, SnapBuild::start_decoding_at, SnapBuild::state, text_to_cstring(), TransactionIdGetDatum(), SnapBuild::two_phase_at, TYPEFUNC_COMPOSITE, UInt32GetDatum(), values, SnapBuild::xcnt, SnapBuild::xip, SnapBuild::xmax, and SnapBuild::xmin.

◆ pg_get_logical_snapshot_meta()

Datum pg_get_logical_snapshot_meta ( PG_FUNCTION_ARGS  )

Definition at line 55 of file pg_logicalinspect.c.

56 {
57 #define PG_GET_LOGICAL_SNAPSHOT_META_COLS 3
58  SnapBuildOnDisk ondisk;
59  HeapTuple tuple;
61  bool nulls[PG_GET_LOGICAL_SNAPSHOT_META_COLS] = {0};
62  TupleDesc tupdesc;
63  char path[MAXPGPATH];
64  int i = 0;
65  text *filename_t = PG_GETARG_TEXT_PP(0);
66 
67  /* Build a tuple descriptor for our result type */
68  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
69  elog(ERROR, "return type must be a row type");
70 
71  sprintf(path, "%s/%s",
73  text_to_cstring(filename_t));
74 
75  /* Validate and restore the snapshot to 'ondisk' */
76  SnapBuildRestoreSnapshot(&ondisk, path, CurrentMemoryContext, false);
77 
78  values[i++] = UInt32GetDatum(ondisk.magic);
79  values[i++] = Int64GetDatum((int64) ondisk.checksum);
80  values[i++] = UInt32GetDatum(ondisk.version);
81 
83 
84  tuple = heap_form_tuple(tupdesc, values, nulls);
85 
87 
88 #undef PG_GET_LOGICAL_SNAPSHOT_META_COLS
89 }
int64_t int64
Definition: c.h:482
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1807
#define PG_GET_LOGICAL_SNAPSHOT_META_COLS

References Assert, SnapBuildOnDisk::checksum, CurrentMemoryContext, elog, ERROR, get_call_result_type(), heap_form_tuple(), HeapTupleGetDatum(), i, Int64GetDatum(), SnapBuildOnDisk::magic, MAXPGPATH, PG_GET_LOGICAL_SNAPSHOT_META_COLS, PG_GETARG_TEXT_PP, PG_LOGICAL_SNAPSHOTS_DIR, PG_RETURN_DATUM, SnapBuildRestoreSnapshot(), sprintf, text_to_cstring(), TYPEFUNC_COMPOSITE, UInt32GetDatum(), values, and SnapBuildOnDisk::version.

Variable Documentation

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 21 of file pg_logicalinspect.c.