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

Function ReadControlFile

src/backend/access/transam/xlog.c:4835–5045  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4833}
4834
4835static void
4836ReadControlFile(void)
4837{
4838 pg_crc32c crc;
4839 int fd;
4840 static char wal_segsz_str[20];
4841 int r;
4842
4843 /*
4844 * Read data...
4845 */
4846 fd = BasicOpenFile(XLOG_CONTROL_FILE,
4847 O_RDWR | PG_BINARY);
4848 if (fd < 0)
4849 ereport(PANIC,
4850 (errcode_for_file_access(),
4851 errmsg("could not open file \"%s\": %m",
4852 XLOG_CONTROL_FILE)));
4853
4854 pgstat_report_wait_start(WAIT_EVENT_CONTROL_FILE_READ);
4855 r = read(fd, ControlFile, sizeof(ControlFileData));
4856 if (r != sizeof(ControlFileData))
4857 {
4858 if (r < 0)
4859 ereport(PANIC,
4860 (errcode_for_file_access(),
4861 errmsg("could not read file \"%s\": %m",
4862 XLOG_CONTROL_FILE)));
4863 else
4864 ereport(PANIC,
4865 (errcode(ERRCODE_DATA_CORRUPTED),
4866 errmsg("could not read file \"%s\": read %d of %zu",
4867 XLOG_CONTROL_FILE, r, sizeof(ControlFileData))));
4868 }
4869 pgstat_report_wait_end();
4870
4871 close(fd);
4872
4873 /*
4874 * Check for expected pg_control format version. If this is wrong, the
4875 * CRC check will likely fail because we'll be checking the wrong number
4876 * of bytes. Complaining about wrong version will probably be more
4877 * enlightening than complaining about wrong CRC.
4878 */
4879
4880 if (ControlFile->pg_control_version != PG_CONTROL_VERSION && ControlFile->pg_control_version % 65536 == 0 && ControlFile->pg_control_version / 65536 != 0)
4881 ereport(FATAL,
4882 (errmsg("database files are incompatible with server"),
4883 errdetail("The database cluster was initialized with PG_CONTROL_VERSION %d (0x%08x),"
4884 " but the server was compiled with PG_CONTROL_VERSION %d (0x%08x).",
4885 ControlFile->pg_control_version, ControlFile->pg_control_version,
4886 PG_CONTROL_VERSION, PG_CONTROL_VERSION),
4887 errhint("This could be a problem of mismatched byte ordering. It looks like you need to initdb.")));
4888
4889 if (ControlFile->pg_control_version != PG_CONTROL_VERSION)
4890 ereport(FATAL,
4891 (errmsg("database files are incompatible with server"),
4892 errdetail("The database cluster was initialized with PG_CONTROL_VERSION %d,"

Callers 2

LocalProcessControlFileFunction · 0.85
BootStrapXLOGFunction · 0.85

Calls 12

BasicOpenFileFunction · 0.85
pgstat_report_wait_startFunction · 0.85
pgstat_report_wait_endFunction · 0.85
SetConfigOptionFunction · 0.85
DataChecksumsEnabledFunction · 0.85
errcode_for_file_accessFunction · 0.50
errmsgFunction · 0.50
errcodeFunction · 0.50
errdetailFunction · 0.50
errhintFunction · 0.50
errmsg_pluralFunction · 0.50

Tested by

no test coverage detected