PostgreSQL Source Code  git master
pg_subscription_rel.h File Reference
#include "access/xlogdefs.h"
#include "catalog/genbki.h"
#include "catalog/pg_subscription_rel_d.h"
#include "nodes/pg_list.h"
Include dependency graph for pg_subscription_rel.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SubscriptionRelState
 

Typedefs

typedef FormData_pg_subscription_relForm_pg_subscription_rel
 
typedef struct SubscriptionRelState SubscriptionRelState
 

Functions

 CATALOG (pg_subscription_rel, 6102, SubscriptionRelRelationId)
 
 DECLARE_UNIQUE_INDEX_PKEY (pg_subscription_rel_srrelid_srsubid_index, 6117, SubscriptionRelSrrelidSrsubidIndexId, on pg_subscription_rel using btree(srrelid oid_ops, srsubid oid_ops))
 
void AddSubscriptionRelState (Oid subid, Oid relid, char state, XLogRecPtr sublsn)
 
void UpdateSubscriptionRelState (Oid subid, Oid relid, char state, XLogRecPtr sublsn)
 
char GetSubscriptionRelState (Oid subid, Oid relid, XLogRecPtr *sublsn)
 
void RemoveSubscriptionRel (Oid subid, Oid relid)
 
bool HasSubscriptionRelations (Oid subid)
 
ListGetSubscriptionRelations (Oid subid)
 
ListGetSubscriptionNotReadyRelations (Oid subid)
 

Variables

 FormData_pg_subscription_rel
 

Typedef Documentation

◆ Form_pg_subscription_rel

◆ SubscriptionRelState

Function Documentation

◆ AddSubscriptionRelState()

void AddSubscriptionRelState ( Oid  subid,
Oid  relid,
char  state,
XLogRecPtr  sublsn 
)

Definition at line 239 of file pg_subscription.c.

References AccessShareLock, CatalogTupleInsert(), CharGetDatum, elog, ERROR, heap_form_tuple(), heap_freetuple(), HeapTupleIsValid, InvalidXLogRecPtr, LockSharedObject(), LSNGetDatum, NoLock, ObjectIdGetDatum, RelationGetDescr, RowExclusiveLock, SearchSysCacheCopy2, SUBSCRIPTIONRELMAP, table_close(), table_open(), and values.

Referenced by AlterSubscription_refresh(), and CreateSubscription().

241 {
242  Relation rel;
243  HeapTuple tup;
244  bool nulls[Natts_pg_subscription_rel];
245  Datum values[Natts_pg_subscription_rel];
246 
247  LockSharedObject(SubscriptionRelationId, subid, 0, AccessShareLock);
248 
249  rel = table_open(SubscriptionRelRelationId, RowExclusiveLock);
250 
251  /* Try finding existing mapping. */
253  ObjectIdGetDatum(relid),
254  ObjectIdGetDatum(subid));
255  if (HeapTupleIsValid(tup))
256  elog(ERROR, "subscription table %u in subscription %u already exists",
257  relid, subid);
258 
259  /* Form the tuple. */
260  memset(values, 0, sizeof(values));
261  memset(nulls, false, sizeof(nulls));
262  values[Anum_pg_subscription_rel_srsubid - 1] = ObjectIdGetDatum(subid);
263  values[Anum_pg_subscription_rel_srrelid - 1] = ObjectIdGetDatum(relid);
264  values[Anum_pg_subscription_rel_srsubstate - 1] = CharGetDatum(state);
265  if (sublsn != InvalidXLogRecPtr)
266  values[Anum_pg_subscription_rel_srsublsn - 1] = LSNGetDatum(sublsn);
267  else
268  nulls[Anum_pg_subscription_rel_srsublsn - 1] = true;
269 
270  tup = heap_form_tuple(RelationGetDescr(rel), values, nulls);
271 
272  /* Insert tuple into catalog. */
273  CatalogTupleInsert(rel, tup);
274 
275  heap_freetuple(tup);
276 
277  /* Cleanup. */
278  table_close(rel, NoLock);
279 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
#define RelationGetDescr(relation)
Definition: rel.h:503
#define AccessShareLock
Definition: lockdefs.h:36
#define LSNGetDatum(X)
Definition: pg_lsn.h:22
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
#define NoLock
Definition: lockdefs.h:34
#define RowExclusiveLock
Definition: lockdefs.h:38
uintptr_t Datum
Definition: postgres.h:411
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1017
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
Definition: regguts.h:317
#define CharGetDatum(X)
Definition: postgres.h:460
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define elog(elevel,...)
Definition: elog.h:232
#define SearchSysCacheCopy2(cacheId, key1, key2)
Definition: syscache.h:177
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition: indexing.c:221

