PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
relmapper.h File Reference
#include "access/xlogreader.h"
#include "lib/stringinfo.h"
Include dependency graph for relmapper.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  xl_relmap_update
 

Macros

#define XLOG_RELMAP_UPDATE   0x00
 
#define MinSizeOfRelmapUpdate   offsetof(xl_relmap_update, data)
 

Typedefs

typedef struct xl_relmap_update xl_relmap_update
 

Functions

Oid RelationMapOidToFilenode (Oid relationId, bool shared)
 
Oid RelationMapFilenodeToOid (Oid relationId, bool shared)
 
void RelationMapUpdateMap (Oid relationId, Oid fileNode, bool shared, bool immediate)
 
void RelationMapRemoveMapping (Oid relationId)
 
void RelationMapInvalidate (bool shared)
 
void RelationMapInvalidateAll (void)
 
void AtCCI_RelationMap (void)
 
void AtEOXact_RelationMap (bool isCommit)
 
void AtPrepare_RelationMap (void)
 
void CheckPointRelationMap (void)
 
void RelationMapFinishBootstrap (void)
 
void RelationMapInitialize (void)
 
void RelationMapInitializePhase2 (void)
 
void RelationMapInitializePhase3 (void)
 
void relmap_redo (XLogReaderState *record)
 
void relmap_desc (StringInfo buf, XLogReaderState *record)
 
const char * relmap_identify (uint8 info)
 

Macro Definition Documentation

#define MinSizeOfRelmapUpdate   offsetof(xl_relmap_update, data)

Definition at line 35 of file relmapper.h.

Referenced by write_relmap_file().

#define XLOG_RELMAP_UPDATE   0x00

Definition at line 25 of file relmapper.h.

Referenced by relmap_desc(), relmap_identify(), relmap_redo(), and write_relmap_file().

Typedef Documentation

Function Documentation

void AtCCI_RelationMap ( void  )

Definition at line 423 of file relmapper.c.

References merge_map_updates(), and RelMapFile::num_mappings.

Referenced by AtCCI_LocalCache().

424 {
426  {
429  true);
431  }
433  {
436  true);
438  }
439 }
static void merge_map_updates(RelMapFile *map, const RelMapFile *updates, bool add_okay)
Definition: relmapper.c:335
static RelMapFile pending_shared_updates
Definition: relmapper.c:117
static RelMapFile active_local_updates
Definition: relmapper.c:116
static RelMapFile pending_local_updates
Definition: relmapper.c:118
static RelMapFile active_shared_updates
Definition: relmapper.c:115
int32 num_mappings
Definition: relmapper.c:88
void AtEOXact_RelationMap ( bool  isCommit)

Definition at line 457 of file relmapper.c.

References Assert, RelMapFile::num_mappings, and perform_relmap_update().

Referenced by AbortTransaction(), and CommitTransaction().

458 {
459  if (isCommit)
460  {
461  /*
462  * We should not get here with any "pending" updates. (We could
463  * logically choose to treat such as committed, but in the current
464  * code this should never happen.)
465  */
468 
469  /*
470  * Write any active updates to the actual map files, then reset them.
471  */
473  {
476  }
478  {
481  }
482  }
483  else
484  {
485  /* Abort --- drop all local and pending updates */
490  }
491 }
static RelMapFile pending_shared_updates
Definition: relmapper.c:117
static void perform_relmap_update(bool shared, const RelMapFile *updates)
Definition: relmapper.c:863
static RelMapFile active_local_updates
Definition: relmapper.c:116
static RelMapFile pending_local_updates
Definition: relmapper.c:118
static RelMapFile active_shared_updates
Definition: relmapper.c:115
#define Assert(condition)
Definition: c.h:675
int32 num_mappings
Definition: relmapper.c:88
void AtPrepare_RelationMap ( void  )

Definition at line 501 of file relmapper.c.

References ereport, errcode(), errmsg(), ERROR, and RelMapFile::num_mappings.

Referenced by PrepareTransaction().

502 {
507  ereport(ERROR,
508  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
509  errmsg("cannot PREPARE a transaction that modified relation mapping")));
510 }
int errcode(int sqlerrcode)
Definition: elog.c:575
static RelMapFile pending_shared_updates
Definition: relmapper.c:117
#define ERROR
Definition: elog.h:43
static RelMapFile active_local_updates
Definition: relmapper.c:116
static RelMapFile pending_local_updates
Definition: relmapper.c:118
#define ereport(elevel, rest)
Definition: elog.h:122
static RelMapFile active_shared_updates
Definition: relmapper.c:115
int errmsg(const char *fmt,...)
Definition: elog.c:797
int32 num_mappings
Definition: relmapper.c:88
void CheckPointRelationMap ( void  )

