PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
relation.c File Reference
Include dependency graph for relation.c:

Go to the source code of this file.

Functions

static void logicalrep_typmap_invalidate_cb (Datum arg, int cacheid, uint32 hashvalue)
 
static void logicalrep_relmap_invalidate_cb (Datum arg, Oid reloid)
 
static void logicalrep_relmap_init (void)
 
static void logicalrep_relmap_free_entry (LogicalRepRelMapEntry *entry)
 
void logicalrep_relmap_update (LogicalRepRelation *remoterel)
 
static int logicalrep_rel_att_by_name (LogicalRepRelation *remoterel, const char *attname)
 
LogicalRepRelMapEntrylogicalrep_rel_open (LogicalRepRelId remoteid, LOCKMODE lockmode)
 
void logicalrep_rel_close (LogicalRepRelMapEntry *rel, LOCKMODE lockmode)
 
static void logicalrep_typmap_free_entry (LogicalRepTyp *entry)
 
void logicalrep_typmap_update (LogicalRepTyp *remotetyp)
 
Oid logicalrep_typmap_getid (Oid remoteid)
 

Variables

static MemoryContext LogicalRepRelMapContext = NULL
 
static HTABLogicalRepRelMap = NULL
 
static HTABLogicalRepTypMap = NULL
 

Function Documentation

static int logicalrep_rel_att_by_name ( LogicalRepRelation remoterel,
const char *  attname 
)
static

Definition at line 203 of file relation.c.

References LogicalRepRelation::attnames, i, and LogicalRepRelation::natts.

Referenced by logicalrep_rel_open().

204 {
205  int i;
206 
207  for (i = 0; i < remoterel->natts; i++)
208  {
209  if (strcmp(remoterel->attnames[i], attname) == 0)
210  return i;
211  }
212 
213  return -1;
214 }
int i
void logicalrep_rel_close ( LogicalRepRelMapEntry rel,
LOCKMODE  lockmode 
)

Definition at line 368 of file relation.c.

References heap_close, LogicalRepRelMapEntry::localrel, and NULL.

Referenced by apply_handle_delete(), apply_handle_insert(), apply_handle_update(), and copy_table().

369 {
370  heap_close(rel->localrel, lockmode);
371  rel->localrel = NULL;
372 }
#define heap_close(r, l)
Definition: heapam.h:97
#define NULL
Definition: c.h:229
LogicalRepRelMapEntry* logicalrep_rel_open ( LogicalRepRelId  remoteid,
LOCKMODE  lockmode 
)

Definition at line 223 of file relation.c.

References LogicalRepRelation::attkeys, LogicalRepRelMapEntry::attrmap, AttrNumberGetAttrOffset, AttrNumberIsForUserDefinedAttr, tupleDesc::attrs, bms_is_member(), bms_next_member(), CheckSubscriptionRelkind(), elog, ereport, errcode(), errmsg(), ERROR, FirstLowInvalidHeapAttributeNumber, GetSubscriptionRelState(), HASH_FIND, hash_search(), heap_open(), i, INDEX_ATTR_BITMAP_IDENTITY_KEY, INDEX_ATTR_BITMAP_PRIMARY_KEY, LogicalRepRelMapEntry::localrel, LogicalRepRelMapEntry::localreloid, logicalrep_rel_att_by_name(), logicalrep_relmap_init(), makeRangeVar(), MemoryContextSwitchTo(), MySubscription, NameStr, tupleDesc::natts, NoLock, LogicalRepRelation::nspname, NULL, Subscription::oid, OidIsValid, palloc(), RangeVarGetRelid, RelationData::rd_rel, RelationGetDescr, RelationGetIndexAttrBitmap(), LogicalRepRelation::relname, LogicalRepRelMapEntry::remoterel, REPLICA_IDENTITY_FULL, LogicalRepRelation::replident, LogicalRepRelMapEntry::state, LogicalRepRelMapEntry::statelsn, SUBREL_STATE_READY, and LogicalRepRelMapEntry::updatable.

Referenced by apply_handle_delete(), apply_handle_insert(), apply_handle_update(), and copy_table().