◆ CATALOG()

CATALOG ( pg_subscription_rel  ,
6102  ,
SubscriptionRelRelationId   
)

Definition at line 31 of file pg_subscription_rel.h.

References BKI_FORCE_NULL, and BKI_LOOKUP.

32 {
33  Oid srsubid BKI_LOOKUP(pg_subscription); /* Oid of subscription */
34  Oid srrelid BKI_LOOKUP(pg_class); /* Oid of relation */
35  char srsubstate; /* state of the relation in subscription */
36 
37  /*
38  * Although srsublsn is a fixed-width type, it is allowed to be NULL, so
39  * we prevent direct C code access to it just as for a varlena field.
40  */
41 #ifdef CATALOG_VARLEN /* variable-length fields start here */
42 
43  XLogRecPtr srsublsn BKI_FORCE_NULL; /* remote LSN of the state change
44  * used for synchronization
45  * coordination, or NULL if not
46  * valid */
47 #endif
unsigned int Oid
Definition: postgres_ext.h:31
FormData_pg_subscription_rel
#define BKI_FORCE_NULL
Definition: genbki.h:32
#define BKI_LOOKUP(catalog)
Definition: genbki.h:46
uint64 XLogRecPtr
Definition: xlogdefs.h:21

◆ DECLARE_UNIQUE_INDEX_PKEY()

DECLARE_UNIQUE_INDEX_PKEY ( pg_subscription_rel_srrelid_srsubid_index  ,
6117  ,
SubscriptionRelSrrelidSrsubidIndexId  ,
on pg_subscription_rel using   btreesrrelid oid_ops, srsubid oid_ops 
)

◆ GetSubscriptionNotReadyRelations()

List* GetSubscriptionNotReadyRelations ( Oid  subid)

Definition at line 547 of file pg_subscription.c.

References AccessShareLock, BTEqualStrategyNumber, CharGetDatum, DatumGetLSN, GETSTRUCT, HeapTupleIsValid, InvalidOid, InvalidXLogRecPtr, lappend(), SubscriptionRelState::lsn, NIL, ObjectIdGetDatum, palloc(), SubscriptionRelState::relid, ScanKeyInit(), SubscriptionRelState::state, SUBSCRIPTIONRELMAP, SysCacheGetAttr(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().

Referenced by DropSubscription(), and FetchTableStates().

548 {
549  List *res = NIL;
550  Relation rel;
551  HeapTuple tup;
552  int nkeys = 0;
553  ScanKeyData skey[2];
554  SysScanDesc scan;
555 
556  rel = table_open(SubscriptionRelRelationId, AccessShareLock);
557 
558  ScanKeyInit(&skey[nkeys++],
559  Anum_pg_subscription_rel_srsubid,
560  BTEqualStrategyNumber, F_OIDEQ,
561  ObjectIdGetDatum(subid));
562 
563  ScanKeyInit(&skey[nkeys++],
564  Anum_pg_subscription_rel_srsubstate,
565  BTEqualStrategyNumber, F_CHARNE,
566  CharGetDatum(SUBREL_STATE_READY));
567 
568  scan = systable_beginscan(rel, InvalidOid, false,
569  NULL, nkeys, skey);
570 
571  while (HeapTupleIsValid(tup = systable_getnext(scan)))
572  {
574  SubscriptionRelState *relstate;
575  Datum d;
576  bool isnull;
577 
578  subrel = (Form_pg_subscription_rel) GETSTRUCT(tup);
579 
580  relstate = (SubscriptionRelState *) palloc(sizeof(SubscriptionRelState));
581  relstate->relid = subrel->srrelid;
582  relstate->state = subrel->srsubstate;
584  Anum_pg_subscription_rel_srsublsn, &isnull);
585  if (isnull)
586  relstate->lsn = InvalidXLogRecPtr;
587  else
588  relstate->lsn = DatumGetLSN(d);
589 
590  res = lappend(res, relstate);
591  }
592 
593  /* Cleanup */
594  systable_endscan(scan);
596 
597  return res;
598 }
#define NIL
Definition: pg_list.h:65
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:595
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
#define AccessShareLock
Definition: lockdefs.h:36
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:383
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:502
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
List * lappend(List *list, void *datum)
Definition: list.c:336
uintptr_t Datum
Definition: postgres.h:411
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1388
#define InvalidOid
Definition: postgres_ext.h:36
#define DatumGetLSN(X)
Definition: pg_lsn.h:21
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_subscription_rel * Form_pg_subscription_rel
#define CharGetDatum(X)
Definition: postgres.h:460
void * palloc(Size size)
Definition: mcxt.c:1062
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
Definition: pg_list.h:50
#define BTEqualStrategyNumber
Definition: stratnum.h:31

◆ GetSubscriptionRelations()

List* GetSubscriptionRelations ( Oid  subid)

Definition at line 494 of file pg_subscription.c.

References AccessShareLock, BTEqualStrategyNumber, DatumGetLSN, GETSTRUCT, HeapTupleIsValid, InvalidOid, InvalidXLogRecPtr, lappend(), SubscriptionRelState::lsn, NIL, ObjectIdGetDatum, palloc(), SubscriptionRelState::relid, ScanKeyInit(), SubscriptionRelState::state, SUBSCRIPTIONRELMAP, SysCacheGetAttr(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().

Referenced by AlterSubscription_refresh().

495 {
496  List *res = NIL;
497  Relation rel;
498  HeapTuple tup;
499  ScanKeyData skey[1];
500  SysScanDesc scan;
501 
502  rel = table_open(SubscriptionRelRelationId, AccessShareLock);
503 
504  ScanKeyInit(&skey[0],
505  Anum_pg_subscription_rel_srsubid,
506  BTEqualStrategyNumber, F_OIDEQ,
507  ObjectIdGetDatum(subid));
508 
509  scan = systable_beginscan(rel, InvalidOid, false,
510  NULL, 1, skey);
511 
512  while (HeapTupleIsValid(tup = systable_getnext(scan)))
513  {
515  SubscriptionRelState *relstate;
516  Datum d;
517  bool isnull;
518 
519  subrel = (Form_pg_subscription_rel) GETSTRUCT(tup);
520 
521  relstate = (SubscriptionRelState *) palloc(sizeof(SubscriptionRelState));
522  relstate->relid = subrel->srrelid;
523  relstate->state = subrel->srsubstate;
525  Anum_pg_subscription_rel_srsublsn, &isnull);
526  if (isnull)
527  relstate->lsn = InvalidXLogRecPtr;
528  else
529  relstate->lsn = DatumGetLSN(d);
530 
531  res = lappend(res, relstate);
532  }
533 
534  /* Cleanup */
535  systable_endscan(scan);
537 
538  return res;
539 }
#define NIL
Definition: pg_list.h:65
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:595
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
#define AccessShareLock
Definition: lockdefs.h:36
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:383
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:502
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
List * lappend(List *list, void *datum)
Definition: list.c:336
uintptr_t Datum
Definition: postgres.h:411
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1388
#define InvalidOid
Definition: postgres_ext.h:36
#define DatumGetLSN(X)
Definition: pg_lsn.h:21
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_subscription_rel * Form_pg_subscription_rel
void * palloc(Size size)
Definition: mcxt.c:1062
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
Definition: pg_list.h:50
#define BTEqualStrategyNumber
Definition: stratnum.h:31

◆ GetSubscriptionRelState()

char GetSubscriptionRelState ( Oid  subid,
Oid  relid,
XLogRecPtr sublsn 
)

Definition at line 336 of file pg_subscription.c.

References AccessShareLock, DatumGetLSN, GETSTRUCT, HeapTupleIsValid, InvalidXLogRecPtr, ObjectIdGetDatum, ReleaseSysCache(), SearchSysCache2(), SUBSCRIPTIONRELMAP, SysCacheGetAttr(), table_close(), and table_open().

Referenced by AlterSubscription_refresh(), logicalrep_rel_open(), LogicalRepSyncTableStart(), and wait_for_relation_state_change().

337 {
338  HeapTuple tup;
339  char substate;
340  bool isnull;
341  Datum d;
342  Relation rel;
343 
344  /*
345  * This is to avoid the race condition with AlterSubscription which tries
346  * to remove this relstate.
347  */
348  rel = table_open(SubscriptionRelRelationId, AccessShareLock);
349 
350  /* Try finding the mapping. */
352  ObjectIdGetDatum(relid),
353  ObjectIdGetDatum(subid));
354 
355  if (!HeapTupleIsValid(tup))
356  {
358  *sublsn = InvalidXLogRecPtr;
359  return SUBREL_STATE_UNKNOWN;
360  }
361 
362  /* Get the state. */
363  substate = ((Form_pg_subscription_rel) GETSTRUCT(tup))->srsubstate;
364 
365  /* Get the LSN */
367  Anum_pg_subscription_rel_srsublsn, &isnull);
368  if (isnull)
369  *sublsn = InvalidXLogRecPtr;
370  else
371  *sublsn = DatumGetLSN(d);
372 
373  /* Cleanup */
374  ReleaseSysCache(tup);
375 
377 
378  return substate;
379 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
#define AccessShareLock
Definition: lockdefs.h:36
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
uintptr_t Datum
Definition: postgres.h:411
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1388
#define DatumGetLSN(X)
Definition: pg_lsn.h:21
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_subscription_rel * Form_pg_subscription_rel
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition: syscache.c:1138
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ HasSubscriptionRelations()

