1 /*-------------------------------------------------------------------------
4 * Catalog-to-filenode mapping
6 * For most tables, the physical file underlying the table is specified by
7 * pg_class.relfilenode. However, that obviously won't work for pg_class
8 * itself, nor for the other "nailed" catalogs for which we have to be able
9 * to set up working Relation entries without access to pg_class. It also
10 * does not work for shared catalogs, since there is no practical way to
11 * update other databases' pg_class entries when relocating a shared catalog.
12 * Therefore, for these special catalogs (henceforth referred to as "mapped
13 * catalogs") we rely on a separately maintained file that shows the mapping
14 * from catalog OIDs to filenode numbers. Each database has a map file for
15 * its local mapped catalogs, and there is a separate map file for shared
16 * catalogs. Mapped catalogs have zero in their pg_class.relfilenode entries.
18 * Relocation of a normal table is committed (ie, the new physical file becomes
19 * authoritative) when the pg_class row update commits. For mapped catalogs,
20 * the act of updating the map file is effectively commit of the relocation.
21 * We postpone the file update till just before commit of the transaction
22 * doing the rewrite, but there is necessarily a window between. Therefore
23 * mapped catalogs can only be relocated by operations such as VACUUM FULL
24 * and CLUSTER, which make no transactionally-significant changes: it must be
25 * safe for the new file to replace the old, even if the transaction itself
26 * aborts. An important factor here is that the indexes and toast table of
27 * a mapped catalog must also be mapped, so that the rewrites/relocations of
28 * all these files commit in a single map file update rather than being tied
29 * to transaction commit.
31 * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
32 * Portions Copyright (c) 1994, Regents of the University of California
36 * src/backend/utils/cache/relmapper.c
38 *-------------------------------------------------------------------------
46 #include "access/xact.h"
47 #include "access/xlog.h"
48 #include "access/xloginsert.h"
49 #include "catalog/catalog.h"
50 #include "catalog/pg_tablespace.h"
51 #include "catalog/storage.h"
52 #include "miscadmin.h"
54 #include "storage/fd.h"
55 #include "storage/lwlock.h"
56 #include "utils/inval.h"
57 #include "utils/relmapper.h"
61 * The map file is critical data: we have no automatic method for recovering
62 * from loss or corruption of it. We use a CRC so that we can detect
63 * corruption. To minimize the risk of failed updates, the map file should
64 * be kept to no more than one standard-size disk sector (ie 512 bytes),
65 * and we use overwrite-in-place rather than playing renaming games.
66 * The struct layout below is designed to occupy exactly 512 bytes, which
67 * might make filesystem updates a bit more efficient.
69 * Entries in the mappings[] array are in no particular order. We could
70 * speed searching by insisting on OID order, but it really shouldn't be
71 * worth the trouble given the intended size of the mapping sets.
73 #define RELMAPPER_FILENAME "pg_filenode.map"
75 #define RELMAPPER_FILEMAGIC 0x592717 /* version ID value */
77 #define MAX_MAPPINGS 62 /* 62 * 8 + 16 = 512 */
79 typedef struct RelMapping
81 Oid mapoid; /* OID of a catalog */
82 Oid mapfilenode; /* its filenode number */
85 typedef struct RelMapFile
87 int32 magic; /* always RELMAPPER_FILEMAGIC */
88 int32 num_mappings; /* number of valid RelMapping entries */
89 RelMapping mappings[MAX_MAPPINGS];
90 pg_crc32c crc; /* CRC of all above */
91 int32 pad; /* to make the struct size be 512 exactly */
95 * The currently known contents of the shared map file and our database's
96 * local map file are stored here. These can be reloaded from disk
97 * immediately whenever we receive an update sinval message.
99 static RelMapFile shared_map;
100 static RelMapFile local_map;
103 * We use the same RelMapFile data structure to track uncommitted local
104 * changes in the mappings (but note the magic and crc fields are not made
105 * valid in these variables). Currently, map updates are not allowed within
106 * subtransactions, so one set of transaction-level changes is sufficient.
108 * The active_xxx variables contain updates that are valid in our transaction
109 * and should be honored by RelationMapOidToFilenode. The pending_xxx
110 * variables contain updates we have been told about that aren't active yet;
111 * they will become active at the next CommandCounterIncrement. This setup
112 * lets map updates act similarly to updates of pg_class rows, ie, they
113 * become visible only at the next CommandCounterIncrement boundary.
115 static RelMapFile active_shared_updates;
116 static RelMapFile active_local_updates;
117 static RelMapFile pending_shared_updates;
118 static RelMapFile pending_local_updates;
121 /* non-export function prototypes */
122 static void apply_map_update(RelMapFile *map, Oid relationId, Oid fileNode,
124 static void merge_map_updates(RelMapFile *map, const RelMapFile *updates,
126 static void load_relmap_file(bool shared);
127 static void write_relmap_file(bool shared, RelMapFile *newmap,
128 bool write_wal, bool send_sinval, bool preserve_files,
129 Oid dbid, Oid tsid, const char *dbpath);
130 static void perform_relmap_update(bool shared, const RelMapFile *updates);
134 * RelationMapOidToFilenode
136 * The raison d' etre ... given a relation OID, look up its filenode.
138 * Although shared and local relation OIDs should never overlap, the caller
139 * always knows which we need --- so pass that information to avoid useless
142 * Returns InvalidOid if the OID is not known (which should never happen,
143 * but the caller is in a better position to report a meaningful error).
146 RelationMapOidToFilenode(Oid relationId, bool shared)
148 const RelMapFile *map;
151 /* If there are active updates, believe those over the main maps */
154 map = &active_shared_updates;
155 for (i = 0; i < map->num_mappings; i++)
157 if (relationId == map->mappings[i].mapoid)
158 return map->mappings[i].mapfilenode;
161 for (i = 0; i < map->num_mappings; i++)
163 if (relationId == map->mappings[i].mapoid)
164 return map->mappings[i].mapfilenode;
169 map = &active_local_updates;
170 for (i = 0; i < map->num_mappings; i++)
172 if (relationId == map->mappings[i].mapoid)
173 return map->mappings[i].mapfilenode;
176 for (i = 0; i < map->num_mappings; i++)
178 if (relationId == map->mappings[i].mapoid)
179 return map->mappings[i].mapfilenode;
187 * RelationMapFilenodeToOid
189 * Do the reverse of the normal direction of mapping done in
190 * RelationMapOidToFilenode.
192 * This is not supposed to be used during normal running but rather for
193 * information purposes when looking at the filesystem or xlog.
195 * Returns InvalidOid if the OID is not known; this can easily happen if the
196 * relfilenode doesn't pertain to a mapped relation.
199 RelationMapFilenodeToOid(Oid filenode, bool shared)
201 const RelMapFile *map;
204 /* If there are active updates, believe those over the main maps */
207 map = &active_shared_updates;
208 for (i = 0; i < map->num_mappings; i++)
210 if (filenode == map->mappings[i].mapfilenode)
211 return map->mappings[i].mapoid;
214 for (i = 0; i < map->num_mappings; i++)
216 if (filenode == map->mappings[i].mapfilenode)
217 return map->mappings[i].mapoid;
222 map = &active_local_updates;
223 for (i = 0; i < map->num_mappings; i++)
225 if (filenode == map->mappings[i].mapfilenode)
226 return map->mappings[i].mapoid;
229 for (i = 0; i < map->num_mappings; i++)
231 if (filenode == map->mappings[i].mapfilenode)
232 return map->mappings[i].mapoid;
240 * RelationMapUpdateMap
242 * Install a new relfilenode mapping for the specified relation.
244 * If immediate is true (or we're bootstrapping), the mapping is activated
245 * immediately. Otherwise it is made pending until CommandCounterIncrement.
248 RelationMapUpdateMap(Oid relationId, Oid fileNode, bool shared,
253 if (IsBootstrapProcessingMode())
256 * In bootstrap mode, the mapping gets installed in permanent map.
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.
270 if (GetCurrentTransactionNestLevel() > 1)
271 elog(ERROR, "cannot change relation mapping within subtransaction");
275 /* Make it active, but only locally */
277 map = &active_shared_updates;
279 map = &active_local_updates;
283 /* Make it pending */
285 map = &pending_shared_updates;
287 map = &pending_local_updates;
290 apply_map_update(map, relationId, fileNode, true);
296 * Insert a new mapping into the given map variable, replacing any existing
297 * mapping for the same relation.
299 * In some cases the caller knows there must be an existing mapping; pass
300 * add_okay = false to draw an error if not.
303 apply_map_update(RelMapFile *map, Oid relationId, Oid fileNode, bool add_okay)
307 /* Replace any existing mapping */
308 for (i = 0; i < map->num_mappings; i++)
310 if (relationId == map->mappings[i].mapoid)
312 map->mappings[i].mapfilenode = fileNode;
317 /* Nope, need to add a new mapping */
319 elog(ERROR, "attempt to apply a mapping to unmapped relation %u",
321 if (map->num_mappings >= MAX_MAPPINGS)
322 elog(ERROR, "ran out of space in relation map");
323 map->mappings[map->num_mappings].mapoid = relationId;
324 map->mappings[map->num_mappings].mapfilenode = fileNode;
331 * Merge all the updates in the given pending-update map into the target map.
332 * This is just a bulk form of apply_map_update.
335 merge_map_updates(RelMapFile *map, const RelMapFile *updates, bool add_okay)
339 for (i = 0; i < updates->num_mappings; i++)
341 apply_map_update(map,
342 updates->mappings[i].mapoid,
343 updates->mappings[i].mapfilenode,
349 * RelationMapRemoveMapping
351 * Remove a relation's entry in the map. This is only allowed for "active"
352 * (but not committed) local mappings. We need it so we can back out the
353 * entry for the transient target file when doing VACUUM FULL/CLUSTER on
357 RelationMapRemoveMapping(Oid relationId)
359 RelMapFile *map = &active_local_updates;
362 for (i = 0; i < map->num_mappings; i++)
364 if (relationId == map->mappings[i].mapoid)
366 /* Found it, collapse it out */
367 map->mappings[i] = map->mappings[map->num_mappings - 1];
372 elog(ERROR, "could not find temporary mapping for relation %u",
377 * RelationMapInvalidate
379 * This routine is invoked for SI cache flush messages. We must re-read
380 * the indicated map file. However, we might receive a SI message in a
381 * process that hasn't yet, and might never, load the mapping files;
382 * for example the autovacuum launcher, which *must not* try to read
383 * a local map since it is attached to no particular database.
384 * So, re-read only if the map is valid now.
387 RelationMapInvalidate(bool shared)
391 if (shared_map.magic == RELMAPPER_FILEMAGIC)
392 load_relmap_file(true);
396 if (local_map.magic == RELMAPPER_FILEMAGIC)
397 load_relmap_file(false);
402 * RelationMapInvalidateAll
404 * Reload all map files. This is used to recover from SI message buffer
405 * overflow: we can't be sure if we missed an inval message.
406 * Again, reload only currently-valid maps.
409 RelationMapInvalidateAll(void)
411 if (shared_map.magic == RELMAPPER_FILEMAGIC)
412 load_relmap_file(true);
413 if (local_map.magic == RELMAPPER_FILEMAGIC)
414 load_relmap_file(false);
420 * Activate any "pending" relation map updates at CommandCounterIncrement time.
423 AtCCI_RelationMap(void)
425 if (pending_shared_updates.num_mappings != 0)
427 merge_map_updates(&active_shared_updates,
428 &pending_shared_updates,
430 pending_shared_updates.num_mappings = 0;
432 if (pending_local_updates.num_mappings != 0)
434 merge_map_updates(&active_local_updates,
435 &pending_local_updates,
437 pending_local_updates.num_mappings = 0;
442 * AtEOXact_RelationMap
444 * Handle relation mapping at main-transaction commit or abort.
446 * During commit, this must be called as late as possible before the actual
447 * transaction commit, so as to minimize the window where the transaction
448 * could still roll back after committing map changes. Although nothing
449 * critically bad happens in such a case, we still would prefer that it
450 * not happen, since we'd possibly be losing useful updates to the relations'
453 * During abort, we just have to throw away any pending map changes.
454 * Normal post-abort cleanup will take care of fixing relcache entries.
457 AtEOXact_RelationMap(bool isCommit)
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.)
466 Assert(pending_shared_updates.num_mappings == 0);
467 Assert(pending_local_updates.num_mappings == 0);
470 * Write any active updates to the actual map files, then reset them.
472 if (active_shared_updates.num_mappings != 0)
474 perform_relmap_update(true, &active_shared_updates);
475 active_shared_updates.num_mappings = 0;
477 if (active_local_updates.num_mappings != 0)
479 perform_relmap_update(false, &active_local_updates);
480 active_local_updates.num_mappings = 0;
485 /* Abort --- drop all local and pending updates */
486 active_shared_updates.num_mappings = 0;
487 active_local_updates.num_mappings = 0;
488 pending_shared_updates.num_mappings = 0;
489 pending_local_updates.num_mappings = 0;
494 * AtPrepare_RelationMap
496 * Handle relation mapping at PREPARE.
498 * Currently, we don't support preparing any transaction that changes the map.
501 AtPrepare_RelationMap(void)
503 if (active_shared_updates.num_mappings != 0 ||
504 active_local_updates.num_mappings != 0 ||
505 pending_shared_updates.num_mappings != 0 ||
506 pending_local_updates.num_mappings != 0)
508 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
509 errmsg("cannot PREPARE a transaction that modified relation mapping")));
513 * CheckPointRelationMap
515 * This is called during a checkpoint. It must ensure that any relation map
516 * updates that were WAL-logged before the start of the checkpoint are
517 * securely flushed to disk and will not need to be replayed later. This
518 * seems unlikely to be a performance-critical issue, so we use a simple
519 * method: we just take and release the RelationMappingLock. This ensures
520 * that any already-logged map update is complete, because write_relmap_file
521 * will fsync the map file before the lock is released.
524 CheckPointRelationMap(void)
526 LWLockAcquire(RelationMappingLock, LW_SHARED);
527 LWLockRelease(RelationMappingLock);
531 * RelationMapFinishBootstrap
533 * Write out the initial relation mapping files at the completion of
534 * bootstrap. All the mapped files should have been made known to us
535 * via RelationMapUpdateMap calls.
538 RelationMapFinishBootstrap(void)
540 Assert(IsBootstrapProcessingMode());
542 /* Shouldn't be anything "pending" ... */
543 Assert(active_shared_updates.num_mappings == 0);
544 Assert(active_local_updates.num_mappings == 0);
545 Assert(pending_shared_updates.num_mappings == 0);
546 Assert(pending_local_updates.num_mappings == 0);
548 /* Write the files; no WAL or sinval needed */
549 write_relmap_file(true, &shared_map, false, false, false,
550 InvalidOid, GLOBALTABLESPACE_OID, NULL);
551 write_relmap_file(false, &local_map, false, false, false,
552 MyDatabaseId, MyDatabaseTableSpace, DatabasePath);
556 * RelationMapInitialize
558 * This initializes the mapper module at process startup. We can't access the
559 * database yet, so just make sure the maps are empty.
562 RelationMapInitialize(void)
564 /* The static variables should initialize to zeroes, but let's be sure */
565 shared_map.magic = 0; /* mark it not loaded */
567 shared_map.num_mappings = 0;
568 local_map.num_mappings = 0;
569 active_shared_updates.num_mappings = 0;
570 active_local_updates.num_mappings = 0;
571 pending_shared_updates.num_mappings = 0;
572 pending_local_updates.num_mappings = 0;
576 * RelationMapInitializePhase2
578 * This is called to prepare for access to pg_database during startup.
579 * We should be able to read the shared map file now.
582 RelationMapInitializePhase2(void)
585 * In bootstrap mode, the map file isn't there yet, so do nothing.
587 if (IsBootstrapProcessingMode())
591 * Load the shared map file, die on error.
593 load_relmap_file(true);
597 * RelationMapInitializePhase3
599 * This is called as soon as we have determined MyDatabaseId and set up
600 * DatabasePath. At this point we should be able to read the local map file.
603 RelationMapInitializePhase3(void)
606 * In bootstrap mode, the map file isn't there yet, so do nothing.
608 if (IsBootstrapProcessingMode())
612 * Load the local map file, die on error.
614 load_relmap_file(false);
618 * load_relmap_file -- load data from the shared or local map file
620 * Because the map file is essential for access to core system catalogs,
621 * failure to read it is a fatal error.
623 * Note that the local case requires DatabasePath to be set up.
626 load_relmap_file(bool shared)
629 char mapfilename[MAXPGPATH];
636 snprintf(mapfilename, sizeof(mapfilename), "global/%s",
642 snprintf(mapfilename, sizeof(mapfilename), "%s/%s",
643 DatabasePath, RELMAPPER_FILENAME);
648 fd = OpenTransientFile(mapfilename, O_RDONLY | PG_BINARY);
651 (errcode_for_file_access(),
652 errmsg("could not open file \"%s\": %m",
656 * Note: we could take RelationMappingLock in shared mode here, but it
657 * seems unnecessary since our read() should be atomic against any
658 * concurrent updater's write(). If the file is updated shortly after we
659 * look, the sinval signaling mechanism will make us re-read it before we
660 * are able to access any relation that's affected by the change.
662 pgstat_report_wait_start(WAIT_EVENT_RELATION_MAP_READ);
663 r = read(fd, map, sizeof(RelMapFile));
664 if (r != sizeof(RelMapFile))
668 (errcode_for_file_access(),
669 errmsg("could not read file \"%s\": %m", mapfilename)));
672 (errcode(ERRCODE_DATA_CORRUPTED),
673 errmsg("could not read file \"%s\": read %d of %zu",
674 mapfilename, r, sizeof(RelMapFile))));
676 pgstat_report_wait_end();
678 CloseTransientFile(fd);
680 /* check for correct magic number, etc */
681 if (map->magic != RELMAPPER_FILEMAGIC ||
682 map->num_mappings < 0 ||
683 map->num_mappings > MAX_MAPPINGS)
685 (errmsg("relation mapping file \"%s\" contains invalid data",
690 COMP_CRC32C(crc, (char *) map, offsetof(RelMapFile, crc));
693 if (!EQ_CRC32C(crc, map->crc))
695 (errmsg("relation mapping file \"%s\" contains incorrect checksum",
700 * Write out a new shared or local map file with the given contents.
702 * The magic number and CRC are automatically updated in *newmap. On
703 * success, we copy the data to the appropriate permanent static variable.
705 * If write_wal is true then an appropriate WAL message is emitted.
706 * (It will be false for bootstrap and WAL replay cases.)
708 * If send_sinval is true then a SI invalidation message is sent.
709 * (This should be true except in bootstrap case.)
711 * If preserve_files is true then the storage manager is warned not to
712 * delete the files listed in the map.
714 * Because this may be called during WAL replay when MyDatabaseId,
715 * DatabasePath, etc aren't valid, we require the caller to pass in suitable
716 * values. The caller is also responsible for being sure no concurrent
717 * map update could be happening.
720 write_relmap_file(bool shared, RelMapFile *newmap,
721 bool write_wal, bool send_sinval, bool preserve_files,
722 Oid dbid, Oid tsid, const char *dbpath)
726 char mapfilename[MAXPGPATH];
729 * Fill in the overhead fields and update CRC.
731 newmap->magic = RELMAPPER_FILEMAGIC;
732 if (newmap->num_mappings < 0 || newmap->num_mappings > MAX_MAPPINGS)
733 elog(ERROR, "attempt to write bogus relation mapping");
735 INIT_CRC32C(newmap->crc);
736 COMP_CRC32C(newmap->crc, (char *) newmap, offsetof(RelMapFile, crc));
737 FIN_CRC32C(newmap->crc);
740 * Open the target file. We prefer to do this before entering the
741 * critical section, so that an open() failure need not force PANIC.
745 snprintf(mapfilename, sizeof(mapfilename), "global/%s",
747 realmap = &shared_map;
751 snprintf(mapfilename, sizeof(mapfilename), "%s/%s",
752 dbpath, RELMAPPER_FILENAME);
753 realmap = &local_map;
756 fd = OpenTransientFile(mapfilename, O_WRONLY | O_CREAT | PG_BINARY);
759 (errcode_for_file_access(),
760 errmsg("could not open file \"%s\": %m",
765 xl_relmap_update xlrec;
768 /* now errors are fatal ... */
769 START_CRIT_SECTION();
773 xlrec.nbytes = sizeof(RelMapFile);
776 XLogRegisterData((char *) (&xlrec), MinSizeOfRelmapUpdate);
777 XLogRegisterData((char *) newmap, sizeof(RelMapFile));
779 lsn = XLogInsert(RM_RELMAP_ID, XLOG_RELMAP_UPDATE);
781 /* As always, WAL must hit the disk before the data update does */
786 pgstat_report_wait_start(WAIT_EVENT_RELATION_MAP_WRITE);
787 if (write(fd, newmap, sizeof(RelMapFile)) != sizeof(RelMapFile))
789 /* if write didn't set errno, assume problem is no disk space */
793 (errcode_for_file_access(),
794 errmsg("could not write file \"%s\": %m",
797 pgstat_report_wait_end();
800 * We choose to fsync the data to disk before considering the task done.
801 * It would be possible to relax this if it turns out to be a performance
802 * issue, but it would complicate checkpointing --- see notes for
803 * CheckPointRelationMap.
805 pgstat_report_wait_start(WAIT_EVENT_RELATION_MAP_SYNC);
806 if (pg_fsync(fd) != 0)
808 (errcode_for_file_access(),
809 errmsg("could not fsync file \"%s\": %m",
811 pgstat_report_wait_end();
813 if (CloseTransientFile(fd))
815 (errcode_for_file_access(),
816 errmsg("could not close file \"%s\": %m",
820 * Now that the file is safely on disk, send sinval message to let other
821 * backends know to re-read it. We must do this inside the critical
822 * section: if for some reason we fail to send the message, we have to
823 * force a database-wide PANIC. Otherwise other backends might continue
824 * execution with stale mapping information, which would be catastrophic
825 * as soon as others began to use the now-committed data.
828 CacheInvalidateRelmap(dbid);
831 * Make sure that the files listed in the map are not deleted if the outer
832 * transaction aborts. This had better be within the critical section
833 * too: it's not likely to fail, but if it did, we'd arrive at transaction
834 * abort with the files still vulnerable. PANICing will leave things in a
835 * good state on-disk.
837 * Note: we're cheating a little bit here by assuming that mapped files
838 * are either in pg_global or the database's default tablespace.
844 for (i = 0; i < newmap->num_mappings; i++)
848 rnode.spcNode = tsid;
850 rnode.relNode = newmap->mappings[i].mapfilenode;
851 RelationPreserveStorage(rnode, false);
855 /* Success, update permanent copy */
856 memcpy(realmap, newmap, sizeof(RelMapFile));
858 /* Critical section done */
864 * Merge the specified updates into the appropriate "real" map,
865 * and write out the changes. This function must be used for committing
866 * updates during normal multiuser operation.
869 perform_relmap_update(bool shared, const RelMapFile *updates)
874 * Anyone updating a relation's mapping info should take exclusive lock on
875 * that rel and hold it until commit. This ensures that there will not be
876 * concurrent updates on the same mapping value; but there could easily be
877 * concurrent updates on different values in the same file. We cover that
878 * by acquiring the RelationMappingLock, re-reading the target file to
879 * ensure it's up to date, applying the updates, and writing the data
880 * before releasing RelationMappingLock.
882 * There is only one RelationMappingLock. In principle we could try to
883 * have one per mapping file, but it seems unlikely to be worth the
886 LWLockAcquire(RelationMappingLock, LW_EXCLUSIVE);
888 /* Be certain we see any other updates just made */
889 load_relmap_file(shared);
891 /* Prepare updated data in a local variable */
893 memcpy(&newmap, &shared_map, sizeof(RelMapFile));
895 memcpy(&newmap, &local_map, sizeof(RelMapFile));
898 * Apply the updates to newmap. No new mappings should appear, unless
899 * somebody is adding indexes to system catalogs.
901 merge_map_updates(&newmap, updates, allowSystemTableMods);
903 /* Write out the updated map and do other necessary tasks */
904 write_relmap_file(shared, &newmap, true, true, true,
905 (shared ? InvalidOid : MyDatabaseId),
906 (shared ? GLOBALTABLESPACE_OID : MyDatabaseTableSpace),
909 /* Now we can release the lock */
910 LWLockRelease(RelationMappingLock);
914 * RELMAP resource manager's routines
917 relmap_redo(XLogReaderState *record)
919 uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
921 /* Backup blocks are not used in relmap records */
922 Assert(!XLogRecHasAnyBlockRefs(record));
924 if (info == XLOG_RELMAP_UPDATE)
926 xl_relmap_update *xlrec = (xl_relmap_update *) XLogRecGetData(record);
930 if (xlrec->nbytes != sizeof(RelMapFile))
931 elog(PANIC, "relmap_redo: wrong size %u in relmap update record",
933 memcpy(&newmap, xlrec->data, sizeof(newmap));
935 /* We need to construct the pathname for this database */
936 dbpath = GetDatabasePath(xlrec->dbid, xlrec->tsid);
939 * Write out the new map and send sinval, but of course don't write a
940 * new WAL entry. There's no surrounding transaction to tell to
941 * preserve files, either.
943 * There shouldn't be anyone else updating relmaps during WAL replay,
944 * so we don't bother to take the RelationMappingLock. We would need
945 * to do so if load_relmap_file needed to interlock against writers.
947 write_relmap_file((xlrec->dbid == InvalidOid), &newmap,
949 xlrec->dbid, xlrec->tsid, dbpath);
954 elog(PANIC, "relmap_redo: unknown op code %u", info);