MCPcopy Create free account
hub / github.com/apache/cloudberry / write_relmap_file

Function write_relmap_file

src/backend/utils/cache/relmapper.c:808–957  ·  view source on GitHub ↗

* Write out a new shared or local map file with the given contents. * * The magic number and CRC are automatically updated in *newmap. On * success, we copy the data to the appropriate permanent static variable. * * If write_wal is true then an appropriate WAL message is emitted. * (It will be false for bootstrap and WAL replay cases.) * * If send_sinval is true then a SI invalidation mes

Source from the content-addressed store, hash-verified

806 * map update could be happening.
807 */
808static void
809write_relmap_file(bool shared, RelMapFile *newmap,
810 bool write_wal, bool send_sinval, bool preserve_files,
811 Oid dbid, Oid tsid, const char *dbpath)
812{
813 int fd;
814 RelMapFile *realmap;
815 char mapfilename[MAXPGPATH];
816
817 /*
818 * Fill in the overhead fields and update CRC.
819 */
820 newmap->magic = RELMAPPER_FILEMAGIC;
821 if (newmap->num_mappings < 0 || newmap->num_mappings > MAX_MAPPINGS)
822 elog(ERROR, "attempt to write bogus relation mapping");
823
824 INIT_CRC32C(newmap->crc);
825 COMP_CRC32C(newmap->crc, (char *) newmap, offsetof(RelMapFile, crc));
826 FIN_CRC32C(newmap->crc);
827
828 /*
829 * Open the target file. We prefer to do this before entering the
830 * critical section, so that an open() failure need not force PANIC.
831 */
832 if (shared)
833 {
834 snprintf(mapfilename, sizeof(mapfilename), "global/%s",
835 RELMAPPER_FILENAME);
836 realmap = &shared_map;
837 }
838 else
839 {
840 snprintf(mapfilename, sizeof(mapfilename), "%s/%s",
841 dbpath, RELMAPPER_FILENAME);
842 realmap = &local_map;
843 }
844
845 fd = OpenTransientFile(mapfilename, O_WRONLY | O_CREAT | PG_BINARY);
846 if (fd < 0)
847 ereport(ERROR,
848 (errcode_for_file_access(),
849 errmsg("could not open file \"%s\": %m",
850 mapfilename)));
851
852 if (write_wal)
853 {
854 xl_relmap_update xlrec;
855 XLogRecPtr lsn;
856
857 /* now errors are fatal ... */
858 START_CRIT_SECTION();
859
860 xlrec.dbid = dbid;
861 xlrec.tsid = tsid;
862 xlrec.nbytes = sizeof(RelMapFile);
863
864 XLogBeginInsert();
865 XLogRegisterData((char *) (&xlrec), MinSizeOfRelmapUpdate);

Callers 3

perform_relmap_updateFunction · 0.85
relmap_redoFunction · 0.85

Calls 14

OpenTransientFileFunction · 0.85
XLogBeginInsertFunction · 0.85
XLogRegisterDataFunction · 0.85
XLogInsertFunction · 0.85
XLogFlushFunction · 0.85
pgstat_report_wait_startFunction · 0.85
pgstat_report_wait_endFunction · 0.85
pg_fsyncFunction · 0.85
data_sync_elevelFunction · 0.85
CloseTransientFileFunction · 0.85
CacheInvalidateRelmapFunction · 0.85
RelationPreserveStorageFunction · 0.85

Tested by

no test coverage detected