224 {
225  LogicalRepRelMapEntry *entry;
226  bool found;
227 
228  if (LogicalRepRelMap == NULL)
230 
231  /* Search for existing entry. */
232  entry = hash_search(LogicalRepRelMap, (void *) &remoteid,
233  HASH_FIND, &found);
234 
235  if (!found)
236  elog(ERROR, "no relation map entry for remote relation ID %u",
237  remoteid);
238 
239  /* Need to update the local cache? */
240  if (!OidIsValid(entry->localreloid))
241  {
242  Oid relid;
243  int i;
244  int found;
245  Bitmapset *idkey;
246  TupleDesc desc;
247  LogicalRepRelation *remoterel;
248  MemoryContext oldctx;
249 
250  remoterel = &entry->remoterel;
251 
252  /* Try to find and lock the relation by name. */
253  relid = RangeVarGetRelid(makeRangeVar(remoterel->nspname,
254  remoterel->relname, -1),
255  lockmode, true);
256  if (!OidIsValid(relid))
257  ereport(ERROR,
258  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
259  errmsg("logical replication target relation \"%s.%s\" does not exist",
260  remoterel->nspname, remoterel->relname)));
261  entry->localrel = heap_open(relid, NoLock);
262 
263  /* Check for supported relkind. */
264  CheckSubscriptionRelkind(entry->localrel->rd_rel->relkind,
265  remoterel->nspname, remoterel->relname);
266 
267  /*
268  * Build the mapping of local attribute numbers to remote attribute
269  * numbers and validate that we don't miss any replicated columns as
270  * that would result in potentially unwanted data loss.
271  */
272  desc = RelationGetDescr(entry->localrel);
274  entry->attrmap = palloc(desc->natts * sizeof(int));
275  MemoryContextSwitchTo(oldctx);
276 
277  found = 0;
278  for (i = 0; i < desc->natts; i++)
279  {
280  int attnum;
281 
282  if (desc->attrs[i]->attisdropped)
283  continue;
284 
285  attnum = logicalrep_rel_att_by_name(remoterel,
286  NameStr(desc->attrs[i]->attname));
287 
288  entry->attrmap[i] = attnum;
289  if (attnum >= 0)
290  found++;
291  }
292 
293  /* TODO, detail message with names of missing columns */
294  if (found < remoterel->natts)
295  ereport(ERROR,
296  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
297  errmsg("logical replication target relation \"%s.%s\" is missing "
298  "some replicated columns",
299  remoterel->nspname, remoterel->relname)));
300 
301  /*
302  * Check that replica identity matches. We allow for stricter replica
303  * identity (fewer columns) on subscriber as that will not stop us
304  * from finding unique tuple. IE, if publisher has identity
305  * (id,timestamp) and subscriber just (id) this will not be a problem,
306  * but in the opposite scenario it will.
307  *
308  * Don't throw any error here just mark the relation entry as not
309  * updatable, as replica identity is only for updates and deletes but
310  * inserts can be replicated even without it.
311  */
312  entry->updatable = true;
313  idkey = RelationGetIndexAttrBitmap(entry->localrel,
315  /* fallback to PK if no replica identity */
316  if (idkey == NULL)
317  {
318  idkey = RelationGetIndexAttrBitmap(entry->localrel,
320 
321  /*
322  * If no replica identity index and no PK, the published table
323  * must have replica identity FULL.
324  */
325  if (idkey == NULL && remoterel->replident != REPLICA_IDENTITY_FULL)
326  entry->updatable = false;
327  }
328 
329  i = -1;
330  while ((i = bms_next_member(idkey, i)) >= 0)
331  {
332  int attnum = i + FirstLowInvalidHeapAttributeNumber;
333 
334  if (!AttrNumberIsForUserDefinedAttr(attnum))
335  ereport(ERROR,
336  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
337  errmsg("logical replication target relation \"%s.%s\" uses "
338  "system columns in REPLICA IDENTITY index",
339  remoterel->nspname, remoterel->relname)));
340 
341  attnum = AttrNumberGetAttrOffset(attnum);
342 
343  if (!bms_is_member(entry->attrmap[attnum], remoterel->attkeys))
344  {
345  entry->updatable = false;
346  break;
347  }
348  }
349 
350  entry->localreloid = relid;
351  }
352  else
353  entry->localrel = heap_open(entry->localreloid, lockmode);
354 
355  if (entry->state != SUBREL_STATE_READY)
357  entry->localreloid,
358  &entry->statelsn,
359  true);
360 
361  return entry;
362 }
Subscription * MySubscription
Definition: worker.c:109
#define RelationGetDescr(relation)
Definition: rel.h:429
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Definition: namespace.h:53
int bms_next_member(const Bitmapset *a, int prevbit)
Definition: bitmapset.c:937
Form_pg_attribute * attrs
Definition: tupdesc.h:74
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define AttrNumberIsForUserDefinedAttr(attributeNumber)
Definition: attnum.h:41
int errcode(int sqlerrcode)
Definition: elog.c:575
#define FirstLowInvalidHeapAttributeNumber
Definition: sysattr.h:28
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:885
Form_pg_class rd_rel
Definition: rel.h:114
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
Bitmapset * attkeys
Definition: logicalproto.h:52
int natts
Definition: tupdesc.h:73
#define REPLICA_IDENTITY_FULL
Definition: pg_class.h:179
#define ERROR
Definition: elog.h:43
static int logicalrep_rel_att_by_name(LogicalRepRelation *remoterel, const char *attname)
Definition: relation.c:203
LogicalRepRelation remoterel
#define AttrNumberGetAttrOffset(attNum)
Definition: attnum.h:51
#define NoLock
Definition: lockdefs.h:34
static MemoryContext LogicalRepRelMapContext
Definition: relation.c:33
void CheckSubscriptionRelkind(char relkind, const char *nspname, const char *relname)
#define ereport(elevel, rest)
Definition: elog.h:122
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1284
#define NULL
Definition: c.h:229
char GetSubscriptionRelState(Oid subid, Oid relid, XLogRecPtr *sublsn, bool missing_ok)
void * palloc(Size size)
Definition: mcxt.c:849
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
Bitmapset * RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind attrKind)
Definition: relcache.c:4847
#define NameStr(name)
Definition: c.h:499
#define elog
Definition: elog.h:219
static void logicalrep_relmap_init(void)
Definition: relation.c:86
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:420
#define SUBREL_STATE_READY
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition: makefuncs.c:419
static HTAB * LogicalRepRelMap
Definition: relation.c:35
static void logicalrep_relmap_free_entry ( LogicalRepRelMapEntry entry)
static

