Skip to content

Commit 173c978

Browse files
committed
Use XLOG_CONTROL_FILE macro consistently for control file name.
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 <a.melnikov@postgrespro.ru> Reviewed-by: Daniel Gustafsson <daniel@yesql.se> Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com> Reviewed-by: Masao Fujii <masao.fujii@gmail.com> Discussion: https://postgr.es/m/0841ec77-47e5-452a-adb4-c6fa55d605fc@postgrespro.ru
1 parent a233a60 commit 173c978

File tree

10 files changed

+25
-19
lines changed

10 files changed

+25
-19
lines changed

src/backend/backup/basebackup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,7 @@ sendDir(bbsink *sink, const char *path, int basepathlen, bool sizeonly,
13491349
snprintf(pathbuf, sizeof(pathbuf), "%s/%s", path, de->d_name);
13501350

13511351
/* Skip pg_control here to back up it last */
1352-
if (strcmp(pathbuf, "./global/pg_control") == 0)
1352+
if (strcmp(pathbuf, "./" XLOG_CONTROL_FILE) == 0)
13531353
continue;
13541354

13551355
if (lstat(pathbuf, &statbuf) != 0)

src/backend/postmaster/postmaster.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
#endif
9191

9292
#include "access/xlog.h"
93+
#include "access/xlog_internal.h"
9394
#include "access/xlogrecovery.h"
9495
#include "common/file_perm.h"
9596
#include "common/pg_prng.h"
@@ -1516,7 +1517,7 @@ checkControlFile(void)
15161517
char path[MAXPGPATH];
15171518
FILE *fp;
15181519

1519-
snprintf(path, sizeof(path), "%s/global/pg_control", DataDir);
1520+
snprintf(path, sizeof(path), "%s/%s", DataDir, XLOG_CONTROL_FILE);
15201521

15211522
fp = AllocateFile(path, PG_BINARY_R);
15221523
if (fp == NULL)

src/bin/pg_combinebackup/pg_combinebackup.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/fs.h>
2525
#endif
2626

27+
#include "access/xlog_internal.h"
2728
#include "backup_label.h"
2829
#include "common/checksum_helper.h"
2930
#include "common/controldata_utils.h"
@@ -300,7 +301,7 @@ main(int argc, char *argv[])
300301
{
301302
char *controlpath;
302303

303-
controlpath = psprintf("%s/%s", prior_backup_dirs[i], "global/pg_control");
304+
controlpath = psprintf("%s/%s", prior_backup_dirs[i], XLOG_CONTROL_FILE);
304305

305306
pg_fatal("%s: manifest system identifier is %" PRIu64 ", but control file has %" PRIu64,
306307
controlpath,
@@ -614,7 +615,7 @@ check_control_files(int n_backups, char **backup_dirs)
614615
bool crc_ok;
615616
char *controlpath;
616617

617-
controlpath = psprintf("%s/%s", backup_dirs[i], "global/pg_control");
618+
controlpath = psprintf("%s/%s", backup_dirs[i], XLOG_CONTROL_FILE);
618619
pg_log_debug("reading \"%s\"", controlpath);
619620
control_file = get_controlfile_by_exact_path(controlpath, &crc_ok);
620621

src/bin/pg_controldata/pg_controldata.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* pg_controldata
33
*
4-
* reads the data from $PGDATA/global/pg_control
4+
* reads the data from the control file located at $PGDATA/XLOG_CONTROL_FILE.
55
*
66
* copyright (c) Oliver Elphick <olly@lfix.co.uk>, 2001;
77
* license: BSD

src/bin/pg_rewind/filemap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <sys/stat.h>
2727
#include <unistd.h>
2828

29+
#include "access/xlog_internal.h"
2930
#include "catalog/pg_tablespace_d.h"
3031
#include "common/file_utils.h"
3132
#include "common/hashfn_unstable.h"
@@ -704,7 +705,7 @@ decide_file_action(file_entry_t *entry)
704705
* Don't touch the control file. It is handled specially, after copying
705706
* all the other files.
706707
*/
707-
if (strcmp(path, "global/pg_control") == 0)
708+
if (strcmp(path, XLOG_CONTROL_FILE) == 0)
708709
return FILE_ACTION_NONE;
709710

710711
/* Skip macOS system files */

src/bin/pg_rewind/pg_rewind.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ main(int argc, char **argv)
328328
* need to make sure by themselves that the target cluster is in a clean
329329
* state.
330330
*/
331-
buffer = slurpFile(datadir_target, "global/pg_control", &size);
331+
buffer = slurpFile(datadir_target, XLOG_CONTROL_FILE, &size);
332332
digestControlFile(&ControlFile_target, buffer, size);
333333
pg_free(buffer);
334334

@@ -338,12 +338,12 @@ main(int argc, char **argv)
338338
{
339339
ensureCleanShutdown(argv[0]);
340340

341-
buffer = slurpFile(datadir_target, "global/pg_control", &size);
341+
buffer = slurpFile(datadir_target, XLOG_CONTROL_FILE, &size);
342342
digestControlFile(&ControlFile_target, buffer, size);
343343
pg_free(buffer);
344344
}
345345

346-
buffer = source->fetch_file(source, "global/pg_control", &size);
346+
buffer = source->fetch_file(source, XLOG_CONTROL_FILE, &size);
347347
digestControlFile(&ControlFile_source, buffer, size);
348348
pg_free(buffer);
349349

@@ -636,7 +636,7 @@ perform_rewind(filemap_t *filemap, rewind_source *source,
636636
* Fetch the control file from the source last. This ensures that the
637637
* minRecoveryPoint is up-to-date.
638638
*/
639-
buffer = source->fetch_file(source, "global/pg_control", &size);
639+
buffer = source->fetch_file(source, XLOG_CONTROL_FILE, &size);
640640
digestControlFile(&ControlFile_source_after, buffer, size);
641641
pg_free(buffer);
642642

src/bin/pg_upgrade/controldata.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <ctype.h>
1313
#include <limits.h> /* for CHAR_MIN */
1414

15+
#include "access/xlog_internal.h"
1516
#include "common/string.h"
1617
#include "pg_upgrade.h"
1718

@@ -757,10 +758,10 @@ disable_old_cluster(transferMode transfer_mode)
757758
new_path[MAXPGPATH];
758759

759760
/* rename pg_control so old server cannot be accidentally started */
760-
prep_status("Adding \".old\" suffix to old global/pg_control");
761+
prep_status("Adding \".old\" suffix to old " XLOG_CONTROL_FILE);
761762

762-
snprintf(old_path, sizeof(old_path), "%s/global/pg_control", old_cluster.pgdata);
763-
snprintf(new_path, sizeof(new_path), "%s/global/pg_control.old", old_cluster.pgdata);
763+
snprintf(old_path, sizeof(old_path), "%s/%s", old_cluster.pgdata, XLOG_CONTROL_FILE);
764+
snprintf(new_path, sizeof(new_path), "%s/%s.old", old_cluster.pgdata, XLOG_CONTROL_FILE);
764765
if (pg_mv_file(old_path, new_path) != 0)
765766
pg_fatal("could not rename file \"%s\" to \"%s\": %m",
766767
old_path, new_path);
@@ -769,10 +770,10 @@ disable_old_cluster(transferMode transfer_mode)
769770
if (transfer_mode == TRANSFER_MODE_LINK)
770771
pg_log(PG_REPORT, "\n"
771772
"If you want to start the old cluster, you will need to remove\n"
772-
"the \".old\" suffix from %s/global/pg_control.old.\n"
773+
"the \".old\" suffix from %s/%s.old.\n"
773774
"Because \"link\" mode was used, the old cluster cannot be safely\n"
774775
"started once the new cluster has been started.",
775-
old_cluster.pgdata);
776+
old_cluster.pgdata, XLOG_CONTROL_FILE);
776777
else if (transfer_mode == TRANSFER_MODE_SWAP)
777778
pg_log(PG_REPORT, "\n"
778779
"Because \"swap\" mode was used, the old cluster can no longer be\n"

src/bin/pg_verifybackup/astreamer_verify.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "postgres_fe.h"
1616

17+
#include "access/xlog_internal.h"
1718
#include "catalog/pg_control.h"
1819
#include "pg_verifybackup.h"
1920

@@ -225,7 +226,7 @@ member_verify_header(astreamer *streamer, astreamer_member *member)
225226
(!mystreamer->context->skip_checksums && should_verify_checksum(m));
226227
mystreamer->verify_control_data =
227228
mystreamer->context->manifest->version != 1 &&
228-
!m->bad && strcmp(m->pathname, "global/pg_control") == 0;
229+
!m->bad && strcmp(m->pathname, XLOG_CONTROL_FILE) == 0;
229230

230231
/* If we're going to verify the checksum, initial a checksum context. */
231232
if (mystreamer->verify_checksum &&
@@ -370,7 +371,7 @@ member_verify_control_data(astreamer *streamer)
370371
pg_crc32c crc;
371372

372373
/* Should be here only for control file */
373-
Assert(strcmp(mystreamer->mfile->pathname, "global/pg_control") == 0);
374+
Assert(strcmp(mystreamer->mfile->pathname, XLOG_CONTROL_FILE) == 0);
374375
Assert(mystreamer->verify_control_data);
375376

376377
/*

src/bin/pg_verifybackup/pg_verifybackup.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <sys/stat.h>
1919
#include <time.h>
2020

21+
#include "access/xlog_internal.h"
2122
#include "common/logging.h"
2223
#include "common/parse_manifest.h"
2324
#include "fe_utils/simple_list.h"
@@ -730,7 +731,7 @@ verify_plain_backup_file(verifier_context *context, char *relpath,
730731
* version 1.
731732
*/
732733
if (context->manifest->version != 1 &&
733-
strcmp(relpath, "global/pg_control") == 0)
734+
strcmp(relpath, XLOG_CONTROL_FILE) == 0)
734735
verify_control_file(fullpath, context->manifest->system_identifier);
735736

736737
/* Update statistics for progress report, if necessary */

src/common/controldata_utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ get_controlfile(const char *DataDir, bool *crc_ok_p)
5353
{
5454
char ControlFilePath[MAXPGPATH];
5555

56-
snprintf(ControlFilePath, MAXPGPATH, "%s/global/pg_control", DataDir);
56+
snprintf(ControlFilePath, MAXPGPATH, "%s/%s", DataDir, XLOG_CONTROL_FILE);
5757

5858
return get_controlfile_by_exact_path(ControlFilePath, crc_ok_p);
5959
}

0 commit comments

Comments
 (0)