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

Function load_relmap_file

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

* load_relmap_file -- load data from the shared or local map file * * Because the map file is essential for access to core system catalogs, * failure to read it is a fatal error. * * Note that the local case requires DatabasePath to be set up. */

Source from the content-addressed store, hash-verified

702 * Note that the local case requires DatabasePath to be set up.
703 */
704static void
705load_relmap_file(bool shared, bool lock_held)
706{
707 RelMapFile *map;
708 char mapfilename[MAXPGPATH];
709 pg_crc32c crc;
710 int fd;
711 int r;
712
713 if (shared)
714 {
715 snprintf(mapfilename, sizeof(mapfilename), "global/%s",
716 RELMAPPER_FILENAME);
717 map = &shared_map;
718 }
719 else
720 {
721 snprintf(mapfilename, sizeof(mapfilename), "%s/%s",
722 DatabasePath, RELMAPPER_FILENAME);
723 map = &local_map;
724 }
725
726 /* Read data ... */
727 fd = OpenTransientFile(mapfilename, O_RDONLY | PG_BINARY);
728 if (fd < 0)
729 ereport(FATAL,
730 (errcode_for_file_access(),
731 errmsg("could not open file \"%s\": %m",
732 mapfilename)));
733
734 /*
735 * Grab the lock to prevent the file from being updated while we read it,
736 * unless the caller is already holding the lock. If the file is updated
737 * shortly after we look, the sinval signaling mechanism will make us
738 * re-read it before we are able to access any relation that's affected by
739 * the change.
740 */
741 if (!lock_held)
742 LWLockAcquire(RelationMappingLock, LW_SHARED);
743
744 pgstat_report_wait_start(WAIT_EVENT_RELATION_MAP_READ);
745 r = read(fd, map, sizeof(RelMapFile));
746 if (r != sizeof(RelMapFile))
747 {
748 if (r < 0)
749 ereport(FATAL,
750 (errcode_for_file_access(),
751 errmsg("could not read file \"%s\": %m", mapfilename)));
752 else
753 ereport(FATAL,
754 (errcode(ERRCODE_DATA_CORRUPTED),
755 errmsg("could not read file \"%s\": read %d of %zu",
756 mapfilename, r, sizeof(RelMapFile))));
757 }
758 pgstat_report_wait_end();
759
760 if (!lock_held)
761 LWLockRelease(RelationMappingLock);

Callers 5

RelationMapInvalidateFunction · 0.85
RelationMapInvalidateAllFunction · 0.85
perform_relmap_updateFunction · 0.85

Calls 9

OpenTransientFileFunction · 0.85
LWLockAcquireFunction · 0.85
pgstat_report_wait_startFunction · 0.85
pgstat_report_wait_endFunction · 0.85
LWLockReleaseFunction · 0.85
CloseTransientFileFunction · 0.85
errcode_for_file_accessFunction · 0.50
errmsgFunction · 0.50
errcodeFunction · 0.50

Tested by

no test coverage detected