bool HasSubscriptionRelations ( Oid  subid)

Definition at line 461 of file pg_subscription.c.

References AccessShareLock, BTEqualStrategyNumber, HeapTupleIsValid, InvalidOid, ObjectIdGetDatum, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().

Referenced by FetchTableStates().

462 {
463  Relation rel;
464  ScanKeyData skey[1];
465  SysScanDesc scan;
466  bool has_subrels;
467 
468  rel = table_open(SubscriptionRelRelationId, AccessShareLock);
469 
470  ScanKeyInit(&skey[0],
471  Anum_pg_subscription_rel_srsubid,
472  BTEqualStrategyNumber, F_OIDEQ,
473  ObjectIdGetDatum(subid));
474 
475  scan = systable_beginscan(rel, InvalidOid, false,
476  NULL, 1, skey);
477 
478  /* If even a single tuple exists then the subscription has tables. */
479  has_subrels = HeapTupleIsValid(systable_getnext(scan));
480 
481  /* Cleanup */
482  systable_endscan(scan);
484 
485  return has_subrels;
486 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:595
#define AccessShareLock
Definition: lockdefs.h:36
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:383
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:502
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
#define BTEqualStrategyNumber
Definition: stratnum.h:31

◆ RemoveSubscriptionRel()

void RemoveSubscriptionRel ( Oid  subid,
Oid  relid 
)

Definition at line 386 of file pg_subscription.c.

References BTEqualStrategyNumber, CatalogTupleDelete(), ereport, errcode(), errdetail(), errhint(), errmsg(), ERROR, ForwardScanDirection, get_rel_name(), get_subscription_name(), GETSTRUCT, heap_getnext(), HeapTupleIsValid, ObjectIdGetDatum, OidIsValid, RowExclusiveLock, ScanKeyInit(), HeapTupleData::t_self, table_beginscan_catalog(), table_close(), table_endscan(), and table_open().

Referenced by AlterSubscription_refresh(), DropSubscription(), and heap_drop_with_catalog().

387 {
388  Relation rel;
389  TableScanDesc scan;
390  ScanKeyData skey[2];
391  HeapTuple tup;
392  int nkeys = 0;
393 
394  rel = table_open(SubscriptionRelRelationId, RowExclusiveLock);
395 
396  if (OidIsValid(subid))
397  {
398  ScanKeyInit(&skey[nkeys++],
399  Anum_pg_subscription_rel_srsubid,
401  F_OIDEQ,
402  ObjectIdGetDatum(subid));
403  }
404 
405  if (OidIsValid(relid))
406  {
407  ScanKeyInit(&skey[nkeys++],
408  Anum_pg_subscription_rel_srrelid,
410  F_OIDEQ,
411  ObjectIdGetDatum(relid));
412  }
413 
414  /* Do the search and delete what we found. */
415  scan = table_beginscan_catalog(rel, nkeys, skey);
417  {
419 
420  subrel = (Form_pg_subscription_rel) GETSTRUCT(tup);
421 
422  /*
423  * We don't allow to drop the relation mapping when the table
424  * synchronization is in progress unless the caller updates the
425  * corresponding subscription as well. This is to ensure that we don't
426  * leave tablesync slots or origins in the system when the
427  * corresponding table is dropped.
428  */
429  if (!OidIsValid(subid) && subrel->srsubstate != SUBREL_STATE_READY)
430  {
431  ereport(ERROR,
432  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
433  errmsg("could not drop relation mapping for subscription \"%s\"",
434  get_subscription_name(subrel->srsubid, false)),
435  errdetail("Table synchronization for relation \"%s\" is in progress and is in state \"%c\".",
436  get_rel_name(relid), subrel->srsubstate),
437 
438  /*
439  * translator: first %s is a SQL ALTER command and second %s is a
440  * SQL DROP command
441  */
442  errhint("Use %s to enable subscription if not already enabled or use %s to drop the subscription.",
443  "ALTER SUBSCRIPTION ... ENABLE",
444  "DROP SUBSCRIPTION ...")));
445  }
446 
447  CatalogTupleDelete(rel, &tup->t_self);
448  }
449  table_endscan(scan);
450 
452 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
int errhint(const char *fmt,...)
Definition: elog.c:1156
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
TableScanDesc table_beginscan_catalog(Relation relation, int nkeys, struct ScanKeyData *key)
Definition: tableam.c:112
int errcode(int sqlerrcode)
Definition: elog.c:698
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:350
#define OidIsValid(objectId)
Definition: c.h:710
char * get_subscription_name(Oid subid, bool missing_ok)
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
ItemPointerData t_self
Definition: htup.h:65
HeapTuple heap_getnext(TableScanDesc sscan, ScanDirection direction)
Definition: heapam.c:1340
#define RowExclusiveLock
Definition: lockdefs.h:38
int errdetail(const char *fmt,...)
Definition: elog.c:1042
#define ereport(elevel,...)
Definition: elog.h:157
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_subscription_rel * Form_pg_subscription_rel
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:991
int errmsg(const char *fmt,...)
Definition: elog.c:909
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
char * get_rel_name(Oid relid)
Definition: lsyscache.c:1899
#define BTEqualStrategyNumber
Definition: stratnum.h:31

◆ UpdateSubscriptionRelState()

void UpdateSubscriptionRelState ( Oid  subid,
Oid  relid,
char  state,
XLogRecPtr  sublsn 
)

Definition at line 285 of file pg_subscription.c.

References AccessShareLock, CatalogTupleUpdate(), CharGetDatum, elog, ERROR, heap_modify_tuple(), HeapTupleIsValid, InvalidXLogRecPtr, LockSharedObject(), LSNGetDatum, NoLock, ObjectIdGetDatum, RelationGetDescr, RowExclusiveLock, SearchSysCacheCopy2, SUBSCRIPTIONRELMAP, HeapTupleData::t_self, table_close(), table_open(), and values.

Referenced by LogicalRepSyncTableStart(), process_syncing_tables_for_apply(), and process_syncing_tables_for_sync().

287 {
288  Relation rel;
289  HeapTuple tup;
290  bool nulls[Natts_pg_subscription_rel];
291  Datum values[Natts_pg_subscription_rel];
292  bool replaces[Natts_pg_subscription_rel];
293 
294  LockSharedObject(SubscriptionRelationId, subid, 0, AccessShareLock);
295 
296  rel = table_open(SubscriptionRelRelationId, RowExclusiveLock);
297 
298  /* Try finding existing mapping. */
300  ObjectIdGetDatum(relid),
301  ObjectIdGetDatum(subid));
302  if (!HeapTupleIsValid(tup))
303  elog(ERROR, "subscription table %u in subscription %u does not exist",
304  relid, subid);
305 
306  /* Update the tuple. */
307  memset(values, 0, sizeof(values));
308  memset(nulls, false, sizeof(nulls));
309  memset(replaces, false, sizeof(replaces));
310 
311  replaces[Anum_pg_subscription_rel_srsubstate - 1] = true;
312  values[Anum_pg_subscription_rel_srsubstate - 1] = CharGetDatum(state);
313 
314  replaces[Anum_pg_subscription_rel_srsublsn - 1] = true;
315  if (sublsn != InvalidXLogRecPtr)
316  values[Anum_pg_subscription_rel_srsublsn - 1] = LSNGetDatum(sublsn);
317  else
318  nulls[Anum_pg_subscription_rel_srsublsn - 1] = true;
319 
320  tup = heap_modify_tuple(tup, RelationGetDescr(rel), values, nulls,
321  replaces);
322 
323  /* Update the catalog. */
324  CatalogTupleUpdate(rel, &tup->t_self, tup);
325 
326  /* Cleanup. */
327  table_close(rel, NoLock);
328 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
#define RelationGetDescr(relation)
Definition: rel.h:503
#define AccessShareLock
Definition: lockdefs.h:36
#define LSNGetDatum(X)
Definition: pg_lsn.h:22
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
ItemPointerData t_self
Definition: htup.h:65
#define NoLock
Definition: lockdefs.h:34
#define RowExclusiveLock
Definition: lockdefs.h:38
uintptr_t Datum
Definition: postgres.h:411
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1017
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
Definition: regguts.h:317
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:301
#define CharGetDatum(X)
Definition: postgres.h:460
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define elog(elevel,...)
Definition: elog.h:232
#define SearchSysCacheCopy2(cacheId, key1, key2)
Definition: syscache.h:177
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, bool *replIsnull, bool *doReplace)
Definition: heaptuple.c:1113

Variable Documentation

◆ FormData_pg_subscription_rel

FormData_pg_subscription_rel

Definition at line 48 of file pg_subscription_rel.h.