Definition at line 126 of file relation.c.

References LogicalRepRelation::attkeys, LogicalRepRelation::attnames, LogicalRepRelMapEntry::attrmap, LogicalRepRelation::atttyps, bms_free(), i, LogicalRepRelation::natts, LogicalRepRelation::nspname, pfree(), LogicalRepRelation::relname, and LogicalRepRelMapEntry::remoterel.

Referenced by logicalrep_relmap_update().

127 {
128  LogicalRepRelation *remoterel;
129 
130  remoterel = &entry->remoterel;
131 
132  pfree(remoterel->nspname);
133  pfree(remoterel->relname);
134 
135  if (remoterel->natts > 0)
136  {
137  int i;
138 
139  for (i = 0; i < remoterel->natts; i++)
140  pfree(remoterel->attnames[i]);
141 
142  pfree(remoterel->attnames);
143  pfree(remoterel->atttyps);
144  }
145  bms_free(remoterel->attkeys);
146 
147  if (entry->attrmap)
148  pfree(entry->attrmap);
149 }
Bitmapset * attkeys
Definition: logicalproto.h:52
void pfree(void *pointer)
Definition: mcxt.c:950
LogicalRepRelation remoterel
void bms_free(Bitmapset *a)
Definition: bitmapset.c:201
int i
static void logicalrep_relmap_init ( void  )
static

Definition at line 86 of file relation.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate(), CacheMemoryContext, CacheRegisterRelcacheCallback(), CacheRegisterSyscacheCallback(), HASHCTL::entrysize, HASH_BLOBS, HASH_CONTEXT, hash_create(), HASH_ELEM, HASHCTL::hcxt, HASHCTL::keysize, logicalrep_relmap_invalidate_cb(), logicalrep_typmap_invalidate_cb(), LogicalRepRelMapContext, MemSet, and TYPEOID.

Referenced by logicalrep_rel_open(), logicalrep_relmap_update(), logicalrep_typmap_getid(), and logicalrep_typmap_update().

