#include "access/xlog.h"

Go to the source code of this file.
Data Structures | |
| struct | xl_relmap_update |
Defines | |
| #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) |
| 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 (XLogRecPtr lsn, XLogRecord *record) |
| void | relmap_desc (StringInfo buf, uint8 xl_info, char *rec) |
| #define MinSizeOfRelmapUpdate offsetof(xl_relmap_update, data) |
Definition at line 34 of file relmapper.h.
| #define XLOG_RELMAP_UPDATE 0x00 |
Definition at line 24 of file relmapper.h.
Referenced by relmap_desc(), relmap_redo(), and write_relmap_file().
| typedef struct xl_relmap_update xl_relmap_update |
| void AtCCI_RelationMap | ( | void | ) |
Definition at line 367 of file relmapper.c.
References merge_map_updates(), and RelMapFile::num_mappings.
Referenced by AtCCI_LocalCache().
{
if (pending_shared_updates.num_mappings != 0)
{
merge_map_updates(&active_shared_updates,
&pending_shared_updates,
true);
pending_shared_updates.num_mappings = 0;
}
if (pending_local_updates.num_mappings != 0)
{
merge_map_updates(&active_local_updates,
&pending_local_updates,
true);
pending_local_updates.num_mappings = 0;
}
}
| void AtEOXact_RelationMap | ( | bool | isCommit | ) |
Definition at line 401 of file relmapper.c.
References Assert, RelMapFile::num_mappings, and perform_relmap_update().
Referenced by AbortTransaction(), and CommitTransaction().
{
if (isCommit)
{
/*
* We should not get here with any "pending" updates. (We could
* logically choose to treat such as committed, but in the current
* code this should never happen.)
*/
Assert(pending_shared_updates.num_mappings == 0);
Assert(pending_local_updates.num_mappings == 0);
/*
* Write any active updates to the actual map files, then reset them.
*/
if (active_shared_updates.num_mappings != 0)
{
perform_relmap_update(true, &active_shared_updates);
active_shared_updates.num_mappings = 0;
}
if (active_local_updates.num_mappings != 0)
{
perform_relmap_update(false, &active_local_updates);
active_local_updates.num_mappings = 0;
}
}
else
{
/* Abort --- drop all local and pending updates */
active_shared_updates.num_mappings = 0;
active_local_updates.num_mappings = 0;
pending_shared_updates.num_mappings = 0;
pending_local_updates.num_mappings = 0;
}
}
| void AtPrepare_RelationMap | ( | void | ) |
Definition at line 445 of file relmapper.c.
References ereport, errcode(), errmsg(), ERROR, and RelMapFile::num_mappings.
Referenced by PrepareTransaction().
{
if (active_shared_updates.num_mappings != 0 ||
active_local_updates.num_mappings != 0 ||
pending_shared_updates.num_mappings != 0 ||
pending_local_updates.num_mappings != 0)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot PREPARE a transaction that modified relation mapping")));
}
| void CheckPointRelationMap | ( | void | ) |
Definition at line 468 of file relmapper.c.
References LW_SHARED, LWLockAcquire(), LWLockRelease(), and RelationMappingLock.
Referenced by CheckPointGuts().
| void RelationMapFinishBootstrap | ( | void | ) |
Definition at line 482 of file relmapper.c.
References Assert, DatabasePath, GLOBALTABLESPACE_OID, InvalidOid, IsBootstrapProcessingMode, MyDatabaseId, MyDatabaseTableSpace, NULL, RelMapFile::num_mappings, and write_relmap_file().
Referenced by BootstrapModeMain().
{
Assert(IsBootstrapProcessingMode());
/* Shouldn't be anything "pending" ... */
Assert(active_shared_updates.num_mappings == 0);
Assert(active_local_updates.num_mappings == 0);
Assert(pending_shared_updates.num_mappings == 0);
Assert(pending_local_updates.num_mappings == 0);
/* Write the files; no WAL or sinval needed */
write_relmap_file(true, &shared_map, false, false, false,
InvalidOid, GLOBALTABLESPACE_OID, NULL);
write_relmap_file(false, &local_map, false, false, false,
MyDatabaseId, MyDatabaseTableSpace, DatabasePath);
}
| void RelationMapInitialize | ( | void | ) |
Definition at line 506 of file relmapper.c.
References RelMapFile::magic, and RelMapFile::num_mappings.
Referenced by RelationCacheInitialize().
{
/* The static variables should initialize to zeroes, but let's be sure */
shared_map.magic = 0; /* mark it not loaded */
local_map.magic = 0;
shared_map.num_mappings = 0;
local_map.num_mappings = 0;
active_shared_updates.num_mappings = 0;
active_local_updates.num_mappings = 0;
pending_shared_updates.num_mappings = 0;
pending_local_updates.num_mappings = 0;
}
| void RelationMapInitializePhase2 | ( | void | ) |
Definition at line 526 of file relmapper.c.
References IsBootstrapProcessingMode, and load_relmap_file().
Referenced by RelationCacheInitializePhase2().
{
/*
* In bootstrap mode, the map file isn't there yet, so do nothing.
*/
if (IsBootstrapProcessingMode())
return;
/*
* Load the shared map file, die on error.
*/
load_relmap_file(true);
}
| void RelationMapInitializePhase3 | ( | void | ) |
Definition at line 547 of file relmapper.c.
References IsBootstrapProcessingMode, and load_relmap_file().
Referenced by RelationCacheInitializePhase3().
{
/*
* In bootstrap mode, the map file isn't there yet, so do nothing.
*/
if (IsBootstrapProcessingMode())
return;
/*
* Load the local map file, die on error.
*/
load_relmap_file(false);
}
| void RelationMapInvalidate | ( | bool | shared | ) |
Definition at line 331 of file relmapper.c.
References load_relmap_file(), RelMapFile::magic, and RELMAPPER_FILEMAGIC.
Referenced by LocalExecuteInvalidationMessage().
{
if (shared)
{
if (shared_map.magic == RELMAPPER_FILEMAGIC)
load_relmap_file(true);
}
else
{
if (local_map.magic == RELMAPPER_FILEMAGIC)
load_relmap_file(false);
}
}
| void RelationMapInvalidateAll | ( | void | ) |
Definition at line 353 of file relmapper.c.
References load_relmap_file(), RelMapFile::magic, and RELMAPPER_FILEMAGIC.
Referenced by RelationCacheInvalidate().
{
if (shared_map.magic == RELMAPPER_FILEMAGIC)
load_relmap_file(true);
if (local_map.magic == RELMAPPER_FILEMAGIC)
load_relmap_file(false);
}
Definition at line 143 of file relmapper.c.
References i, RelMapping::mapfilenode, RelMapping::mapoid, RelMapFile::mappings, and RelMapFile::num_mappings.
Referenced by pg_relation_filenode(), pg_relation_filepath(), RelationInitPhysicalAddr(), and swap_relation_files().
{
const RelMapFile *map;
int32 i;
/* If there are active updates, believe those over the main maps */
if (shared)
{
map = &active_shared_updates;
for (i = 0; i < map->num_mappings; i++)
{
if (relationId == map->mappings[i].mapoid)
return map->mappings[i].mapfilenode;
}
map = &shared_map;
for (i = 0; i < map->num_mappings; i++)
{
if (relationId == map->mappings[i].mapoid)
return map->mappings[i].mapfilenode;
}
}
else
{
map = &active_local_updates;
for (i = 0; i < map->num_mappings; i++)
{
if (relationId == map->mappings[i].mapoid)
return map->mappings[i].mapfilenode;
}
map = &local_map;
for (i = 0; i < map->num_mappings; i++)
{
if (relationId == map->mappings[i].mapoid)
return map->mappings[i].mapfilenode;
}
}
return InvalidOid;
}
| void RelationMapRemoveMapping | ( | Oid | relationId | ) |
Definition at line 301 of file relmapper.c.
References elog, ERROR, i, RelMapping::mapoid, RelMapFile::mappings, and RelMapFile::num_mappings.
Referenced by finish_heap_swap().
{
RelMapFile *map = &active_local_updates;
int32 i;
for (i = 0; i < map->num_mappings; i++)
{
if (relationId == map->mappings[i].mapoid)
{
/* Found it, collapse it out */
map->mappings[i] = map->mappings[map->num_mappings - 1];
map->num_mappings--;
return;
}
}
elog(ERROR, "could not find temporary mapping for relation %u",
relationId);
}
Definition at line 192 of file relmapper.c.
References apply_map_update(), elog, ERROR, GetCurrentTransactionNestLevel(), and IsBootstrapProcessingMode.
Referenced by formrdesc(), RelationBuildLocalRelation(), RelationSetNewRelfilenode(), and swap_relation_files().
{
RelMapFile *map;
if (IsBootstrapProcessingMode())
{
/*
* In bootstrap mode, the mapping gets installed in permanent map.
*/
if (shared)
map = &shared_map;
else
map = &local_map;
}
else
{
/*
* We don't currently support map changes within subtransactions. This
* could be done with more bookkeeping infrastructure, but it doesn't
* presently seem worth it.
*/
if (GetCurrentTransactionNestLevel() > 1)
elog(ERROR, "cannot change relation mapping within subtransaction");
if (immediate)
{
/* Make it active, but only locally */
if (shared)
map = &active_shared_updates;
else
map = &active_local_updates;
}
else
{
/* Make it pending */
if (shared)
map = &pending_shared_updates;
else
map = &pending_local_updates;
}
}
apply_map_update(map, relationId, fileNode, true);
}
| void relmap_desc | ( | StringInfo | buf, | |
| uint8 | xl_info, | |||
| char * | rec | |||
| ) |
Definition at line 20 of file relmapdesc.c.
References appendStringInfo(), xl_relmap_update::dbid, xl_relmap_update::nbytes, xl_relmap_update::tsid, and XLOG_RELMAP_UPDATE.
{
uint8 info = xl_info & ~XLR_INFO_MASK;
if (info == XLOG_RELMAP_UPDATE)
{
xl_relmap_update *xlrec = (xl_relmap_update *) rec;
appendStringInfo(buf, "update relmap: database %u tablespace %u size %u",
xlrec->dbid, xlrec->tsid, xlrec->nbytes);
}
else
appendStringInfo(buf, "UNKNOWN");
}
| void relmap_redo | ( | XLogRecPtr | lsn, | |
| XLogRecord * | record | |||
| ) |
Definition at line 855 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(), XLogRecord::xl_info, XLOG_RELMAP_UPDATE, XLogRecGetData, and XLR_BKP_BLOCK_MASK.
{
uint8 info = record->xl_info & ~XLR_INFO_MASK;
/* Backup blocks are not used in relmap records */
Assert(!(record->xl_info & XLR_BKP_BLOCK_MASK));
if (info == XLOG_RELMAP_UPDATE)
{
xl_relmap_update *xlrec = (xl_relmap_update *) XLogRecGetData(record);
RelMapFile newmap;
char *dbpath;
if (xlrec->nbytes != sizeof(RelMapFile))
elog(PANIC, "relmap_redo: wrong size %u in relmap update record",
xlrec->nbytes);
memcpy(&newmap, xlrec->data, sizeof(newmap));
/* We need to construct the pathname for this database */
dbpath = GetDatabasePath(xlrec->dbid, xlrec->tsid);
/*
* Write out the new map and send sinval, but of course don't write a
* new WAL entry. There's no surrounding transaction to tell to
* preserve files, either.
*
* There shouldn't be anyone else updating relmaps during WAL replay,
* so we don't bother to take the RelationMappingLock. We would need
* to do so if load_relmap_file needed to interlock against writers.
*/
write_relmap_file((xlrec->dbid == InvalidOid), &newmap,
false, true, false,
xlrec->dbid, xlrec->tsid, dbpath);
pfree(dbpath);
}
else
elog(PANIC, "relmap_redo: unknown op code %u", info);
}
1.7.1