Use XLOG_CONTROL_FILE macro consistently for control file name.
authorFujii Masao <[email protected]>
Mon, 7 Apr 2025 00:27:33 +0000 (09:27 +0900)
committerFujii Masao <[email protected]>
Mon, 7 Apr 2025 00:27:33 +0000 (09:27 +0900)
The XLOG_CONTROL_FILE macro (defined in access/xlog_internal.h)
represents the control file name. While some parts of the codebase already
use this macro, others previously hardcoded the file name as a string.

This commit replaces those hardcoded strings with the macro,
ensuring consistent usage throughout the code. This makes future
maintenance easier and improves searchability, for example when
grepping for control file usage.

Author: Anton A. Melnikov <[email protected]>
Reviewed-by: Daniel Gustafsson <[email protected]>
Reviewed-by: Kyotaro Horiguchi <[email protected]>
Reviewed-by: Masao Fujii <[email protected]>
Discussion: https://postgr.es/m/0841ec77-47e5-452a-adb4-c6fa55d605fc@postgrespro.ru

src/backend/backup/basebackup.c
src/backend/postmaster/postmaster.c
src/bin/pg_combinebackup/pg_combinebackup.c
src/bin/pg_controldata/pg_controldata.c
src/bin/pg_rewind/filemap.c
src/bin/pg_rewind/pg_rewind.c
src/bin/pg_upgrade/controldata.c
src/bin/pg_verifybackup/astreamer_verify.c
src/bin/pg_verifybackup/pg_verifybackup.c
src/common/controldata_utils.c