87 {
88  HASHCTL ctl;
89 
93  "LogicalRepRelMapContext",
95 
96  /* Initialize the relation hash table. */
97  MemSet(&ctl, 0, sizeof(ctl));
98  ctl.keysize = sizeof(LogicalRepRelId);
99  ctl.entrysize = sizeof(LogicalRepRelMapEntry);
101 
102  LogicalRepRelMap = hash_create("logicalrep relation map cache", 128, &ctl,
104 
105  /* Initialize the type hash table. */
106  MemSet(&ctl, 0, sizeof(ctl));
107  ctl.keysize = sizeof(Oid);
108  ctl.entrysize = sizeof(LogicalRepTyp);
110 
111  /* This will usually be small. */
112  LogicalRepTypMap = hash_create("logicalrep type map cache", 2, &ctl,
114 
115  /* Watch for invalidation events. */
117  (Datum) 0);
119  (Datum) 0);
120 }
#define HASH_CONTEXT
Definition: hsearch.h:93
#define HASH_ELEM
Definition: hsearch.h:87
MemoryContext hcxt
Definition: hsearch.h:78
Size entrysize
Definition: hsearch.h:73
#define MemSet(start, val, len)
Definition: c.h:857
unsigned int Oid
Definition: postgres_ext.h:31
static HTAB * LogicalRepTypMap
Definition: relation.c:36
void CacheRegisterRelcacheCallback(RelcacheCallbackFunction func, Datum arg)
Definition: inval.c:1431
static void logicalrep_relmap_invalidate_cb(Datum arg, Oid reloid)
Definition: relation.c:45
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:165
static MemoryContext LogicalRepRelMapContext
Definition: relation.c:33
struct LogicalRepTyp LogicalRepTyp
#define HASH_BLOBS
Definition: hsearch.h:88
static void logicalrep_typmap_invalidate_cb(Datum arg, int cacheid, uint32 hashvalue)
Definition: relation.c:379
struct LogicalRepRelMapEntry LogicalRepRelMapEntry
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: aset.c:322
void CacheRegisterSyscacheCallback(int cacheid, SyscacheCallbackFunction func, Datum arg)
Definition: inval.c:1389
uintptr_t Datum
Definition: postgres.h:372
HTAB * hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
Definition: dynahash.c:301
Size keysize
Definition: hsearch.h:72
static HTAB * LogicalRepRelMap
Definition: relation.c:35
uint32 LogicalRepRelId
Definition: logicalproto.h:39
MemoryContext CacheMemoryContext
Definition: mcxt.c:46
static void logicalrep_relmap_invalidate_cb ( Datum  arg,
Oid  reloid 
)
static

Definition at line 45 of file relation.c.

References hash_seq_init(), hash_seq_search(), hash_seq_term(), InvalidOid, LogicalRepRelMapEntry::localreloid, NULL, and status().

Referenced by logicalrep_relmap_init().