Definition at line 524 of file relmapper.c.

References LW_SHARED, LWLockAcquire(), and LWLockRelease().

Referenced by CheckPointGuts().

525 {
526  LWLockAcquire(RelationMappingLock, LW_SHARED);
527  LWLockRelease(RelationMappingLock);
528 }
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1715
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1111
Oid RelationMapFilenodeToOid ( Oid  relationId,
bool  shared 
)

Definition at line 199 of file relmapper.c.

References active_local_updates, active_shared_updates, i, InvalidOid, local_map, RelMapping::mapfilenode, RelMapping::mapoid, RelMapFile::mappings, RelMapFile::num_mappings, and shared_map.

Referenced by RelidByRelfilenode().

200 {
201  const RelMapFile *map;
202  int32 i;
203 
204  /* If there are active updates, believe those over the main maps */
205  if (shared)
206  {
207  map = &active_shared_updates;
208  for (i = 0; i < map->num_mappings; i++)
209  {
210  if (filenode == map->mappings[i].mapfilenode)
211  return map->mappings[i].mapoid;
212  }
213  map = &shared_map;
214  for (i = 0; i < map->num_mappings; i++)
215  {
216  if (filenode == map->mappings[i].mapfilenode)
217  return map->mappings[i].mapoid;
218  }
219  }
220  else
221  {
222  map = &active_local_updates;
223  for (i = 0; i < map->num_mappings; i++)
224  {
225  if (filenode == map->mappings[i].mapfilenode)
226  return map->mappings[i].mapoid;
227  }
228  map = &local_map;
229  for (i = 0; i < map->num_mappings; i++)
230  {
231  if (filenode == map->mappings[i].mapfilenode)
232  return map->mappings[i].mapoid;
233  }
234  }
235 
236  return InvalidOid;
237 }
Oid mapoid
Definition: relmapper.c:81
static RelMapFile local_map
Definition: relmapper.c:100
signed int int32
Definition: c.h:256
static RelMapFile shared_map
Definition: relmapper.c:99
static RelMapFile active_local_updates
Definition: relmapper.c:116
RelMapping mappings[MAX_MAPPINGS]
Definition: relmapper.c:89
static RelMapFile active_shared_updates
Definition: relmapper.c:115
#define InvalidOid
Definition: postgres_ext.h:36
Oid mapfilenode
Definition: relmapper.c:82
int i
int32 num_mappings
Definition: relmapper.c:88
void RelationMapFinishBootstrap ( void  )

Definition at line 538 of file relmapper.c.

References Assert, DatabasePath, GLOBALTABLESPACE_OID, InvalidOid, IsBootstrapProcessingMode, MyDatabaseId, MyDatabaseTableSpace, NULL, RelMapFile::num_mappings, and write_relmap_file().

Referenced by BootstrapModeMain().