index 891637e3a4495d2b2bfaf6b8dbcd2882906b9376..f0f88838dc21aa3d7e906176ef50ca6d0cef4114 100644 (file)
@@ -1349,7 +1349,7 @@ sendDir(bbsink *sink, const char *path, int basepathlen, bool sizeonly,
        snprintf(pathbuf, sizeof(pathbuf), "%s/%s", path, de->d_name);
 
        /* Skip pg_control here to back up it last */
-       if (strcmp(pathbuf, "./global/pg_control") == 0)
+       if (strcmp(pathbuf, "./" XLOG_CONTROL_FILE) == 0)
            continue;
 
        if (lstat(pathbuf, &statbuf) != 0)
index 3fe45de5da0e96589c2c98b8716267df5301721b..17fed96fe20c93943acf208c659e20a48d160bd8 100644 (file)
@@ -90,6 +90,7 @@
 #endif
 
 #include "access/xlog.h"
+#include "access/xlog_internal.h"
 #include "access/xlogrecovery.h"
 #include "common/file_perm.h"
 #include "common/pg_prng.h"
@@ -1516,7 +1517,7 @@ checkControlFile(void)
    char        path[MAXPGPATH];
    FILE       *fp;
 
-   snprintf(path, sizeof(path), "%s/global/pg_control", DataDir);
+   snprintf(path, sizeof(path), "%s/%s", DataDir, XLOG_CONTROL_FILE);
 
    fp = AllocateFile(path, PG_BINARY_R);
    if (fp == NULL)
index d61bde42f498b9ca8d472d082cdca22da2734eb8..4f8ba156336425c084d8fb04e8010e52d83cd1be 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/fs.h>
 #endif
 
+#include "access/xlog_internal.h"
 #include "backup_label.h"
 #include "common/checksum_helper.h"
 #include "common/controldata_utils.h"
@@ -300,7 +301,7 @@ main(int argc, char *argv[])
        {
            char       *controlpath;
 
-           controlpath = psprintf("%s/%s", prior_backup_dirs[i], "global/pg_control");
+           controlpath = psprintf("%s/%s", prior_backup_dirs[i], XLOG_CONTROL_FILE);
 
            pg_fatal("%s: manifest system identifier is %" PRIu64 ", but control file has %" PRIu64,
                     controlpath,
@@ -614,7 +615,7 @@ check_control_files(int n_backups, char **backup_dirs)
        bool        crc_ok;
        char       *controlpath;
 
-       controlpath = psprintf("%s/%s", backup_dirs[i], "global/pg_control");
+       controlpath = psprintf("%s/%s", backup_dirs[i], XLOG_CONTROL_FILE);
        pg_log_debug("reading \"%s\"", controlpath);
        control_file = get_controlfile_by_exact_path(controlpath, &crc_ok);
 
index 9901a2bae51c93ebf766ee6abe623bfb05dcad25..7bb801bb886123c4d79a4789bbb8ff865c6de5d8 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * pg_controldata
  *
- * reads the data from $PGDATA/global/pg_control
+ * reads the data from the control file located at $PGDATA/XLOG_CONTROL_FILE.
  *
  * copyright (c) Oliver Elphick <[email protected]>, 2001;
  * license: BSD
index a28d1667d4c8c5696a7cd183635b090bd5e1ca9b..c933871ca9fda2f8f4881f435181039e8cbb0c4d 100644 (file)
@@ -26,6 +26,7 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
+#include "access/xlog_internal.h"
 #include "catalog/pg_tablespace_d.h"
 #include "common/file_utils.h"
 #include "common/hashfn_unstable.h"
@@ -704,7 +705,7 @@ decide_file_action(file_entry_t *entry)
     * Don't touch the control file. It is handled specially, after copying
     * all the other files.
     */
-   if (strcmp(path, "global/pg_control") == 0)
+   if (strcmp(path, XLOG_CONTROL_FILE) == 0)
        return FILE_ACTION_NONE;
 
    /* Skip macOS system files */
index 2c8b1a070077f86af9b7349e657a238eda9dcbdb..9d16c1e6b475735f2a3fc62746d818d05c842e5e 100644 (file)
@@ -328,7 +328,7 @@ main(int argc, char **argv)
     * need to make sure by themselves that the target cluster is in a clean
     * state.
     */
-   buffer = slurpFile(datadir_target, "global/pg_control", &size);
+   buffer = slurpFile(datadir_target, XLOG_CONTROL_FILE, &size);
    digestControlFile(&ControlFile_target, buffer, size);
    pg_free(buffer);
 
@@ -338,12 +338,12 @@ main(int argc, char **argv)
    {
        ensureCleanShutdown(argv[0]);
 
-       buffer = slurpFile(datadir_target, "global/pg_control", &size);
+       buffer = slurpFile(datadir_target, XLOG_CONTROL_FILE, &size);
        digestControlFile(&ControlFile_target, buffer, size);
        pg_free(buffer);
    }
 
-   buffer = source->fetch_file(source, "global/pg_control", &size);
+   buffer = source->fetch_file(source, XLOG_CONTROL_FILE, &size);
    digestControlFile(&ControlFile_source, buffer, size);
    pg_free(buffer);
 
@@ -636,7 +636,7 @@ perform_rewind(filemap_t *filemap, rewind_source *source,
     * Fetch the control file from the source last. This ensures that the
     * minRecoveryPoint is up-to-date.
     */
-   buffer = source->fetch_file(source, "global/pg_control", &size);
+   buffer = source->fetch_file(source, XLOG_CONTROL_FILE, &size);
    digestControlFile(&ControlFile_source_after, buffer, size);
    pg_free(buffer);
 
index 47ee27ec83549ce359315b3d2b8f044179e8f3f1..8b7c349a87517d4df82373a0ef41ba37fb8f1ea4 100644 (file)
@@ -12,6 +12,7 @@
 #include <ctype.h>
 #include <limits.h>                /* for CHAR_MIN */
 
+#include "access/xlog_internal.h"
 #include "common/string.h"
 #include "pg_upgrade.h"
 
@@ -757,10 +758,10 @@ disable_old_cluster(transferMode transfer_mode)
                new_path[MAXPGPATH];
 
    /* rename pg_control so old server cannot be accidentally started */
-   prep_status("Adding \".old\" suffix to old global/pg_control");
+   prep_status("Adding \".old\" suffix to old " XLOG_CONTROL_FILE);
 
-   snprintf(old_path, sizeof(old_path), "%s/global/pg_control", old_cluster.pgdata);
-   snprintf(new_path, sizeof(new_path), "%s/global/pg_control.old", old_cluster.pgdata);
+   snprintf(old_path, sizeof(old_path), "%s/%s", old_cluster.pgdata, XLOG_CONTROL_FILE);
+   snprintf(new_path, sizeof(new_path), "%s/%s.old", old_cluster.pgdata, XLOG_CONTROL_FILE);
    if (pg_mv_file(old_path, new_path) != 0)
        pg_fatal("could not rename file \"%s\" to \"%s\": %m",
                 old_path, new_path);
@@ -769,10 +770,10 @@ disable_old_cluster(transferMode transfer_mode)
    if (transfer_mode == TRANSFER_MODE_LINK)
        pg_log(PG_REPORT, "\n"
               "If you want to start the old cluster, you will need to remove\n"
-              "the \".old\" suffix from %s/global/pg_control.old.\n"
+              "the \".old\" suffix from %s/%s.old.\n"
               "Because \"link\" mode was used, the old cluster cannot be safely\n"
               "started once the new cluster has been started.",
-              old_cluster.pgdata);
+              old_cluster.pgdata, XLOG_CONTROL_FILE);
    else if (transfer_mode == TRANSFER_MODE_SWAP)
        pg_log(PG_REPORT, "\n"
               "Because \"swap\" mode was used, the old cluster can no longer be\n"
index 079c3970410ab204a308168f48ff09e7e6e485c1..268c5f0e24635716f6b26e7286e7cfcb6c8eb2a6 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "postgres_fe.h"
 
+#include "access/xlog_internal.h"
 #include "catalog/pg_control.h"
 #include "pg_verifybackup.h"
 
@@ -225,7 +226,7 @@ member_verify_header(astreamer *streamer, astreamer_member *member)
        (!mystreamer->context->skip_checksums && should_verify_checksum(m));
    mystreamer->verify_control_data =
        mystreamer->context->manifest->version != 1 &&
-       !m->bad && strcmp(m->pathname, "global/pg_control") == 0;
+       !m->bad && strcmp(m->pathname, XLOG_CONTROL_FILE) == 0;
 
    /* If we're going to verify the checksum, initial a checksum context. */
    if (mystreamer->verify_checksum &&
@@ -370,7 +371,7 @@ member_verify_control_data(astreamer *streamer)
    pg_crc32c   crc;
 
    /* Should be here only for control file */
-   Assert(strcmp(mystreamer->mfile->pathname, "global/pg_control") == 0);
+   Assert(strcmp(mystreamer->mfile->pathname, XLOG_CONTROL_FILE) == 0);
    Assert(mystreamer->verify_control_data);
 
    /*
index 383668a8b6a50edf20fdeeec2fd87dce3e18b419..3ce233f3c20f4918ddd43ae7d6d9b46f8772a4e4 100644 (file)
@@ -18,6 +18,7 @@
 #include <sys/stat.h>
 #include <time.h>
 
+#include "access/xlog_internal.h"
 #include "common/logging.h"
 #include "common/parse_manifest.h"
 #include "fe_utils/simple_list.h"
@@ -730,7 +731,7 @@ verify_plain_backup_file(verifier_context *context, char *relpath,
     * version 1.
     */
    if (context->manifest->version != 1 &&
-       strcmp(relpath, "global/pg_control") == 0)
+       strcmp(relpath, XLOG_CONTROL_FILE) == 0)
        verify_control_file(fullpath, context->manifest->system_identifier);
 
    /* Update statistics for progress report, if necessary */
index 34d8a3a4e310bb009d9bb337b592c34278cdd4fd..fa375dc91293b9b7f4c0ae03fa47aa0625fc4b58 100644 (file)
@@ -53,7 +53,7 @@ get_controlfile(const char *DataDir, bool *crc_ok_p)
 {
    char        ControlFilePath[MAXPGPATH];
 
-   snprintf(ControlFilePath, MAXPGPATH, "%s/global/pg_control", DataDir);
+   snprintf(ControlFilePath, MAXPGPATH, "%s/%s", DataDir, XLOG_CONTROL_FILE);
 
    return get_controlfile_by_exact_path(ControlFilePath, crc_ok_p);
 }