46 {
47  LogicalRepRelMapEntry *entry;
48 
49  /* Just to be sure. */
50  if (LogicalRepRelMap == NULL)
51  return;
52 
53  if (reloid != InvalidOid)
54  {
56 
58 
59  /* TODO, use inverse lookup hashtable? */
60  while ((entry = (LogicalRepRelMapEntry *) hash_seq_search(&status)) != NULL)
61  {
62  if (entry->localreloid == reloid)
63  {
64  entry->localreloid = InvalidOid;
65  hash_seq_term(&status);
66  break;
67  }
68  }
69  }
70  else
71  {
72  /* invalidate all cache entries */
74 
76 
77  while ((entry = (LogicalRepRelMapEntry *) hash_seq_search(&status)) != NULL)
78  entry->localreloid = InvalidOid;
79  }
80 }
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:229
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1351
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1341
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:224
void hash_seq_term(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1427
static HTAB * LogicalRepRelMap
Definition: relation.c:35
void logicalrep_relmap_update ( LogicalRepRelation remoterel)

Definition at line 158 of file relation.c.

References LogicalRepRelation::attkeys, LogicalRepRelation::attnames, LogicalRepRelation::atttyps, bms_copy(), HASH_ENTER, hash_search(), i, logicalrep_relmap_free_entry(), logicalrep_relmap_init(), MemoryContextSwitchTo(), LogicalRepRelation::natts, LogicalRepRelation::nspname, NULL, palloc(), pstrdup(), LogicalRepRelation::relname, LogicalRepRelation::remoteid, LogicalRepRelMapEntry::remoterel, and LogicalRepRelation::replident.

Referenced by apply_handle_relation(), and copy_table().

159 {
160  MemoryContext oldctx;
161  LogicalRepRelMapEntry *entry;
162  bool found;
163  int i;
164 
165  if (LogicalRepRelMap == NULL)
167 
168  /*
169  * HASH_ENTER returns the existing entry if present or creates a new one.
170  */
171  entry = hash_search(LogicalRepRelMap, (void *) &remoterel->remoteid,
172  HASH_ENTER, &found);
173 
174  if (found)
176 
177  memset(entry, 0, sizeof(LogicalRepRelMapEntry));
178 
179  /* Make cached copy of the data */
181  entry->remoterel.remoteid = remoterel->remoteid;
182  entry->remoterel.nspname = pstrdup(remoterel->nspname);
183  entry->remoterel.relname = pstrdup(remoterel->relname);
184  entry->remoterel.natts = remoterel->natts;
185  entry->remoterel.attnames = palloc(remoterel->natts * sizeof(char *));
186  entry->remoterel.atttyps = palloc(remoterel->natts * sizeof(Oid));
187  for (i = 0; i < remoterel->natts; i++)
188  {
189  entry->remoterel.attnames[i] = pstrdup(remoterel->attnames[i]);
190  entry->remoterel.atttyps[i] = remoterel->atttyps[i];
191  }
192  entry->remoterel.replident = remoterel->replident;
193  entry->remoterel.attkeys = bms_copy(remoterel->attkeys);
194  MemoryContextSwitchTo(oldctx);
195 }
static void logicalrep_relmap_free_entry(LogicalRepRelMapEntry *entry)
Definition: relation.c:126
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:111
char * pstrdup(const char *in)
Definition: mcxt.c:1077
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:885
unsigned int Oid
Definition: postgres_ext.h:31
Bitmapset * attkeys
Definition: logicalproto.h:52
LogicalRepRelId remoteid
Definition: logicalproto.h:45
LogicalRepRelation remoterel
static MemoryContext LogicalRepRelMapContext
Definition: relation.c:33
#define NULL
Definition: c.h:229
void * palloc(Size size)
Definition: mcxt.c:849
int i
static void logicalrep_relmap_init(void)
Definition: relation.c:86
static HTAB * LogicalRepRelMap
Definition: relation.c:35
static void logicalrep_typmap_free_entry ( LogicalRepTyp entry)
static

Definition at line 399 of file relation.c.

References InvalidOid, LogicalRepTyp::nspname, pfree(), LogicalRepTyp::typname, and LogicalRepTyp::typoid.

Referenced by logicalrep_typmap_update().

400 {
401  pfree(entry->nspname);
402  pfree(entry->typname);
403 
404  entry->typoid = InvalidOid;
405 }
char * typname
Definition: logicalproto.h:60
void pfree(void *pointer)
Definition: mcxt.c:950
#define InvalidOid
Definition: postgres_ext.h:36
char * nspname
Definition: logicalproto.h:59
Oid logicalrep_typmap_getid ( Oid  remoteid)

Definition at line 442 of file relation.c.

References elog, ereport, errcode(), errhint(), errmsg(), ERROR, FirstNormalObjectId, get_typisdefined(), GetSysCacheOid2, HASH_FIND, hash_search(), InvalidOid, logicalrep_relmap_init(), LookupExplicitNamespace(), LogicalRepTyp::nspname, NULL, ObjectIdGetDatum, OidIsValid, PointerGetDatum, TYPENAMENSP, LogicalRepTyp::typname, and LogicalRepTyp::typoid.

Referenced by slot_store_error_callback().

443 {
444  LogicalRepTyp *entry;
445  bool found;
446  Oid nspoid;
447 
448  /* Internal types are mapped directly. */
449  if (remoteid < FirstNormalObjectId)
450  {
451  if (!get_typisdefined(remoteid))
452  ereport(ERROR,
453  (errmsg("builtin type %u not found", remoteid),
454  errhint("This can be caused by having publisher with "
455  "higher major version than subscriber")));
456  return remoteid;
457  }
458 
459  if (LogicalRepTypMap == NULL)
461 
462  /* Try finding the mapping. */
463  entry = hash_search(LogicalRepTypMap, (void *) &remoteid,
464  HASH_FIND, &found);
465 
466  if (!found)
467  elog(ERROR, "no type map entry for remote type %u",
468  remoteid);
469 
470  /* Found and mapped, return the oid. */
471  if (OidIsValid(entry->typoid))
472  return entry->typoid;
473 
474  /* Otherwise, try to map to local type. */
475  nspoid = LookupExplicitNamespace(entry->nspname, true);
476  if (OidIsValid(nspoid))
478  PointerGetDatum(entry->typname),
479  ObjectIdGetDatum(nspoid));
480  else
481  entry->typoid = InvalidOid;
482 
483  if (!OidIsValid(entry->typoid))
484  ereport(ERROR,
485  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
486  errmsg("data type \"%s.%s\" required for logical replication does not exist",
487  entry->nspname, entry->typname)));
488 
489  return entry->typoid;
490 }
Oid LookupExplicitNamespace(const char *nspname, bool missing_ok)
Definition: namespace.c:2810
int errhint(const char *fmt,...)
Definition: elog.c:987
char * typname
Definition: logicalproto.h:60
#define PointerGetDatum(X)
Definition: postgres.h:562
bool get_typisdefined(Oid typid)
Definition: lsyscache.c:1923
int errcode(int sqlerrcode)
Definition: elog.c:575
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:885
unsigned int Oid
Definition: postgres_ext.h:31
static HTAB * LogicalRepTypMap
Definition: relation.c:36
#define OidIsValid(objectId)
Definition: c.h:538
#define FirstNormalObjectId
Definition: transam.h:94
#define GetSysCacheOid2(cacheId, key1, key2)
Definition: syscache.h:185
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:229
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219
static void logicalrep_relmap_init(void)
Definition: relation.c:86
char * nspname
Definition: logicalproto.h:59
static void logicalrep_typmap_invalidate_cb ( Datum  arg,
int  cacheid,
uint32  hashvalue 
)
static