539 {
541 
542  /* Shouldn't be anything "pending" ... */
547 
548  /* Write the files; no WAL or sinval needed */
549  write_relmap_file(true, &shared_map, false, false, false,
551  write_relmap_file(false, &local_map, false, false, false,
553 }
static RelMapFile local_map
Definition: relmapper.c:100
#define GLOBALTABLESPACE_OID
Definition: pg_tablespace.h:64
static void write_relmap_file(bool shared, RelMapFile *newmap, bool write_wal, bool send_sinval, bool preserve_files, Oid dbid, Oid tsid, const char *dbpath)
Definition: relmapper.c:712
Oid MyDatabaseTableSpace
Definition: globals.c:78
static RelMapFile pending_shared_updates
Definition: relmapper.c:117
static RelMapFile shared_map
Definition: relmapper.c:99
static RelMapFile active_local_updates
Definition: relmapper.c:116
static RelMapFile pending_local_updates
Definition: relmapper.c:118
static RelMapFile active_shared_updates
Definition: relmapper.c:115
Oid MyDatabaseId
Definition: globals.c:76
#define InvalidOid
Definition: postgres_ext.h:36
char * DatabasePath
Definition: globals.c:84
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:365
int32 num_mappings
Definition: relmapper.c:88
void RelationMapInitialize ( void  )

Definition at line 562 of file relmapper.c.

References RelMapFile::magic, and RelMapFile::num_mappings.

Referenced by RelationCacheInitialize().

563 {
564  /* The static variables should initialize to zeroes, but let's be sure */
565  shared_map.magic = 0; /* mark it not loaded */
566  local_map.magic = 0;
573 }
int32 magic
Definition: relmapper.c:87
static RelMapFile local_map
Definition: relmapper.c:100
static RelMapFile pending_shared_updates
Definition: relmapper.c:117
static RelMapFile shared_map
Definition: relmapper.c:99
static RelMapFile active_local_updates
Definition: relmapper.c:116
static RelMapFile pending_local_updates
Definition: relmapper.c:118
static RelMapFile active_shared_updates
Definition: relmapper.c:115
int32 num_mappings
Definition: relmapper.c:88
void RelationMapInitializePhase2 ( void  )

Definition at line 582 of file relmapper.c.

References IsBootstrapProcessingMode, and load_relmap_file().

Referenced by RelationCacheInitializePhase2().

583 {
584  /*
585  * In bootstrap mode, the map file isn't there yet, so do nothing.
586  */
588  return;
589 
590  /*
591  * Load the shared map file, die on error.
592  */
593  load_relmap_file(true);
594 }
static void load_relmap_file(bool shared)
Definition: relmapper.c:626
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:365
void RelationMapInitializePhase3 ( void  )

Definition at line 603 of file relmapper.c.

References IsBootstrapProcessingMode, and load_relmap_file().

Referenced by RelationCacheInitializePhase3().

604 {
605  /*
606  * In bootstrap mode, the map file isn't there yet, so do nothing.
607  */
609  return;
610 
611  /*
612  * Load the local map file, die on error.
613  */
614  load_relmap_file(false);
615 }
static void load_relmap_file(bool shared)
Definition: relmapper.c:626
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:365
void RelationMapInvalidate ( bool  shared)

Definition at line 387 of file relmapper.c.

References load_relmap_file(), RelMapFile::magic, and RELMAPPER_FILEMAGIC.

Referenced by LocalExecuteInvalidationMessage().

388 {
389  if (shared)
390  {
392  load_relmap_file(true);
393  }
394  else
395  {
397  load_relmap_file(false);
398  }
399 }
int32 magic
Definition: relmapper.c:87
static RelMapFile local_map
Definition: relmapper.c:100
#define RELMAPPER_FILEMAGIC
Definition: relmapper.c:75
static RelMapFile shared_map
Definition: relmapper.c:99
static void load_relmap_file(bool shared)
Definition: relmapper.c:626
void RelationMapInvalidateAll ( void  )

Definition at line 409 of file relmapper.c.

References load_relmap_file(), RelMapFile::magic, and RELMAPPER_FILEMAGIC.

Referenced by RelationCacheInvalidate().

410 {
412  load_relmap_file(true);
414  load_relmap_file(false);
415 }
int32 magic
Definition: relmapper.c:87
static RelMapFile local_map
Definition: relmapper.c:100
#define RELMAPPER_FILEMAGIC
Definition: relmapper.c:75
static RelMapFile shared_map
Definition: relmapper.c:99
static void load_relmap_file(bool shared)
Definition: relmapper.c:626
Oid RelationMapOidToFilenode ( Oid  relationId,
bool  shared 
)

Definition at line 146 of file relmapper.c.

References active_local_updates, active_shared_updates, i, InvalidOid, local_map, RelMapping::mapfilenode, RelMapping::mapoid, RelMapFile::mappings, RelMapFile::num_mappings, and shared_map.

Referenced by pg_relation_filenode(), pg_relation_filepath(), RelationInitPhysicalAddr(), and swap_relation_files().

147 {
148  const RelMapFile *map;
149  int32 i;
150 
151  /* If there are active updates, believe those over the main maps */
152  if (shared)
153  {
154  map = &active_shared_updates;
155  for (i = 0; i < map->num_mappings; i++)
156  {
157  if (relationId == map->mappings[i].mapoid)
158  return map->mappings[i].mapfilenode;
159  }
160  map = &shared_map;
161  for (i = 0; i < map->num_mappings; i++)
162  {
163  if (relationId == map->mappings[i].mapoid)
164  return map->mappings[i].mapfilenode;
165  }
166  }
167  else
168  {
169  map = &active_local_updates;
170  for (i = 0; i < map->num_mappings; i++)
171  {
172  if (relationId == map->mappings[i].mapoid)
173  return map->mappings[i].mapfilenode;
174  }
175  map = &local_map;
176  for (i = 0; i < map->num_mappings; i++)
177  {
178  if (relationId == map->mappings[i].mapoid)
179  return map->mappings[i].mapfilenode;
180  }
181  }
182 
183  return InvalidOid;
184 }
Oid mapoid
Definition: relmapper.c:81
static RelMapFile local_map
Definition: relmapper.c:100
signed int int32
Definition: c.h:256
static RelMapFile shared_map
Definition: relmapper.c:99
static RelMapFile active_local_updates
Definition: relmapper.c:116
RelMapping mappings[MAX_MAPPINGS]
Definition: relmapper.c:89
static RelMapFile active_shared_updates
Definition: relmapper.c:115
#define InvalidOid
Definition: postgres_ext.h:36
Oid mapfilenode
Definition: relmapper.c:82
int i
int32 num_mappings
Definition: relmapper.c:88
void RelationMapRemoveMapping ( Oid  relationId)

Definition at line 357 of file relmapper.c.

References active_local_updates, elog, ERROR, i, RelMapping::mapoid, RelMapFile::mappings, and RelMapFile::num_mappings.

Referenced by finish_heap_swap().

358 {
360  int32 i;
361 
362  for (i = 0; i < map->num_mappings; i++)
363  {
364  if (relationId == map->mappings[i].mapoid)
365  {
366  /* Found it, collapse it out */
367  map->mappings[i] = map->mappings[map->num_mappings - 1];
368  map->num_mappings--;
369  return;
370  }
371  }
372  elog(ERROR, "could not find temporary mapping for relation %u",
373  relationId);
374 }
Oid mapoid
Definition: relmapper.c:81
signed int int32
Definition: c.h:256
#define ERROR
Definition: elog.h:43
static RelMapFile active_local_updates
Definition: relmapper.c:116
RelMapping mappings[MAX_MAPPINGS]
Definition: relmapper.c:89
int i
#define elog
Definition: elog.h:219
int32 num_mappings
Definition: relmapper.c:88
void RelationMapUpdateMap ( Oid  relationId,
Oid  fileNode,
bool  shared,
bool  immediate 
)

Definition at line 248 of file relmapper.c.

References active_local_updates, active_shared_updates, apply_map_update(), elog, ERROR, GetCurrentTransactionNestLevel(), IsBootstrapProcessingMode, local_map, pending_local_updates, pending_shared_updates, and shared_map.

Referenced by formrdesc(), RelationBuildLocalRelation(), RelationSetNewRelfilenode(), and swap_relation_files().

250 {
251  RelMapFile *map;
252 
254  {
255  /*
256  * In bootstrap mode, the mapping gets installed in permanent map.
257  */
258  if (shared)
259  map = &shared_map;
260  else
261  map = &local_map;
262  }
263  else
264  {
265  /*
266  * We don't currently support map changes within subtransactions. This
267  * could be done with more bookkeeping infrastructure, but it doesn't
268  * presently seem worth it.
269  */
271  elog(ERROR, "cannot change relation mapping within subtransaction");
272 
273  if (immediate)
274  {
275  /* Make it active, but only locally */
276  if (shared)
277  map = &active_shared_updates;
278  else
279  map = &active_local_updates;
280  }
281  else
282  {
283  /* Make it pending */
284  if (shared)
285  map = &pending_shared_updates;
286  else
287  map = &pending_local_updates;
288  }
289  }
290  apply_map_update(map, relationId, fileNode, true);
291 }
static RelMapFile local_map
Definition: relmapper.c:100
static RelMapFile pending_shared_updates
Definition: relmapper.c:117
static RelMapFile shared_map
Definition: relmapper.c:99
#define ERROR
Definition: elog.h:43
static RelMapFile active_local_updates
Definition: relmapper.c:116
static RelMapFile pending_local_updates
Definition: relmapper.c:118
static RelMapFile active_shared_updates
Definition: relmapper.c:115
int GetCurrentTransactionNestLevel(void)
Definition: xact.c:761
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:365
#define elog
Definition: elog.h:219
static void apply_map_update(RelMapFile *map, Oid relationId, Oid fileNode, bool add_okay)
Definition: relmapper.c:303
void relmap_desc ( StringInfo  buf,
XLogReaderState record 
)

Definition at line 20 of file relmapdesc.c.

References appendStringInfo(), xl_relmap_update::dbid, xl_relmap_update::nbytes, xl_relmap_update::tsid, XLOG_RELMAP_UPDATE, XLogRecGetData, XLogRecGetInfo, and XLR_INFO_MASK.

21 {
22  char *rec = XLogRecGetData(record);
23  uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
24 
25  if (info == XLOG_RELMAP_UPDATE)
26  {
27  xl_relmap_update *xlrec = (xl_relmap_update *) rec;
28 
29  appendStringInfo(buf, "database %u tablespace %u size %u",
30  xlrec->dbid, xlrec->tsid, xlrec->nbytes);
31  }
32 }
unsigned char uint8
Definition: c.h:266
#define XLogRecGetData(decoder)
Definition: xlogreader.h:220
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:78
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:216
#define XLOG_RELMAP_UPDATE
Definition: relmapper.h:25
#define XLR_INFO_MASK
Definition: xlogrecord.h:62
const char* relmap_identify ( uint8  info)

Definition at line 35 of file relmapdesc.c.

References NULL, XLOG_RELMAP_UPDATE, and XLR_INFO_MASK.

36 {
37  const char *id = NULL;
38 
39  switch (info & ~XLR_INFO_MASK)
40  {
41  case XLOG_RELMAP_UPDATE:
42  id = "UPDATE";
43  break;
44  }
45 
46  return id;
47 }
#define XLOG_RELMAP_UPDATE
Definition: relmapper.h:25
#define NULL
Definition: c.h:229
#define XLR_INFO_MASK
Definition: xlogrecord.h:62
void relmap_redo ( XLogReaderState record)

Definition at line 911 of file relmapper.c.

References Assert, xl_relmap_update::data, xl_relmap_update::dbid, elog, GetDatabasePath(), InvalidOid, xl_relmap_update::nbytes, PANIC, pfree(), xl_relmap_update::tsid, write_relmap_file(), XLOG_RELMAP_UPDATE, XLogRecGetData, XLogRecGetInfo, XLogRecHasAnyBlockRefs, and XLR_INFO_MASK.

912 {
913  uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
914 
915  /* Backup blocks are not used in relmap records */
916  Assert(!XLogRecHasAnyBlockRefs(record));
917 
918  if (info == XLOG_RELMAP_UPDATE)
919  {
920  xl_relmap_update *xlrec = (xl_relmap_update *) XLogRecGetData(record);
921  RelMapFile newmap;
922  char *dbpath;
923 
924  if (xlrec->nbytes != sizeof(RelMapFile))
925  elog(PANIC, "relmap_redo: wrong size %u in relmap update record",
926  xlrec->nbytes);
927  memcpy(&newmap, xlrec->data, sizeof(newmap));
928 
929  /* We need to construct the pathname for this database */
930  dbpath = GetDatabasePath(xlrec->dbid, xlrec->tsid);
931 
932  /*
933  * Write out the new map and send sinval, but of course don't write a
934  * new WAL entry. There's no surrounding transaction to tell to
935  * preserve files, either.
936  *
937  * There shouldn't be anyone else updating relmaps during WAL replay,
938  * so we don't bother to take the RelationMappingLock. We would need
939  * to do so if load_relmap_file needed to interlock against writers.
940  */
941  write_relmap_file((xlrec->dbid == InvalidOid), &newmap,
942  false, true, false,
943  xlrec->dbid, xlrec->tsid, dbpath);
944 
945  pfree(dbpath);
946  }
947  else
948  elog(PANIC, "relmap_redo: unknown op code %u", info);
949 }
unsigned char uint8
Definition: c.h:266
static void write_relmap_file(bool shared, RelMapFile *newmap, bool write_wal, bool send_sinval, bool preserve_files, Oid dbid, Oid tsid, const char *dbpath)
Definition: relmapper.c:712
#define PANIC
Definition: elog.h:53
void pfree(void *pointer)
Definition: mcxt.c:950
#define XLogRecGetData(decoder)
Definition: xlogreader.h:220
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:216
char * GetDatabasePath(Oid dbNode, Oid spcNode)
Definition: relpath.c:108
#define XLOG_RELMAP_UPDATE
Definition: relmapper.h:25
#define InvalidOid
Definition: postgres_ext.h:36
#define Assert(condition)
Definition: c.h:675
#define XLR_INFO_MASK
Definition: xlogrecord.h:62
#define XLogRecHasAnyBlockRefs(decoder)
Definition: xlogreader.h:222
#define elog
Definition: elog.h:219
char data[FLEXIBLE_ARRAY_MEMBER]
Definition: relmapper.h:32