Definition at line 379 of file relation.c.

References hash_seq_init(), hash_seq_search(), InvalidOid, NULL, status(), and LogicalRepTyp::typoid.

Referenced by logicalrep_relmap_init().

380 {
382  LogicalRepTyp *entry;
383 
384  /* Just to be sure. */
385  if (LogicalRepTypMap == NULL)
386  return;
387 
388  /* invalidate all cache entries */
390 
391  while ((entry = (LogicalRepTyp *) hash_seq_search(&status)) != NULL)
392  entry->typoid = InvalidOid;
393 }
static HTAB * LogicalRepTypMap
Definition: relation.c:36
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:229
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1351
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1341
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:224
void logicalrep_typmap_update ( LogicalRepTyp remotetyp)

Definition at line 411 of file relation.c.

References HASH_ENTER, hash_search(), InvalidOid, logicalrep_relmap_init(), logicalrep_typmap_free_entry(), MemoryContextSwitchTo(), LogicalRepTyp::nspname, NULL, pstrdup(), LogicalRepTyp::remoteid, LogicalRepTyp::typname, and LogicalRepTyp::typoid.

Referenced by apply_handle_type().

412 {
413  MemoryContext oldctx;
414  LogicalRepTyp *entry;
415  bool found;
416 
417  if (LogicalRepTypMap == NULL)
419 
420  /*
421  * HASH_ENTER returns the existing entry if present or creates a new one.
422  */
423  entry = hash_search(LogicalRepTypMap, (void *) &remotetyp->remoteid,
424  HASH_ENTER, &found);
425 
426  if (found)
428 
429  /* Make cached copy of the data */
430  entry->remoteid = remotetyp->remoteid;
432  entry->nspname = pstrdup(remotetyp->nspname);
433  entry->typname = pstrdup(remotetyp->typname);
434  MemoryContextSwitchTo(oldctx);
435  entry->typoid = InvalidOid;
436 }
char * typname
Definition: logicalproto.h:60
char * pstrdup(const char *in)
Definition: mcxt.c:1077
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:885
static HTAB * LogicalRepTypMap
Definition: relation.c:36
static MemoryContext LogicalRepRelMapContext
Definition: relation.c:33
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:229
static void logicalrep_relmap_init(void)
Definition: relation.c:86
static void logicalrep_typmap_free_entry(LogicalRepTyp *entry)
Definition: relation.c:399
char * nspname
Definition: logicalproto.h:59

Variable Documentation

HTAB* LogicalRepRelMap = NULL
static

Definition at line 35 of file relation.c.

MemoryContext LogicalRepRelMapContext = NULL
static

Definition at line 33 of file relation.c.

Referenced by logicalrep_relmap_init().

HTAB* LogicalRepTypMap = NULL
static

Definition at line 36 of file relation.c.