Use XLOG_CONTROL_FILE macro everywhere?
Hello!
There is a macro XLOG_CONTROL_FILE for control file name
defined in access/xlog_internal.h
And there are some places in code where this macro is used
like here
https://github.com/postgres/postgres/blob/84db9a0eb10dd1dbee6db509c0e427fa237177dc/src/bin/pg_resetwal/pg_resetwal.c#L588
or here
https://github.com/postgres/postgres/blob/84db9a0eb10dd1dbee6db509c0e427fa237177dc/src/common/controldata_utils.c#L214
But there are some other places where the control file
name is used as text string directly.
May be better use this macro everywhere in C code?
The patch attached tries to do this.
Would be glad if take a look on it.
With the best regards,
--
Anton A. Melnikov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
Attachments:
0001-Use-XLOG_CONTROL_FILE-macro-everywhere-in-C-code.patchtext/x-patch; charset=UTF-8; name=0001-Use-XLOG_CONTROL_FILE-macro-everywhere-in-C-code.patchDownload
From 2692683142c98572114c32f696b55c6a642dd3e9 Mon Sep 17 00:00:00 2001
From: "Anton A. Melnikov" <a.melnikov@postgrespro.ru>
Date: Fri, 19 Apr 2024 06:12:44 +0300
Subject: [PATCH] Use XLOG_CONTROL_FILE macro everywhere in C code
---
src/backend/backup/basebackup.c | 2 +-
src/backend/postmaster/postmaster.c | 3 ++-
src/bin/pg_combinebackup/pg_combinebackup.c | 5 +++--
src/bin/pg_controldata/pg_controldata.c | 2 +-
src/bin/pg_rewind/filemap.c | 3 ++-
src/bin/pg_rewind/pg_rewind.c | 8 ++++----
src/bin/pg_upgrade/controldata.c | 11 ++++++-----
src/bin/pg_verifybackup/pg_verifybackup.c | 3 ++-
src/common/controldata_utils.c | 2 +-
9 files changed, 22 insertions(+), 17 deletions(-)
diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c
index 9a2bf59e84..c5a1e18104 100644
--- a/src/backend/backup/basebackup.c
+++ b/src/backend/backup/basebackup.c
@@ -1347,7 +1347,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)
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 7f3170a8f0..02b36caea7 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -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/file_utils.h"
@@ -1489,7 +1490,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)
diff --git a/src/bin/pg_combinebackup/pg_combinebackup.c b/src/bin/pg_combinebackup/pg_combinebackup.c
index b26c532445..16448e78b8 100644
--- a/src/bin/pg_combinebackup/pg_combinebackup.c
+++ b/src/bin/pg_combinebackup/pg_combinebackup.c
@@ -16,6 +16,7 @@
#include <fcntl.h>
#include <limits.h>
+#include "access/xlog_internal.h"
#include "backup_label.h"
#include "common/blkreftable.h"
#include "common/checksum_helper.h"
@@ -284,7 +285,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 %llu, but control file has %llu",
controlpath,
@@ -591,7 +592,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);
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index 93e0837947..1fe6618e7f 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -1,7 +1,7 @@
/*
* pg_controldata
*
- * reads the data from $PGDATA/global/pg_control
+ * reads the data from $PGDATA/<control file>
*
* copyright (c) Oliver Elphick <olly@lfix.co.uk>, 2001;
* license: BSD
diff --git a/src/bin/pg_rewind/filemap.c b/src/bin/pg_rewind/filemap.c
index 4458324c9d..6224e94d09 100644
--- a/src/bin/pg_rewind/filemap.c
+++ b/src/bin/pg_rewind/filemap.c
@@ -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"
@@ -643,7 +644,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 */
diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c
index 8449ae78ef..213a8b22cd 100644
--- a/src/bin/pg_rewind/pg_rewind.c
+++ b/src/bin/pg_rewind/pg_rewind.c
@@ -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);
@@ -631,7 +631,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);
diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c
index 1f0ccea3ed..ae2c5d580a 100644
--- a/src/bin/pg_upgrade/controldata.c
+++ b/src/bin/pg_upgrade/controldata.c
@@ -11,6 +11,7 @@
#include <ctype.h>
+#include "access/xlog_internal.h"
#include "common/string.h"
#include "pg_upgrade.h"
@@ -714,10 +715,10 @@ disable_old_cluster(void)
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);
@@ -725,8 +726,8 @@ disable_old_cluster(void)
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);
}
diff --git a/src/bin/pg_verifybackup/pg_verifybackup.c b/src/bin/pg_verifybackup/pg_verifybackup.c
index fd610c20a6..53338df397 100644
--- a/src/bin/pg_verifybackup/pg_verifybackup.c
+++ b/src/bin/pg_verifybackup/pg_verifybackup.c
@@ -18,6 +18,7 @@
#include <sys/stat.h>
#include <time.h>
+#include "access/xlog_internal.h"
#include "common/controldata_utils.h"
#include "common/hashfn_unstable.h"
#include "common/logging.h"
@@ -735,7 +736,7 @@ verify_backup_file(verifier_context *context, char *relpath, char *fullpath)
* 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 */
diff --git a/src/common/controldata_utils.c b/src/common/controldata_utils.c
index 82309b2510..411139eeb0 100644
--- a/src/common/controldata_utils.c
+++ b/src/common/controldata_utils.c
@@ -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);
}
--
2.43.2
On 19 Apr 2024, at 05:50, Anton A. Melnikov <a.melnikov@postgrespro.ru> wrote:
May be better use this macro everywhere in C code?
Off the cuff that seems to make sense, it does make it easier to grep for uses
of the control file.
--
Daniel Gustafsson
On Fri, Apr 19, 2024 at 10:12:14AM +0200, Daniel Gustafsson wrote:
Off the cuff that seems to make sense, it does make it easier to grep for uses
of the control file.
+1 for switching to the macro where we can. Still, I don't see a
point in rushing and would just switch that once v18 opens up for
business.
--
Michael
On 20 Apr 2024, at 01:23, Michael Paquier <michael@paquier.xyz> wrote:
On Fri, Apr 19, 2024 at 10:12:14AM +0200, Daniel Gustafsson wrote:
Off the cuff that seems to make sense, it does make it easier to grep for uses
of the control file.+1 for switching to the macro where we can. Still, I don't see a
point in rushing and would just switch that once v18 opens up for
business.
Absolutely, this is not fixing a defect so it's v18 material.
Anton: please register this patch in the Open commitfest to ensure it's not
forgotten about.
--
Daniel Gustafsson
On 20.04.2024 09:36, Daniel Gustafsson wrote:
Anton: please register this patch in the Open commitfest to ensure it's not
forgotten about.
Done.
Daniel and Michael thank you!
--
Anton A. Melnikov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
On 19.04.24 05:50, Anton A. Melnikov wrote:
There is a macro XLOG_CONTROL_FILE for control file name
defined in access/xlog_internal.h
And there are some places in code where this macro is used
like here
https://github.com/postgres/postgres/blob/84db9a0eb10dd1dbee6db509c0e427fa237177dc/src/bin/pg_resetwal/pg_resetwal.c#L588
or here
https://github.com/postgres/postgres/blob/84db9a0eb10dd1dbee6db509c0e427fa237177dc/src/common/controldata_utils.c#L214But there are some other places where the control file
name is used as text string directly.May be better use this macro everywhere in C code?
I don't know. I don't find XLOG_CONTROL_FILE to be a very intuitive
proxy for "pg_control".
On 24.04.2024 12:02, Peter Eisentraut wrote:
On 19.04.24 05:50, Anton A. Melnikov wrote:
May be better use this macro everywhere in C code?
I don't know. I don't find XLOG_CONTROL_FILE to be a very intuitive proxy for "pg_control".
Then maybe replace XLOG_CONTROL_FILE with PG_CONTROL_FILE?
The PG_CONTROL_FILE_SIZE macro is already in the code.
With the best regards,
--
Anton A. Melnikov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
On 24 Apr 2024, at 11:13, Anton A. Melnikov <a.melnikov@postgrespro.ru> wrote:
On 24.04.2024 12:02, Peter Eisentraut wrote:
On 19.04.24 05:50, Anton A. Melnikov wrote:
May be better use this macro everywhere in C code?
I don't know. I don't find XLOG_CONTROL_FILE to be a very intuitive proxy for "pg_control".
Maybe, but inconsistent usage is also unintuitive.
Then maybe replace XLOG_CONTROL_FILE with PG_CONTROL_FILE?
The PG_CONTROL_FILE_SIZE macro is already in the code.
With the best regards,
XLOG_CONTROL_FILE is close to two decades old so there might be extensions
using it (though the risk might be slim), perhaps using offering it as as well
as backwards-compatability is warranted should we introduce a new name?
--
Daniel Gustafsson
On 24.04.2024 12:19, Daniel Gustafsson wrote:
On 24 Apr 2024, at 11:13, Anton A. Melnikov <a.melnikov@postgrespro.ru> wrote:
On 24.04.2024 12:02, Peter Eisentraut wrote:
On 19.04.24 05:50, Anton A. Melnikov wrote:
May be better use this macro everywhere in C code?
I don't know. I don't find XLOG_CONTROL_FILE to be a very intuitive proxy for "pg_control".
Maybe, but inconsistent usage is also unintuitive.
Then maybe replace XLOG_CONTROL_FILE with PG_CONTROL_FILE?
The PG_CONTROL_FILE_SIZE macro is already in the code.
With the best regards,XLOG_CONTROL_FILE is close to two decades old so there might be extensions
using it (though the risk might be slim), perhaps using offering it as as well
as backwards-compatability is warranted should we introduce a new name?
To ensure backward compatibility we can save the old macro like this:
#define XLOG_CONTROL_FILE "global/pg_control"
#define PG_CONTROL_FILE XLOG_CONTROL_FILE
With the best wishes,
--
Anton A. Melnikov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
On Wed, Apr 24, 2024 at 12:32:46PM +0300, Anton A. Melnikov wrote:
To ensure backward compatibility we can save the old macro like this:
#define XLOG_CONTROL_FILE "global/pg_control"
#define PG_CONTROL_FILE XLOG_CONTROL_FILEWith the best wishes,
Not sure that I would bother with a second one. But, well, why not if
people want to rename it, as long as you keep compatibility.
--
Michael
On Wed, Apr 24, 2024 at 8:04 PM Michael Paquier <michael@paquier.xyz> wrote:
On Wed, Apr 24, 2024 at 12:32:46PM +0300, Anton A. Melnikov wrote:
To ensure backward compatibility we can save the old macro like this:
#define XLOG_CONTROL_FILE "global/pg_control"
#define PG_CONTROL_FILE XLOG_CONTROL_FILEWith the best wishes,
Not sure that I would bother with a second one. But, well, why not if
people want to rename it, as long as you keep compatibility.
I vote for just standardizing on XLOG_CONTROL_FILE. That name seems
sufficiently intuitive to me, and I'd rather have one identifier for
this than two. It's simpler that way.
--
Robert Haas
EDB: http://www.enterprisedb.com
Robert Haas <robertmhaas@gmail.com> writes:
On Wed, Apr 24, 2024 at 8:04 PM Michael Paquier <michael@paquier.xyz> wrote:
Not sure that I would bother with a second one. But, well, why not if
people want to rename it, as long as you keep compatibility.
I vote for just standardizing on XLOG_CONTROL_FILE. That name seems
sufficiently intuitive to me, and I'd rather have one identifier for
this than two. It's simpler that way.
+1. Back when we did the great xlog-to-wal renaming, we explicitly
agreed that we wouldn't change internal symbols referring to xlog.
It might or might not be appropriate to revisit that decision,
but I sure don't want to do it piecemeal, one symbol at a time.
Also, if we did rename this one, the logical choice would be
WAL_CONTROL_FILE not PG_CONTROL_FILE.
regards, tom lane
On 26.04.24 22:51, Tom Lane wrote:
Robert Haas <robertmhaas@gmail.com> writes:
On Wed, Apr 24, 2024 at 8:04 PM Michael Paquier <michael@paquier.xyz> wrote:
Not sure that I would bother with a second one. But, well, why not if
people want to rename it, as long as you keep compatibility.I vote for just standardizing on XLOG_CONTROL_FILE. That name seems
sufficiently intuitive to me, and I'd rather have one identifier for
this than two. It's simpler that way.+1. Back when we did the great xlog-to-wal renaming, we explicitly
agreed that we wouldn't change internal symbols referring to xlog.
It might or might not be appropriate to revisit that decision,
but I sure don't want to do it piecemeal, one symbol at a time.Also, if we did rename this one, the logical choice would be
WAL_CONTROL_FILE not PG_CONTROL_FILE.
My reasoning was mainly that I don't see pg_control as controlling just
the WAL. But I don't feel strongly about instigating a great renaming
here or something.
On 27 Apr 2024, at 11:12, Peter Eisentraut <peter@eisentraut.org> wrote:
On 26.04.24 22:51, Tom Lane wrote:
Robert Haas <robertmhaas@gmail.com> writes:
On Wed, Apr 24, 2024 at 8:04 PM Michael Paquier <michael@paquier.xyz> wrote:
Not sure that I would bother with a second one. But, well, why not if
people want to rename it, as long as you keep compatibility.I vote for just standardizing on XLOG_CONTROL_FILE. That name seems
sufficiently intuitive to me, and I'd rather have one identifier for
this than two. It's simpler that way.+1. Back when we did the great xlog-to-wal renaming, we explicitly
agreed that we wouldn't change internal symbols referring to xlog.
It might or might not be appropriate to revisit that decision,
but I sure don't want to do it piecemeal, one symbol at a time.
Also, if we did rename this one, the logical choice would be
WAL_CONTROL_FILE not PG_CONTROL_FILE.My reasoning was mainly that I don't see pg_control as controlling just the WAL. But I don't feel strongly about instigating a great renaming here or something.
Summarizing the thread it seems consensus is using XLOG_CONTROL_FILE
consistently as per the original patch.
A few comments on the patch though:
- * reads the data from $PGDATA/global/pg_control
+ * reads the data from $PGDATA/<control file>
I don't think this is an improvement, I'd leave that one as the filename
spelled out.
- "the \".old\" suffix from %s/global/pg_control.old.\n"
+ "the \".old\" suffix from %s/%s.old.\n"
Same with that change, not sure I think that makes reading the errormessage
code any easier.
--
Daniel Gustafsson
At Mon, 2 Sep 2024 15:44:45 +0200, Daniel Gustafsson <daniel@yesql.se> wrote in
Summarizing the thread it seems consensus is using XLOG_CONTROL_FILE
consistently as per the original patch.A few comments on the patch though:
- * reads the data from $PGDATA/global/pg_control + * reads the data from $PGDATA/<control file>I don't think this is an improvement, I'd leave that one as the filename
spelled out.- "the \".old\" suffix from %s/global/pg_control.old.\n" + "the \".old\" suffix from %s/%s.old.\n"Same with that change, not sure I think that makes reading the errormessage
code any easier.
I agree with the first point. In fact, I think it might be even better
to just write something like "reads the data from the control file" in
plain language rather than using the actual file name. As for the
second point, I'm fine either way, but if the main goal is to ensure
resilience against future changes to the value of XLOG_CONTROL_FILE,
then changing it makes sense. On the other hand, I don't see any
strong reasons not to change it. That said, I don't really expect the
value to change in the first place.
The following point caught my attention.
+++ b/src/backend/postmaster/postmaster.c
...
+#include "access/xlog_internal.h"
The name xlog_internal suggests that the file should only be included
by modules dealing with XLOG details, and postmaster.c doesn't seem to
fit that category. If the macro is used more broadly, it might be
better to move it to a more public location. However, following the
current discussion, if we decide to keep the macro's name as it is, it
would make more sense to keep it in its current location.
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
On 03.09.2024 08:37, Kyotaro Horiguchi wrote:
At Mon, 2 Sep 2024 15:44:45 +0200, Daniel Gustafsson <daniel@yesql.se> wrote in
Summarizing the thread it seems consensus is using XLOG_CONTROL_FILE
consistently as per the original patch.
1)
A few comments on the patch though:
- * reads the data from $PGDATA/global/pg_control + * reads the data from $PGDATA/<control file>I don't think this is an improvement, I'd leave that one as the filename
spelled out.I agree with the first point. In fact, I think it might be even better
to just write something like "reads the data from the control file" in
plain language rather than using the actual file name.
Thanks for remarks! Agreed with both. Tried to fix in v2 attached.
2)
- "the \".old\" suffix from %s/global/pg_control.old.\n" + "the \".old\" suffix from %s/%s.old.\n"Same with that change, not sure I think that makes reading the errormessage
code any easier.As for the
second point, I'm fine either way, but if the main goal is to ensure
resilience against future changes to the value of XLOG_CONTROL_FILE,
then changing it makes sense. On the other hand, I don't see any
strong reasons not to change it. That said, I don't really expect the
value to change in the first place.
In v2 removed XLOG_CONTROL_FILE from args and used it directly in the string.
IMHO this makes the code more readable and will output the correct
text if the macro changes.
3)
The following point caught my attention.
+++ b/src/backend/postmaster/postmaster.c...
+#include "access/xlog_internal.h"
The name xlog_internal suggests that the file should only be included
by modules dealing with XLOG details, and postmaster.c doesn't seem to
fit that category. If the macro is used more broadly, it might be
better to move it to a more public location. However, following the
current discussion, if we decide to keep the macro's name as it is, it
would make more sense to keep it in its current location.
Maybe include/access/xlogdefs.h would be a good place for this?
In v2 moved some definitions from xlog_internal to xlogdefs
and removed including xlog_internal.h from the postmaster.c.
Please, take a look on it.
With the best wishes,
--
Anton A. Melnikov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
Attachments:
v2-0001-Use-XLOG_CONTROL_FILE-macro-everywhere-in-C-code.patchtext/x-patch; charset=UTF-8; name=v2-0001-Use-XLOG_CONTROL_FILE-macro-everywhere-in-C-code.patchDownload
From 0b1435492e293ee5553a69c2b3c560b93addc82e Mon Sep 17 00:00:00 2001
From: "Anton A. Melnikov" <a.melnikov@postgrespro.ru>
Date: Fri, 19 Apr 2024 06:12:44 +0300
Subject: [PATCH] Use XLOG_CONTROL_FILE macro everywhere in C code
---
src/backend/backup/basebackup.c | 2 +-
src/backend/postmaster/postmaster.c | 2 +-
src/bin/pg_combinebackup/pg_combinebackup.c | 5 +++--
src/bin/pg_controldata/pg_controldata.c | 3 ++-
src/bin/pg_rewind/filemap.c | 3 ++-
src/bin/pg_rewind/pg_rewind.c | 8 ++++----
src/bin/pg_upgrade/controldata.c | 9 +++++----
src/bin/pg_verifybackup/pg_verifybackup.c | 3 ++-
src/common/controldata_utils.c | 2 +-
src/include/access/xlogdefs.h | 15 +++++++++++++++
10 files changed, 36 insertions(+), 16 deletions(-)
diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c
index 9a2bf59e84..c5a1e18104 100644
--- a/src/backend/backup/basebackup.c
+++ b/src/backend/backup/basebackup.c
@@ -1347,7 +1347,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)
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 7f3170a8f0..1a34ed1cab 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -1489,7 +1489,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)
diff --git a/src/bin/pg_combinebackup/pg_combinebackup.c b/src/bin/pg_combinebackup/pg_combinebackup.c
index b26c532445..16448e78b8 100644
--- a/src/bin/pg_combinebackup/pg_combinebackup.c
+++ b/src/bin/pg_combinebackup/pg_combinebackup.c
@@ -16,6 +16,7 @@
#include <fcntl.h>
#include <limits.h>
+#include "access/xlog_internal.h"
#include "backup_label.h"
#include "common/blkreftable.h"
#include "common/checksum_helper.h"
@@ -284,7 +285,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 %llu, but control file has %llu",
controlpath,
@@ -591,7 +592,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);
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index 93e0837947..ba3e18c918 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -1,7 +1,8 @@
/*
* pg_controldata
*
- * reads the data from $PGDATA/global/pg_control
+ * reads the data from reads the data from the control file
+ * which is located at $PGDATA/XLOG_CONTROL_FILE
*
* copyright (c) Oliver Elphick <olly@lfix.co.uk>, 2001;
* license: BSD
diff --git a/src/bin/pg_rewind/filemap.c b/src/bin/pg_rewind/filemap.c
index 4458324c9d..6224e94d09 100644
--- a/src/bin/pg_rewind/filemap.c
+++ b/src/bin/pg_rewind/filemap.c
@@ -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"
@@ -643,7 +644,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 */
diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c
index 8449ae78ef..213a8b22cd 100644
--- a/src/bin/pg_rewind/pg_rewind.c
+++ b/src/bin/pg_rewind/pg_rewind.c
@@ -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);
@@ -631,7 +631,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);
diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c
index 1f0ccea3ed..0527ae76d8 100644
--- a/src/bin/pg_upgrade/controldata.c
+++ b/src/bin/pg_upgrade/controldata.c
@@ -11,6 +11,7 @@
#include <ctype.h>
+#include "access/xlog_internal.h"
#include "common/string.h"
#include "pg_upgrade.h"
@@ -714,10 +715,10 @@ disable_old_cluster(void)
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);
@@ -725,7 +726,7 @@ disable_old_cluster(void)
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/" XLOG_CONTROL_FILE ".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);
diff --git a/src/bin/pg_verifybackup/pg_verifybackup.c b/src/bin/pg_verifybackup/pg_verifybackup.c
index fd610c20a6..53338df397 100644
--- a/src/bin/pg_verifybackup/pg_verifybackup.c
+++ b/src/bin/pg_verifybackup/pg_verifybackup.c
@@ -18,6 +18,7 @@
#include <sys/stat.h>
#include <time.h>
+#include "access/xlog_internal.h"
#include "common/controldata_utils.h"
#include "common/hashfn_unstable.h"
#include "common/logging.h"
@@ -735,7 +736,7 @@ verify_backup_file(verifier_context *context, char *relpath, char *fullpath)
* 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 */
diff --git a/src/common/controldata_utils.c b/src/common/controldata_utils.c
index 82309b2510..411139eeb0 100644
--- a/src/common/controldata_utils.c
+++ b/src/common/controldata_utils.c
@@ -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);
}
diff --git a/src/include/access/xlogdefs.h b/src/include/access/xlogdefs.h
index 3009798952..9ee9ffad70 100644
--- a/src/include/access/xlogdefs.h
+++ b/src/include/access/xlogdefs.h
@@ -28,6 +28,21 @@ typedef uint64 XLogRecPtr;
#define InvalidXLogRecPtr 0
#define XLogRecPtrIsInvalid(r) ((r) == InvalidXLogRecPtr)
+/*
+ * The XLog directory and control file (relative to $PGDATA)
+ */
+#define XLOGDIR "pg_wal"
+#define XLOG_CONTROL_FILE "global/pg_control"
+
+/*
+ * These macros encapsulate knowledge about the exact layout of XLog file
+ * names, timeline history file names, and archive-status file names.
+ */
+#define MAXFNAMELEN 64
+
+/* Length of XLog file name */
+#define XLOG_FNAME_LEN 24
+
/*
* First LSN to use for "fake" LSNs.
*
--
2.46.0
At Tue, 3 Sep 2024 12:02:26 +0300, "Anton A. Melnikov" <a.melnikov@postgrespro.ru> wrote in
In v2 removed XLOG_CONTROL_FILE from args and used it directly in the
string.
IMHO this makes the code more readable and will output the correct
text if the macro changes.
Yeah, I had this in my mind. Looks good to me.
3)
..
Maybe include/access/xlogdefs.h would be a good place for this?
In v2 moved some definitions from xlog_internal to xlogdefs
and removed including xlog_internal.h from the postmaster.c.
Please, take a look on it.
The change can help avoid disrupting existing users of the
macro. However, the file is documented as follows:
* Postgres write-ahead log manager record pointer and
* timeline number definitions
We could modify the file definition, but I'm not sure if that's the
best approach. Instead, I'd like to propose separating the file and
path-related definitions from xlog_internal.h, as shown in the
attached first patch. This change would allow some modules to include
files without unnecessary details.
The second file is your patch, adjusted based on the first patch.
I’d appreciate hearing from others on whether they find the first
patch worthwhile. If it’s not considered worthwhile, then I believe
having postmaster include xlog_internal.h would be the best approach.
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
Attachments:
0001-Split-file-related-parts-from-xlog_internal.h.patchtext/x-patch; charset=us-asciiDownload
From 22b71830ff601717d01dc66be95bafb930b1a0ea Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Date: Wed, 4 Sep 2024 16:15:16 +0900
Subject: [PATCH 1/2] Split file-related parts from xlog_internal.h
Some modules that require XLOG file manipulation had to include
xlog_internal.h, which contains excessively detailed internal
information. This commit separates the file and file path-related
components into xlogfilepaths.h, thereby avoiding the exposure of
unrelated details of the XLOG module.
---
src/backend/access/transam/timeline.c | 1 -
src/backend/postmaster/pgarch.c | 1 -
src/backend/utils/adt/genfile.c | 1 -
src/bin/initdb/initdb.c | 1 +
src/bin/pg_archivecleanup/pg_archivecleanup.c | 2 +-
src/bin/pg_basebackup/pg_basebackup.c | 4 +-
src/bin/pg_basebackup/pg_receivewal.c | 1 +
src/bin/pg_basebackup/pg_recvlogical.c | 1 -
src/bin/pg_basebackup/receivelog.c | 2 +-
src/bin/pg_basebackup/streamutil.c | 2 +-
src/bin/pg_controldata/pg_controldata.c | 1 -
src/bin/pg_rewind/pg_rewind.c | 2 +-
src/include/access/xlog.h | 13 +-
src/include/access/xlog_internal.h | 178 +-------------
src/include/access/xlogfilepaths.h | 219 ++++++++++++++++++
15 files changed, 230 insertions(+), 199 deletions(-)
create mode 100644 src/include/access/xlogfilepaths.h
diff --git a/src/backend/access/transam/timeline.c b/src/backend/access/transam/timeline.c
index 146751ae37..18df8fd326 100644
--- a/src/backend/access/transam/timeline.c
+++ b/src/backend/access/transam/timeline.c
@@ -38,7 +38,6 @@
#include "access/xlog.h"
#include "access/xlog_internal.h"
#include "access/xlogarchive.h"
-#include "access/xlogdefs.h"
#include "pgstat.h"
#include "storage/fd.h"
diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c
index 02f91431f5..4971cd76ff 100644
--- a/src/backend/postmaster/pgarch.c
+++ b/src/backend/postmaster/pgarch.c
@@ -30,7 +30,6 @@
#include <unistd.h>
#include "access/xlog.h"
-#include "access/xlog_internal.h"
#include "archive/archive_module.h"
#include "archive/shell_archive.h"
#include "lib/binaryheap.h"
diff --git a/src/backend/utils/adt/genfile.c b/src/backend/utils/adt/genfile.c
index 24b95c32b7..17be1756e2 100644
--- a/src/backend/utils/adt/genfile.c
+++ b/src/backend/utils/adt/genfile.c
@@ -21,7 +21,6 @@
#include <dirent.h>
#include "access/htup_details.h"
-#include "access/xlog_internal.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_tablespace_d.h"
#include "catalog/pg_type.h"
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index f00718a015..95ec8d9c92 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -65,6 +65,7 @@
#endif
#include "access/xlog_internal.h"
+#include "lib/stringinfo.h"
#include "catalog/pg_authid_d.h"
#include "catalog/pg_class_d.h" /* pgrminclude ignore */
#include "catalog/pg_collation_d.h"
diff --git a/src/bin/pg_archivecleanup/pg_archivecleanup.c b/src/bin/pg_archivecleanup/pg_archivecleanup.c
index 5a124385b7..f6b33de32a 100644
--- a/src/bin/pg_archivecleanup/pg_archivecleanup.c
+++ b/src/bin/pg_archivecleanup/pg_archivecleanup.c
@@ -15,7 +15,7 @@
#include <signal.h>
#include <sys/time.h>
-#include "access/xlog_internal.h"
+#include "access/xlogfilepaths.h"
#include "common/logging.h"
#include "getopt_long.h"
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index e41a6cfbda..f86af782dc 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -25,7 +25,7 @@
#include <zlib.h>
#endif
-#include "access/xlog_internal.h"
+#include "access/xlogfilepaths.h"
#include "astreamer_inject.h"
#include "backup/basebackup.h"
#include "common/compression.h"
@@ -35,6 +35,8 @@
#include "fe_utils/option_utils.h"
#include "fe_utils/recovery_gen.h"
#include "getopt_long.h"
+#include "pgtime.h"
+#include "port/pg_bswap.h"
#include "receivelog.h"
#include "streamutil.h"
diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c
index 555f0175f0..dbbbeabbc4 100644
--- a/src/bin/pg_basebackup/pg_receivewal.c
+++ b/src/bin/pg_basebackup/pg_receivewal.c
@@ -27,6 +27,7 @@
#include <zlib.h>
#endif
+//#include "access/xlogfilepaths.h"
#include "access/xlog_internal.h"
#include "common/file_perm.h"
#include "common/logging.h"
diff --git a/src/bin/pg_basebackup/pg_recvlogical.c b/src/bin/pg_basebackup/pg_recvlogical.c
index 3db520ed38..f242f1f379 100644
--- a/src/bin/pg_basebackup/pg_recvlogical.c
+++ b/src/bin/pg_basebackup/pg_recvlogical.c
@@ -18,7 +18,6 @@
#include <sys/stat.h>
#include <unistd.h>
-#include "access/xlog_internal.h"
#include "common/fe_memutils.h"
#include "common/file_perm.h"
#include "common/logging.h"
diff --git a/src/bin/pg_basebackup/receivelog.c b/src/bin/pg_basebackup/receivelog.c
index 70f4246764..6db16df4bc 100644
--- a/src/bin/pg_basebackup/receivelog.c
+++ b/src/bin/pg_basebackup/receivelog.c
@@ -18,7 +18,7 @@
#include <sys/stat.h>
#include <unistd.h>
-#include "access/xlog_internal.h"
+#include "access/xlogfilepaths.h"
#include "common/file_utils.h"
#include "common/logging.h"
#include "libpq-fe.h"
diff --git a/src/bin/pg_basebackup/streamutil.c b/src/bin/pg_basebackup/streamutil.c
index 30b3d9a377..e65c5eb060 100644
--- a/src/bin/pg_basebackup/streamutil.c
+++ b/src/bin/pg_basebackup/streamutil.c
@@ -17,7 +17,7 @@
#include <sys/time.h>
#include <unistd.h>
-#include "access/xlog_internal.h"
+#include "access/xlogfilepaths.h"
#include "common/connect.h"
#include "common/fe_memutils.h"
#include "common/file_perm.h"
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index 93a05d80ca..233230712a 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -22,7 +22,6 @@
#include "access/transam.h"
#include "access/xlog.h"
-#include "access/xlog_internal.h"
#include "catalog/pg_control.h"
#include "common/controldata_utils.h"
#include "common/logging.h"
diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c
index 1027d235dc..c4b97abd03 100644
--- a/src/bin/pg_rewind/pg_rewind.c
+++ b/src/bin/pg_rewind/pg_rewind.c
@@ -15,7 +15,7 @@
#include <unistd.h>
#include "access/timeline.h"
-#include "access/xlog_internal.h"
+#include "access/xlogfilepaths.h"
#include "catalog/catversion.h"
#include "catalog/pg_control.h"
#include "common/controldata_utils.h"
diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h
index 083810f5b4..09655c2c34 100644
--- a/src/include/access/xlog.h
+++ b/src/include/access/xlog.h
@@ -16,6 +16,7 @@
#include "datatype/timestamp.h"
#include "lib/stringinfo.h"
#include "nodes/pg_list.h"
+#include "access/xlogfilepaths.h"
/* Sync methods */
@@ -297,16 +298,4 @@ extern void do_pg_abort_backup(int code, Datum arg);
extern void register_persistent_abort_backup_handler(void);
extern SessionBackupState get_backup_status(void);
-/* File path names (all relative to $PGDATA) */
-#define RECOVERY_SIGNAL_FILE "recovery.signal"
-#define STANDBY_SIGNAL_FILE "standby.signal"
-#define BACKUP_LABEL_FILE "backup_label"
-#define BACKUP_LABEL_OLD "backup_label.old"
-
-#define TABLESPACE_MAP "tablespace_map"
-#define TABLESPACE_MAP_OLD "tablespace_map.old"
-
-/* files to signal promotion to primary */
-#define PROMOTE_SIGNAL_FILE "promote"
-
#endif /* XLOG_H */
diff --git a/src/include/access/xlog_internal.h b/src/include/access/xlog_internal.h
index e5cdba0584..39e52cec47 100644
--- a/src/include/access/xlog_internal.h
+++ b/src/include/access/xlog_internal.h
@@ -21,6 +21,7 @@
#include "access/xlogdefs.h"
#include "access/xlogreader.h"
+#include "access/xlogfilepaths.h"
#include "datatype/timestamp.h"
#include "lib/stringinfo.h"
#include "pgtime.h"
@@ -84,187 +85,10 @@ typedef XLogLongPageHeaderData *XLogLongPageHeader;
#define XLogPageHeaderSize(hdr) \
(((hdr)->xlp_info & XLP_LONG_HEADER) ? SizeOfXLogLongPHD : SizeOfXLogShortPHD)
-/* wal_segment_size can range from 1MB to 1GB */
-#define WalSegMinSize 1024 * 1024
-#define WalSegMaxSize 1024 * 1024 * 1024
-/* default number of min and max wal segments */
-#define DEFAULT_MIN_WAL_SEGS 5
-#define DEFAULT_MAX_WAL_SEGS 64
-
-/* check that the given size is a valid wal_segment_size */
-#define IsPowerOf2(x) (x > 0 && ((x) & ((x)-1)) == 0)
-#define IsValidWalSegSize(size) \
- (IsPowerOf2(size) && \
- ((size) >= WalSegMinSize && (size) <= WalSegMaxSize))
-
-#define XLogSegmentsPerXLogId(wal_segsz_bytes) \
- (UINT64CONST(0x100000000) / (wal_segsz_bytes))
-
-#define XLogSegNoOffsetToRecPtr(segno, offset, wal_segsz_bytes, dest) \
- (dest) = (segno) * (wal_segsz_bytes) + (offset)
-
-#define XLogSegmentOffset(xlogptr, wal_segsz_bytes) \
- ((xlogptr) & ((wal_segsz_bytes) - 1))
-
-/*
- * Compute a segment number from an XLogRecPtr.
- *
- * For XLByteToSeg, do the computation at face value. For XLByteToPrevSeg,
- * a boundary byte is taken to be in the previous segment. This is suitable
- * for deciding which segment to write given a pointer to a record end,
- * for example.
- */
-#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes) \
- logSegNo = (xlrp) / (wal_segsz_bytes)
-
-#define XLByteToPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
- logSegNo = ((xlrp) - 1) / (wal_segsz_bytes)
-
-/*
- * Convert values of GUCs measured in megabytes to equiv. segment count.
- * Rounds down.
- */
-#define XLogMBVarToSegs(mbvar, wal_segsz_bytes) \
- ((mbvar) / ((wal_segsz_bytes) / (1024 * 1024)))
-
-/*
- * Is an XLogRecPtr within a particular XLOG segment?
- *
- * For XLByteInSeg, do the computation at face value. For XLByteInPrevSeg,
- * a boundary byte is taken to be in the previous segment.
- */
-#define XLByteInSeg(xlrp, logSegNo, wal_segsz_bytes) \
- (((xlrp) / (wal_segsz_bytes)) == (logSegNo))
-
-#define XLByteInPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
- ((((xlrp) - 1) / (wal_segsz_bytes)) == (logSegNo))
-
/* Check if an XLogRecPtr value is in a plausible range */
#define XRecOffIsValid(xlrp) \
((xlrp) % XLOG_BLCKSZ >= SizeOfXLogShortPHD)
-/*
- * The XLog directory and control file (relative to $PGDATA)
- */
-#define XLOGDIR "pg_wal"
-#define XLOG_CONTROL_FILE "global/pg_control"
-
-/*
- * These macros encapsulate knowledge about the exact layout of XLog file
- * names, timeline history file names, and archive-status file names.
- */
-#define MAXFNAMELEN 64
-
-/* Length of XLog file name */
-#define XLOG_FNAME_LEN 24
-
-/*
- * Generate a WAL segment file name. Do not use this function in a helper
- * function allocating the result generated.
- */
-static inline void
-XLogFileName(char *fname, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)
-{
- snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli,
- (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
- (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)));
-}
-
-static inline void
-XLogFileNameById(char *fname, TimeLineID tli, uint32 log, uint32 seg)
-{
- snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, log, seg);
-}
-
-static inline bool
-IsXLogFileName(const char *fname)
-{
- return (strlen(fname) == XLOG_FNAME_LEN && \
- strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN);
-}
-
-/*
- * XLOG segment with .partial suffix. Used by pg_receivewal and at end of
- * archive recovery, when we want to archive a WAL segment but it might not
- * be complete yet.
- */
-static inline bool
-IsPartialXLogFileName(const char *fname)
-{
- return (strlen(fname) == XLOG_FNAME_LEN + strlen(".partial") &&
- strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN &&
- strcmp(fname + XLOG_FNAME_LEN, ".partial") == 0);
-}
-
-static inline void
-XLogFromFileName(const char *fname, TimeLineID *tli, XLogSegNo *logSegNo, int wal_segsz_bytes)
-{
- uint32 log;
- uint32 seg;
-
- sscanf(fname, "%08X%08X%08X", tli, &log, &seg);
- *logSegNo = (uint64) log * XLogSegmentsPerXLogId(wal_segsz_bytes) + seg;
-}
-
-static inline void
-XLogFilePath(char *path, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)
-{
- snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X", tli,
- (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
- (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)));
-}
-
-static inline void
-TLHistoryFileName(char *fname, TimeLineID tli)
-{
- snprintf(fname, MAXFNAMELEN, "%08X.history", tli);
-}
-
-static inline bool
-IsTLHistoryFileName(const char *fname)
-{
- return (strlen(fname) == 8 + strlen(".history") &&
- strspn(fname, "0123456789ABCDEF") == 8 &&
- strcmp(fname + 8, ".history") == 0);
-}
-
-static inline void
-TLHistoryFilePath(char *path, TimeLineID tli)
-{
- snprintf(path, MAXPGPATH, XLOGDIR "/%08X.history", tli);
-}
-
-static inline void
-StatusFilePath(char *path, const char *xlog, const char *suffix)
-{
- snprintf(path, MAXPGPATH, XLOGDIR "/archive_status/%s%s", xlog, suffix);
-}
-
-static inline void
-BackupHistoryFileName(char *fname, TimeLineID tli, XLogSegNo logSegNo, XLogRecPtr startpoint, int wal_segsz_bytes)
-{
- snprintf(fname, MAXFNAMELEN, "%08X%08X%08X.%08X.backup", tli,
- (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
- (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)),
- (uint32) (XLogSegmentOffset(startpoint, wal_segsz_bytes)));
-}
-
-static inline bool
-IsBackupHistoryFileName(const char *fname)
-{
- return (strlen(fname) > XLOG_FNAME_LEN &&
- strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN &&
- strcmp(fname + strlen(fname) - strlen(".backup"), ".backup") == 0);
-}
-
-static inline void
-BackupHistoryFilePath(char *path, TimeLineID tli, XLogSegNo logSegNo, XLogRecPtr startpoint, int wal_segsz_bytes)
-{
- snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X.%08X.backup", tli,
- (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
- (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)),
- (uint32) (XLogSegmentOffset((startpoint), wal_segsz_bytes)));
-}
/*
* Information logged when we detect a change in one of the parameters
diff --git a/src/include/access/xlogfilepaths.h b/src/include/access/xlogfilepaths.h
new file mode 100644
index 0000000000..cdde2ccae4
--- /dev/null
+++ b/src/include/access/xlogfilepaths.h
@@ -0,0 +1,219 @@
+/*
+ * xlogfilepaths.h
+ *
+ * File name definitions and handling macros for PostgreSQL write-ahead logs.
+ *
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/include/access/xlogfilepaths.h
+ */
+#ifndef XLOG_FILEPATHS_H
+#define XLOG_FILEPATHS_H
+
+#include "access/xlogdefs.h"
+
+/*
+ * The XLog directory and files (relative to $PGDATA)
+ */
+#define XLOGDIR "pg_wal"
+
+/* control files */
+#define XLOG_CONTROL_FILE "global/pg_control"
+#define BACKUP_LABEL_FILE "backup_label"
+#define BACKUP_LABEL_OLD "backup_label.old"
+
+/* tablespace map */
+#define TABLESPACE_MAP "tablespace_map"
+#define TABLESPACE_MAP_OLD "tablespace_map.old"
+
+/* files to signal run mode to standby */
+#define RECOVERY_SIGNAL_FILE "recovery.signal"
+#define STANDBY_SIGNAL_FILE "standby.signal"
+
+/* files to signal promotion to primary */
+#define PROMOTE_SIGNAL_FILE "promote"
+
+/* wal_segment_size can range from 1MB to 1GB */
+#define WalSegMinSize 1024 * 1024
+#define WalSegMaxSize 1024 * 1024 * 1024
+
+/* default number of min and max wal segments */
+#define DEFAULT_MIN_WAL_SEGS 5
+#define DEFAULT_MAX_WAL_SEGS 64
+
+
+/*
+ * These macros encapsulate knowledge about the exact layout of XLog file
+ * names, timeline history file names, and archive-status file names.
+ */
+#define MAXFNAMELEN 64
+
+/* Length of XLog file name */
+#define XLOG_FNAME_LEN 24
+
+/* check that the given size is a valid wal_segment_size */
+#define IsPowerOf2(x) (x > 0 && ((x) & ((x)-1)) == 0)
+#define IsValidWalSegSize(size) \
+ (IsPowerOf2(size) && \
+ ((size) >= WalSegMinSize && (size) <= WalSegMaxSize))
+
+/* Number of segments in a logical XLOG file */
+#define XLogSegmentsPerXLogId(wal_segsz_bytes) \
+ (UINT64CONST(0x100000000) / (wal_segsz_bytes))
+
+/*
+ * Compute an XLogRecPtr from a segment number and offset.
+ */
+#define XLogSegNoOffsetToRecPtr(segno, offset, wal_segsz_bytes, dest) \
+ (dest) = (segno) * (wal_segsz_bytes) + (offset)
+/*
+ * Compute a segment number from an XLogRecPtr.
+ *
+ * For XLByteToSeg, do the computation at face value. For XLByteToPrevSeg,
+ * a boundary byte is taken to be in the previous segment. This is suitable
+ * for deciding which segment to write given a pointer to a record end,
+ * for example.
+ */
+#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ logSegNo = (xlrp) / (wal_segsz_bytes)
+
+#define XLByteToPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ logSegNo = ((xlrp) - 1) / (wal_segsz_bytes)
+
+/* Compute the in-segment offset from an XLogRecPtr. */
+#define XLogSegmentOffset(xlogptr, wal_segsz_bytes) \
+ ((xlogptr) & ((wal_segsz_bytes) - 1))
+
+/*
+ * Convert values of GUCs measured in megabytes to equiv. segment count.
+ * Rounds down.
+ */
+#define XLogMBVarToSegs(mbvar, wal_segsz_bytes) \
+ ((mbvar) / ((wal_segsz_bytes) / (1024 * 1024)))
+
+/*
+ * Is an XLogRecPtr within a particular XLOG segment?
+ *
+ * For XLByteInSeg, do the computation at face value. For XLByteInPrevSeg,
+ * a boundary byte is taken to be in the previous segment.
+ */
+#define XLByteInSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ (((xlrp) / (wal_segsz_bytes)) == (logSegNo))
+
+#define XLByteInPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ ((((xlrp) - 1) / (wal_segsz_bytes)) == (logSegNo))
+
+/*
+ * XLOG file name handling functions
+ */
+static inline void
+StatusFilePath(char *path, const char *xlog, const char *suffix)
+{
+ snprintf(path, MAXPGPATH, XLOGDIR "/archive_status/%s%s", xlog, suffix);
+}
+
+static inline bool
+IsTLHistoryFileName(const char *fname)
+{
+ return (strlen(fname) == 8 + strlen(".history") &&
+ strspn(fname, "0123456789ABCDEF") == 8 &&
+ strcmp(fname + 8, ".history") == 0);
+}
+
+static inline void
+XLogFromFileName(const char *fname, TimeLineID *tli, XLogSegNo *logSegNo, int wal_segsz_bytes)
+{
+ uint32 log;
+ uint32 seg;
+
+ sscanf(fname, "%08X%08X%08X", tli, &log, &seg);
+ *logSegNo = (uint64) log * XLogSegmentsPerXLogId(wal_segsz_bytes) + seg;
+}
+
+static inline void
+XLogFilePath(char *path, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)
+{
+ snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X", tli,
+ (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
+ (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)));
+}
+
+/*
+ * Generate a WAL segment file name. Do not use this function in a helper
+ * function allocating the result generated.
+ */
+static inline void
+XLogFileName(char *fname, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)
+{
+ snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli,
+ (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
+ (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)));
+}
+
+static inline void
+XLogFileNameById(char *fname, TimeLineID tli, uint32 log, uint32 seg)
+{
+ snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, log, seg);
+}
+
+static inline bool
+IsXLogFileName(const char *fname)
+{
+ return (strlen(fname) == XLOG_FNAME_LEN && \
+ strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN);
+}
+
+/*
+ * XLOG segment with .partial suffix. Used by pg_receivewal and at end of
+ * archive recovery, when we want to archive a WAL segment but it might not
+ * be complete yet.
+ */
+static inline bool
+IsPartialXLogFileName(const char *fname)
+{
+ return (strlen(fname) == XLOG_FNAME_LEN + strlen(".partial") &&
+ strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN &&
+ strcmp(fname + XLOG_FNAME_LEN, ".partial") == 0);
+}
+
+static inline void
+TLHistoryFileName(char *fname, TimeLineID tli)
+{
+ snprintf(fname, MAXFNAMELEN, "%08X.history", tli);
+}
+
+static inline void
+TLHistoryFilePath(char *path, TimeLineID tli)
+{
+ snprintf(path, MAXPGPATH, XLOGDIR "/%08X.history", tli);
+}
+
+static inline void
+BackupHistoryFileName(char *fname, TimeLineID tli, XLogSegNo logSegNo, XLogRecPtr startpoint, int wal_segsz_bytes)
+{
+ snprintf(fname, MAXFNAMELEN, "%08X%08X%08X.%08X.backup", tli,
+ (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
+ (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)),
+ (uint32) (XLogSegmentOffset(startpoint, wal_segsz_bytes)));
+}
+
+static inline bool
+IsBackupHistoryFileName(const char *fname)
+{
+ return (strlen(fname) > XLOG_FNAME_LEN &&
+ strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN &&
+ strcmp(fname + strlen(fname) - strlen(".backup"), ".backup") == 0);
+}
+
+static inline void
+BackupHistoryFilePath(char *path, TimeLineID tli, XLogSegNo logSegNo, XLogRecPtr startpoint, int wal_segsz_bytes)
+{
+ snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X.%08X.backup", tli,
+ (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
+ (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)),
+ (uint32) (XLogSegmentOffset((startpoint), wal_segsz_bytes)));
+}
+
+
+#endif /* XLOG_FILEPATHS_H */
--
2.43.5
0002-Use-XLOG_CONTROL_FILE-macro-everywhere-in-C-code.patchtext/x-patch; charset=us-asciiDownload
From 813c3ff42886ecff5d038ffd5de44db488143841 Mon Sep 17 00:00:00 2001
From: "Anton A. Melnikov" <a.melnikov@postgrespro.ru>
Date: Wed, 4 Sep 2024 16:23:23 +0900
Subject: [PATCH 2/2] Use XLOG_CONTROL_FILE macro everywhere in C code
---
src/backend/backup/basebackup.c | 2 +-
src/backend/postmaster/postmaster.c | 2 +-
src/bin/pg_combinebackup/pg_combinebackup.c | 5 +++--
src/bin/pg_controldata/pg_controldata.c | 3 ++-
src/bin/pg_rewind/filemap.c | 3 ++-
src/bin/pg_rewind/pg_rewind.c | 8 ++++----
src/bin/pg_upgrade/controldata.c | 9 +++++----
src/bin/pg_verifybackup/pg_verifybackup.c | 3 ++-
src/common/controldata_utils.c | 2 +-
9 files changed, 21 insertions(+), 16 deletions(-)
diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c
index 14e5ba72e9..bfa101b551 100644
--- a/src/backend/backup/basebackup.c
+++ b/src/backend/backup/basebackup.c
@@ -1348,7 +1348,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)
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 96bc1d1cfe..bc5b0902c2 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -1463,7 +1463,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)
diff --git a/src/bin/pg_combinebackup/pg_combinebackup.c b/src/bin/pg_combinebackup/pg_combinebackup.c
index 6183d31715..def9a114d3 100644
--- a/src/bin/pg_combinebackup/pg_combinebackup.c
+++ b/src/bin/pg_combinebackup/pg_combinebackup.c
@@ -24,6 +24,7 @@
#include <linux/fs.h>
#endif
+#include "access/xlogfilepaths.h"
#include "backup_label.h"
#include "common/blkreftable.h"
#include "common/checksum_helper.h"
@@ -296,7 +297,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 %llu, but control file has %llu",
controlpath,
@@ -605,7 +606,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);
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index 233230712a..feba967221 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -1,7 +1,8 @@
/*
* pg_controldata
*
- * reads the data from $PGDATA/global/pg_control
+ * reads the data from reads the data from the control file
+ * which is located at $PGDATA/XLOG_CONTROL_FILE
*
* copyright (c) Oliver Elphick <olly@lfix.co.uk>, 2001;
* license: BSD
diff --git a/src/bin/pg_rewind/filemap.c b/src/bin/pg_rewind/filemap.c
index 00e644d988..dd4745f0bb 100644
--- a/src/bin/pg_rewind/filemap.c
+++ b/src/bin/pg_rewind/filemap.c
@@ -26,6 +26,7 @@
#include <sys/stat.h>
#include <unistd.h>
+#include "access/xlogfilepaths.h"
#include "catalog/pg_tablespace_d.h"
#include "common/file_utils.h"
#include "common/hashfn_unstable.h"
@@ -643,7 +644,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 */
diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c
index c4b97abd03..b683787fbe 100644
--- a/src/bin/pg_rewind/pg_rewind.c
+++ b/src/bin/pg_rewind/pg_rewind.c
@@ -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);
@@ -631,7 +631,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);
diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c
index 854c6887a2..7af0f82847 100644
--- a/src/bin/pg_upgrade/controldata.c
+++ b/src/bin/pg_upgrade/controldata.c
@@ -11,6 +11,7 @@
#include <ctype.h>
+#include "access/xlogfilepaths.h"
#include "common/string.h"
#include "pg_upgrade.h"
@@ -715,10 +716,10 @@ disable_old_cluster(void)
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);
@@ -726,7 +727,7 @@ disable_old_cluster(void)
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/" XLOG_CONTROL_FILE ".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);
diff --git a/src/bin/pg_verifybackup/pg_verifybackup.c b/src/bin/pg_verifybackup/pg_verifybackup.c
index 3fcfb16721..dabce020a9 100644
--- a/src/bin/pg_verifybackup/pg_verifybackup.c
+++ b/src/bin/pg_verifybackup/pg_verifybackup.c
@@ -18,6 +18,7 @@
#include <sys/stat.h>
#include <time.h>
+#include "access/xlogfilepaths.h"
#include "common/logging.h"
#include "common/parse_manifest.h"
#include "fe_utils/simple_list.h"
@@ -654,7 +655,7 @@ verify_backup_file(verifier_context *context, char *relpath, char *fullpath)
* 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 */
diff --git a/src/common/controldata_utils.c b/src/common/controldata_utils.c
index 82309b2510..411139eeb0 100644
--- a/src/common/controldata_utils.c
+++ b/src/common/controldata_utils.c
@@ -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);
}
--
2.43.5
On 04.09.2024 11:09, Kyotaro Horiguchi wrote:
Instead, I'd like to propose separating the file and
path-related definitions from xlog_internal.h, as shown in the
attached first patch. This change would allow some modules to include
files without unnecessary details.The second file is your patch, adjusted based on the first patch.
I’d appreciate hearing from others on whether they find the first
patch worthwhile. If it’s not considered worthwhile, then I believe
having postmaster include xlog_internal.h would be the best approach.
I really liked the idea of extracting only the necessary and logically
complete part from xlog_internal.h.
But now the presence of macros related to the segment sizes
in the xlogfilepaths.h seems does not correspond to its name.
So i suggest further extract size-related definition and macros from
xlogfilepaths.h to xlogfilesize.h.
Here is a patch that tries to do this based on the your first patch.
Would be glad to hear your opinion.
With the best wishes,
--
Anton A. Melnikov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
Attachments:
0001-Extract-size-related-macros-to-separate-header.patchtext/x-patch; charset=UTF-8; name=0001-Extract-size-related-macros-to-separate-header.patchDownload
From 4b6a12f6eaac98ee22dd63d64431968357905d77 Mon Sep 17 00:00:00 2001
From: "Anton A. Melnikov" <a.melnikov@postgrespro.ru>
Date: Sat, 7 Sep 2024 10:18:51 +0300
Subject: [PATCH] Extract size-related macros from xlogfilepaths.h to
xlogfilesize.h
---
src/include/access/xlogfilepaths.h | 65 +----------------------
src/include/access/xlogfilesize.h | 83 ++++++++++++++++++++++++++++++
2 files changed, 85 insertions(+), 63 deletions(-)
create mode 100644 src/include/access/xlogfilesize.h
diff --git a/src/include/access/xlogfilepaths.h b/src/include/access/xlogfilepaths.h
index cdde2ccae4..ed28cf975e 100644
--- a/src/include/access/xlogfilepaths.h
+++ b/src/include/access/xlogfilepaths.h
@@ -12,6 +12,7 @@
#define XLOG_FILEPATHS_H
#include "access/xlogdefs.h"
+#include "access/xlogfilesize.h"
/*
* The XLog directory and files (relative to $PGDATA)
@@ -34,75 +35,13 @@
/* files to signal promotion to primary */
#define PROMOTE_SIGNAL_FILE "promote"
-/* wal_segment_size can range from 1MB to 1GB */
-#define WalSegMinSize 1024 * 1024
-#define WalSegMaxSize 1024 * 1024 * 1024
-/* default number of min and max wal segments */
-#define DEFAULT_MIN_WAL_SEGS 5
-#define DEFAULT_MAX_WAL_SEGS 64
-
-
-/*
- * These macros encapsulate knowledge about the exact layout of XLog file
- * names, timeline history file names, and archive-status file names.
- */
+/* Maximum length of XLog file name including possible suffix */
#define MAXFNAMELEN 64
/* Length of XLog file name */
#define XLOG_FNAME_LEN 24
-/* check that the given size is a valid wal_segment_size */
-#define IsPowerOf2(x) (x > 0 && ((x) & ((x)-1)) == 0)
-#define IsValidWalSegSize(size) \
- (IsPowerOf2(size) && \
- ((size) >= WalSegMinSize && (size) <= WalSegMaxSize))
-
-/* Number of segments in a logical XLOG file */
-#define XLogSegmentsPerXLogId(wal_segsz_bytes) \
- (UINT64CONST(0x100000000) / (wal_segsz_bytes))
-
-/*
- * Compute an XLogRecPtr from a segment number and offset.
- */
-#define XLogSegNoOffsetToRecPtr(segno, offset, wal_segsz_bytes, dest) \
- (dest) = (segno) * (wal_segsz_bytes) + (offset)
-/*
- * Compute a segment number from an XLogRecPtr.
- *
- * For XLByteToSeg, do the computation at face value. For XLByteToPrevSeg,
- * a boundary byte is taken to be in the previous segment. This is suitable
- * for deciding which segment to write given a pointer to a record end,
- * for example.
- */
-#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes) \
- logSegNo = (xlrp) / (wal_segsz_bytes)
-
-#define XLByteToPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
- logSegNo = ((xlrp) - 1) / (wal_segsz_bytes)
-
-/* Compute the in-segment offset from an XLogRecPtr. */
-#define XLogSegmentOffset(xlogptr, wal_segsz_bytes) \
- ((xlogptr) & ((wal_segsz_bytes) - 1))
-
-/*
- * Convert values of GUCs measured in megabytes to equiv. segment count.
- * Rounds down.
- */
-#define XLogMBVarToSegs(mbvar, wal_segsz_bytes) \
- ((mbvar) / ((wal_segsz_bytes) / (1024 * 1024)))
-
-/*
- * Is an XLogRecPtr within a particular XLOG segment?
- *
- * For XLByteInSeg, do the computation at face value. For XLByteInPrevSeg,
- * a boundary byte is taken to be in the previous segment.
- */
-#define XLByteInSeg(xlrp, logSegNo, wal_segsz_bytes) \
- (((xlrp) / (wal_segsz_bytes)) == (logSegNo))
-
-#define XLByteInPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
- ((((xlrp) - 1) / (wal_segsz_bytes)) == (logSegNo))
/*
* XLOG file name handling functions
diff --git a/src/include/access/xlogfilesize.h b/src/include/access/xlogfilesize.h
new file mode 100644
index 0000000000..fef30e02a6
--- /dev/null
+++ b/src/include/access/xlogfilesize.h
@@ -0,0 +1,83 @@
+/*
+ * xlogfilesize.h
+ *
+ * Size definitions and handling macros for PostgreSQL write-ahead logs.
+ *
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/include/access/xlogfilesize.h
+ */
+
+#ifndef XLOG_FILESIZE_H
+#define XLOG_FILESIZE_H
+
+#include "access/xlogdefs.h"
+
+/* wal_segment_size can range from 1MB to 1GB */
+#define WalSegMinSize 1024 * 1024
+#define WalSegMaxSize 1024 * 1024 * 1024
+
+/* default number of min and max wal segments */
+#define DEFAULT_MIN_WAL_SEGS 5
+#define DEFAULT_MAX_WAL_SEGS 64
+
+/*
+ * These macros encapsulate knowledge about the exact layout of XLog
+ * files, timeline history fils and archive-status fils.
+ */
+
+/* check that the given size is a valid wal_segment_size */
+#define IsPowerOf2(x) (x > 0 && ((x) & ((x)-1)) == 0)
+#define IsValidWalSegSize(size) \
+ (IsPowerOf2(size) && \
+ ((size) >= WalSegMinSize && (size) <= WalSegMaxSize))
+
+/* Number of segments in a logical XLOG file */
+#define XLogSegmentsPerXLogId(wal_segsz_bytes) \
+ (UINT64CONST(0x100000000) / (wal_segsz_bytes))
+
+/*
+ * Compute an XLogRecPtr from a segment number and offset.
+ */
+#define XLogSegNoOffsetToRecPtr(segno, offset, wal_segsz_bytes, dest) \
+ (dest) = (segno) * (wal_segsz_bytes) + (offset)
+/*
+ * Compute a segment number from an XLogRecPtr.
+ *
+ * For XLByteToSeg, do the computation at face value. For XLByteToPrevSeg,
+ * a boundary byte is taken to be in the previous segment. This is suitable
+ * for deciding which segment to write given a pointer to a record end,
+ * for example.
+ */
+#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ logSegNo = (xlrp) / (wal_segsz_bytes)
+
+#define XLByteToPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ logSegNo = ((xlrp) - 1) / (wal_segsz_bytes)
+
+/* Compute the in-segment offset from an XLogRecPtr. */
+#define XLogSegmentOffset(xlogptr, wal_segsz_bytes) \
+ ((xlogptr) & ((wal_segsz_bytes) - 1))
+
+/*
+ * Convert values of GUCs measured in megabytes to equiv. segment count.
+ * Rounds down.
+ */
+#define XLogMBVarToSegs(mbvar, wal_segsz_bytes) \
+ ((mbvar) / ((wal_segsz_bytes) / (1024 * 1024)))
+
+/*
+ * Is an XLogRecPtr within a particular XLOG segment?
+ *
+ * For XLByteInSeg, do the computation at face value. For XLByteInPrevSeg,
+ * a boundary byte is taken to be in the previous segment.
+ */
+#define XLByteInSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ (((xlrp) / (wal_segsz_bytes)) == (logSegNo))
+
+#define XLByteInPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ ((((xlrp) - 1) / (wal_segsz_bytes)) == (logSegNo))
+
+
+#endif /* XLOG_FILESIZE_H */
--
2.46.0
Rebased all patches on the current master, renumbered
them to be linear and marked as v3 version.
With the best regards,
--
Anton A. Melnikov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
Attachments:
v3-0001-Split-file-related-parts-from-xlog_internal.h.patchtext/x-patch; charset=UTF-8; name=v3-0001-Split-file-related-parts-from-xlog_internal.h.patchDownload
From 84ae0a626d5820f93a3423a518becb6dafc0a2af Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Date: Wed, 4 Sep 2024 16:15:16 +0900
Subject: [PATCH] Split file-related parts from xlog_internal.h
Some modules that require XLOG file manipulation had to include
xlog_internal.h, which contains excessively detailed internal
information. This commit separates the file and file path-related
components into xlogfilepaths.h, thereby avoiding the exposure of
unrelated details of the XLOG module.
---
src/backend/access/transam/timeline.c | 1 -
src/backend/postmaster/pgarch.c | 1 -
src/backend/utils/adt/genfile.c | 1 -
src/bin/initdb/initdb.c | 1 +
src/bin/pg_archivecleanup/pg_archivecleanup.c | 2 +-
src/bin/pg_basebackup/pg_basebackup.c | 4 +-
src/bin/pg_basebackup/pg_receivewal.c | 1 +
src/bin/pg_basebackup/receivelog.c | 2 +-
src/bin/pg_basebackup/streamutil.c | 2 +-
src/bin/pg_controldata/pg_controldata.c | 1 -
src/bin/pg_rewind/pg_rewind.c | 2 +-
src/include/access/xlog.h | 13 +-
src/include/access/xlog_internal.h | 178 +-------------
src/include/access/xlogfilepaths.h | 219 ++++++++++++++++++
14 files changed, 230 insertions(+), 198 deletions(-)
create mode 100644 src/include/access/xlogfilepaths.h
diff --git a/src/backend/access/transam/timeline.c b/src/backend/access/transam/timeline.c
index a27f27cc037..710e92297e3 100644
--- a/src/backend/access/transam/timeline.c
+++ b/src/backend/access/transam/timeline.c
@@ -38,7 +38,6 @@
#include "access/xlog.h"
#include "access/xlog_internal.h"
#include "access/xlogarchive.h"
-#include "access/xlogdefs.h"
#include "pgstat.h"
#include "storage/fd.h"
diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c
index 7e622ae4bd2..4db8a00b849 100644
--- a/src/backend/postmaster/pgarch.c
+++ b/src/backend/postmaster/pgarch.c
@@ -30,7 +30,6 @@
#include <unistd.h>
#include "access/xlog.h"
-#include "access/xlog_internal.h"
#include "archive/archive_module.h"
#include "archive/shell_archive.h"
#include "lib/binaryheap.h"
diff --git a/src/backend/utils/adt/genfile.c b/src/backend/utils/adt/genfile.c
index 80bb807fbe9..af4c148c809 100644
--- a/src/backend/utils/adt/genfile.c
+++ b/src/backend/utils/adt/genfile.c
@@ -21,7 +21,6 @@
#include <dirent.h>
#include "access/htup_details.h"
-#include "access/xlog_internal.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_tablespace_d.h"
#include "catalog/pg_type.h"
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index 21a0fe3ecd9..f728e0fa802 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -65,6 +65,7 @@
#endif
#include "access/xlog_internal.h"
+#include "lib/stringinfo.h"
#include "catalog/pg_authid_d.h"
#include "catalog/pg_class_d.h"
#include "catalog/pg_collation_d.h"
diff --git a/src/bin/pg_archivecleanup/pg_archivecleanup.c b/src/bin/pg_archivecleanup/pg_archivecleanup.c
index c25348bcb85..edf1828bc73 100644
--- a/src/bin/pg_archivecleanup/pg_archivecleanup.c
+++ b/src/bin/pg_archivecleanup/pg_archivecleanup.c
@@ -15,7 +15,7 @@
#include <signal.h>
#include <sys/time.h>
-#include "access/xlog_internal.h"
+#include "access/xlogfilepaths.h"
#include "common/logging.h"
#include "getopt_long.h"
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index d4b4e334014..d981bb4c282 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -25,7 +25,7 @@
#include <zlib.h>
#endif
-#include "access/xlog_internal.h"
+#include "access/xlogfilepaths.h"
#include "astreamer_inject.h"
#include "backup/basebackup.h"
#include "common/compression.h"
@@ -35,6 +35,8 @@
#include "fe_utils/option_utils.h"
#include "fe_utils/recovery_gen.h"
#include "getopt_long.h"
+#include "pgtime.h"
+#include "port/pg_bswap.h"
#include "receivelog.h"
#include "streamutil.h"
diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c
index de3584018b0..4facc35f845 100644
--- a/src/bin/pg_basebackup/pg_receivewal.c
+++ b/src/bin/pg_basebackup/pg_receivewal.c
@@ -27,6 +27,7 @@
#include <zlib.h>
#endif
+//#include "access/xlogfilepaths.h"
#include "access/xlog_internal.h"
#include "common/file_perm.h"
#include "common/logging.h"
diff --git a/src/bin/pg_basebackup/receivelog.c b/src/bin/pg_basebackup/receivelog.c
index 6b6e32dfbdf..4f72ed42e11 100644
--- a/src/bin/pg_basebackup/receivelog.c
+++ b/src/bin/pg_basebackup/receivelog.c
@@ -18,7 +18,7 @@
#include <sys/stat.h>
#include <unistd.h>
-#include "access/xlog_internal.h"
+#include "access/xlogfilepaths.h"
#include "common/logging.h"
#include "libpq-fe.h"
#include "receivelog.h"
diff --git a/src/bin/pg_basebackup/streamutil.c b/src/bin/pg_basebackup/streamutil.c
index 8e605f43ffe..62eb0586dc4 100644
--- a/src/bin/pg_basebackup/streamutil.c
+++ b/src/bin/pg_basebackup/streamutil.c
@@ -17,7 +17,7 @@
#include <sys/time.h>
#include <unistd.h>
-#include "access/xlog_internal.h"
+#include "access/xlogfilepaths.h"
#include "common/connect.h"
#include "common/file_perm.h"
#include "common/logging.h"
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index bea779eef94..162f087626d 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -22,7 +22,6 @@
#include "access/transam.h"
#include "access/xlog.h"
-#include "access/xlog_internal.h"
#include "catalog/pg_control.h"
#include "common/controldata_utils.h"
#include "common/logging.h"
diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c
index 2c8b1a07007..a625105fbcc 100644
--- a/src/bin/pg_rewind/pg_rewind.c
+++ b/src/bin/pg_rewind/pg_rewind.c
@@ -15,7 +15,7 @@
#include <unistd.h>
#include "access/timeline.h"
-#include "access/xlog_internal.h"
+#include "access/xlogfilepaths.h"
#include "catalog/catversion.h"
#include "catalog/pg_control.h"
#include "common/controldata_utils.h"
diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h
index d313099c027..7ef9264fabc 100644
--- a/src/include/access/xlog.h
+++ b/src/include/access/xlog.h
@@ -16,6 +16,7 @@
#include "datatype/timestamp.h"
#include "lib/stringinfo.h"
#include "nodes/pg_list.h"
+#include "access/xlogfilepaths.h"
/* Sync methods */
@@ -299,16 +300,4 @@ extern void do_pg_abort_backup(int code, Datum arg);
extern void register_persistent_abort_backup_handler(void);
extern SessionBackupState get_backup_status(void);
-/* File path names (all relative to $PGDATA) */
-#define RECOVERY_SIGNAL_FILE "recovery.signal"
-#define STANDBY_SIGNAL_FILE "standby.signal"
-#define BACKUP_LABEL_FILE "backup_label"
-#define BACKUP_LABEL_OLD "backup_label.old"
-
-#define TABLESPACE_MAP "tablespace_map"
-#define TABLESPACE_MAP_OLD "tablespace_map.old"
-
-/* files to signal promotion to primary */
-#define PROMOTE_SIGNAL_FILE "promote"
-
#endif /* XLOG_H */
diff --git a/src/include/access/xlog_internal.h b/src/include/access/xlog_internal.h
index 2cf8d55d706..5e846e48073 100644
--- a/src/include/access/xlog_internal.h
+++ b/src/include/access/xlog_internal.h
@@ -21,6 +21,7 @@
#include "access/xlogdefs.h"
#include "access/xlogreader.h"
+#include "access/xlogfilepaths.h"
#include "datatype/timestamp.h"
#include "lib/stringinfo.h"
#include "pgtime.h"
@@ -84,187 +85,10 @@ typedef XLogLongPageHeaderData *XLogLongPageHeader;
#define XLogPageHeaderSize(hdr) \
(((hdr)->xlp_info & XLP_LONG_HEADER) ? SizeOfXLogLongPHD : SizeOfXLogShortPHD)
-/* wal_segment_size can range from 1MB to 1GB */
-#define WalSegMinSize 1024 * 1024
-#define WalSegMaxSize 1024 * 1024 * 1024
-/* default number of min and max wal segments */
-#define DEFAULT_MIN_WAL_SEGS 5
-#define DEFAULT_MAX_WAL_SEGS 64
-
-/* check that the given size is a valid wal_segment_size */
-#define IsPowerOf2(x) (x > 0 && ((x) & ((x)-1)) == 0)
-#define IsValidWalSegSize(size) \
- (IsPowerOf2(size) && \
- ((size) >= WalSegMinSize && (size) <= WalSegMaxSize))
-
-#define XLogSegmentsPerXLogId(wal_segsz_bytes) \
- (UINT64CONST(0x100000000) / (wal_segsz_bytes))
-
-#define XLogSegNoOffsetToRecPtr(segno, offset, wal_segsz_bytes, dest) \
- (dest) = (segno) * (wal_segsz_bytes) + (offset)
-
-#define XLogSegmentOffset(xlogptr, wal_segsz_bytes) \
- ((xlogptr) & ((wal_segsz_bytes) - 1))
-
-/*
- * Compute a segment number from an XLogRecPtr.
- *
- * For XLByteToSeg, do the computation at face value. For XLByteToPrevSeg,
- * a boundary byte is taken to be in the previous segment. This is suitable
- * for deciding which segment to write given a pointer to a record end,
- * for example.
- */
-#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes) \
- logSegNo = (xlrp) / (wal_segsz_bytes)
-
-#define XLByteToPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
- logSegNo = ((xlrp) - 1) / (wal_segsz_bytes)
-
-/*
- * Convert values of GUCs measured in megabytes to equiv. segment count.
- * Rounds down.
- */
-#define XLogMBVarToSegs(mbvar, wal_segsz_bytes) \
- ((mbvar) / ((wal_segsz_bytes) / (1024 * 1024)))
-
-/*
- * Is an XLogRecPtr within a particular XLOG segment?
- *
- * For XLByteInSeg, do the computation at face value. For XLByteInPrevSeg,
- * a boundary byte is taken to be in the previous segment.
- */
-#define XLByteInSeg(xlrp, logSegNo, wal_segsz_bytes) \
- (((xlrp) / (wal_segsz_bytes)) == (logSegNo))
-
-#define XLByteInPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
- ((((xlrp) - 1) / (wal_segsz_bytes)) == (logSegNo))
-
/* Check if an XLogRecPtr value is in a plausible range */
#define XRecOffIsValid(xlrp) \
((xlrp) % XLOG_BLCKSZ >= SizeOfXLogShortPHD)
-/*
- * The XLog directory and control file (relative to $PGDATA)
- */
-#define XLOGDIR "pg_wal"
-#define XLOG_CONTROL_FILE "global/pg_control"
-
-/*
- * These macros encapsulate knowledge about the exact layout of XLog file
- * names, timeline history file names, and archive-status file names.
- */
-#define MAXFNAMELEN 64
-
-/* Length of XLog file name */
-#define XLOG_FNAME_LEN 24
-
-/*
- * Generate a WAL segment file name. Do not use this function in a helper
- * function allocating the result generated.
- */
-static inline void
-XLogFileName(char *fname, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)
-{
- snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli,
- (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
- (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)));
-}
-
-static inline void
-XLogFileNameById(char *fname, TimeLineID tli, uint32 log, uint32 seg)
-{
- snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, log, seg);
-}
-
-static inline bool
-IsXLogFileName(const char *fname)
-{
- return (strlen(fname) == XLOG_FNAME_LEN && \
- strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN);
-}
-
-/*
- * XLOG segment with .partial suffix. Used by pg_receivewal and at end of
- * archive recovery, when we want to archive a WAL segment but it might not
- * be complete yet.
- */
-static inline bool
-IsPartialXLogFileName(const char *fname)
-{
- return (strlen(fname) == XLOG_FNAME_LEN + strlen(".partial") &&
- strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN &&
- strcmp(fname + XLOG_FNAME_LEN, ".partial") == 0);
-}
-
-static inline void
-XLogFromFileName(const char *fname, TimeLineID *tli, XLogSegNo *logSegNo, int wal_segsz_bytes)
-{
- uint32 log;
- uint32 seg;
-
- sscanf(fname, "%08X%08X%08X", tli, &log, &seg);
- *logSegNo = (uint64) log * XLogSegmentsPerXLogId(wal_segsz_bytes) + seg;
-}
-
-static inline void
-XLogFilePath(char *path, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)
-{
- snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X", tli,
- (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
- (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)));
-}
-
-static inline void
-TLHistoryFileName(char *fname, TimeLineID tli)
-{
- snprintf(fname, MAXFNAMELEN, "%08X.history", tli);
-}
-
-static inline bool
-IsTLHistoryFileName(const char *fname)
-{
- return (strlen(fname) == 8 + strlen(".history") &&
- strspn(fname, "0123456789ABCDEF") == 8 &&
- strcmp(fname + 8, ".history") == 0);
-}
-
-static inline void
-TLHistoryFilePath(char *path, TimeLineID tli)
-{
- snprintf(path, MAXPGPATH, XLOGDIR "/%08X.history", tli);
-}
-
-static inline void
-StatusFilePath(char *path, const char *xlog, const char *suffix)
-{
- snprintf(path, MAXPGPATH, XLOGDIR "/archive_status/%s%s", xlog, suffix);
-}
-
-static inline void
-BackupHistoryFileName(char *fname, TimeLineID tli, XLogSegNo logSegNo, XLogRecPtr startpoint, int wal_segsz_bytes)
-{
- snprintf(fname, MAXFNAMELEN, "%08X%08X%08X.%08X.backup", tli,
- (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
- (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)),
- (uint32) (XLogSegmentOffset(startpoint, wal_segsz_bytes)));
-}
-
-static inline bool
-IsBackupHistoryFileName(const char *fname)
-{
- return (strlen(fname) > XLOG_FNAME_LEN &&
- strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN &&
- strcmp(fname + strlen(fname) - strlen(".backup"), ".backup") == 0);
-}
-
-static inline void
-BackupHistoryFilePath(char *path, TimeLineID tli, XLogSegNo logSegNo, XLogRecPtr startpoint, int wal_segsz_bytes)
-{
- snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X.%08X.backup", tli,
- (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
- (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)),
- (uint32) (XLogSegmentOffset((startpoint), wal_segsz_bytes)));
-}
/*
* Information logged when we detect a change in one of the parameters
diff --git a/src/include/access/xlogfilepaths.h b/src/include/access/xlogfilepaths.h
new file mode 100644
index 00000000000..cdde2ccae4f
--- /dev/null
+++ b/src/include/access/xlogfilepaths.h
@@ -0,0 +1,219 @@
+/*
+ * xlogfilepaths.h
+ *
+ * File name definitions and handling macros for PostgreSQL write-ahead logs.
+ *
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/include/access/xlogfilepaths.h
+ */
+#ifndef XLOG_FILEPATHS_H
+#define XLOG_FILEPATHS_H
+
+#include "access/xlogdefs.h"
+
+/*
+ * The XLog directory and files (relative to $PGDATA)
+ */
+#define XLOGDIR "pg_wal"
+
+/* control files */
+#define XLOG_CONTROL_FILE "global/pg_control"
+#define BACKUP_LABEL_FILE "backup_label"
+#define BACKUP_LABEL_OLD "backup_label.old"
+
+/* tablespace map */
+#define TABLESPACE_MAP "tablespace_map"
+#define TABLESPACE_MAP_OLD "tablespace_map.old"
+
+/* files to signal run mode to standby */
+#define RECOVERY_SIGNAL_FILE "recovery.signal"
+#define STANDBY_SIGNAL_FILE "standby.signal"
+
+/* files to signal promotion to primary */
+#define PROMOTE_SIGNAL_FILE "promote"
+
+/* wal_segment_size can range from 1MB to 1GB */
+#define WalSegMinSize 1024 * 1024
+#define WalSegMaxSize 1024 * 1024 * 1024
+
+/* default number of min and max wal segments */
+#define DEFAULT_MIN_WAL_SEGS 5
+#define DEFAULT_MAX_WAL_SEGS 64
+
+
+/*
+ * These macros encapsulate knowledge about the exact layout of XLog file
+ * names, timeline history file names, and archive-status file names.
+ */
+#define MAXFNAMELEN 64
+
+/* Length of XLog file name */
+#define XLOG_FNAME_LEN 24
+
+/* check that the given size is a valid wal_segment_size */
+#define IsPowerOf2(x) (x > 0 && ((x) & ((x)-1)) == 0)
+#define IsValidWalSegSize(size) \
+ (IsPowerOf2(size) && \
+ ((size) >= WalSegMinSize && (size) <= WalSegMaxSize))
+
+/* Number of segments in a logical XLOG file */
+#define XLogSegmentsPerXLogId(wal_segsz_bytes) \
+ (UINT64CONST(0x100000000) / (wal_segsz_bytes))
+
+/*
+ * Compute an XLogRecPtr from a segment number and offset.
+ */
+#define XLogSegNoOffsetToRecPtr(segno, offset, wal_segsz_bytes, dest) \
+ (dest) = (segno) * (wal_segsz_bytes) + (offset)
+/*
+ * Compute a segment number from an XLogRecPtr.
+ *
+ * For XLByteToSeg, do the computation at face value. For XLByteToPrevSeg,
+ * a boundary byte is taken to be in the previous segment. This is suitable
+ * for deciding which segment to write given a pointer to a record end,
+ * for example.
+ */
+#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ logSegNo = (xlrp) / (wal_segsz_bytes)
+
+#define XLByteToPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ logSegNo = ((xlrp) - 1) / (wal_segsz_bytes)
+
+/* Compute the in-segment offset from an XLogRecPtr. */
+#define XLogSegmentOffset(xlogptr, wal_segsz_bytes) \
+ ((xlogptr) & ((wal_segsz_bytes) - 1))
+
+/*
+ * Convert values of GUCs measured in megabytes to equiv. segment count.
+ * Rounds down.
+ */
+#define XLogMBVarToSegs(mbvar, wal_segsz_bytes) \
+ ((mbvar) / ((wal_segsz_bytes) / (1024 * 1024)))
+
+/*
+ * Is an XLogRecPtr within a particular XLOG segment?
+ *
+ * For XLByteInSeg, do the computation at face value. For XLByteInPrevSeg,
+ * a boundary byte is taken to be in the previous segment.
+ */
+#define XLByteInSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ (((xlrp) / (wal_segsz_bytes)) == (logSegNo))
+
+#define XLByteInPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ ((((xlrp) - 1) / (wal_segsz_bytes)) == (logSegNo))
+
+/*
+ * XLOG file name handling functions
+ */
+static inline void
+StatusFilePath(char *path, const char *xlog, const char *suffix)
+{
+ snprintf(path, MAXPGPATH, XLOGDIR "/archive_status/%s%s", xlog, suffix);
+}
+
+static inline bool
+IsTLHistoryFileName(const char *fname)
+{
+ return (strlen(fname) == 8 + strlen(".history") &&
+ strspn(fname, "0123456789ABCDEF") == 8 &&
+ strcmp(fname + 8, ".history") == 0);
+}
+
+static inline void
+XLogFromFileName(const char *fname, TimeLineID *tli, XLogSegNo *logSegNo, int wal_segsz_bytes)
+{
+ uint32 log;
+ uint32 seg;
+
+ sscanf(fname, "%08X%08X%08X", tli, &log, &seg);
+ *logSegNo = (uint64) log * XLogSegmentsPerXLogId(wal_segsz_bytes) + seg;
+}
+
+static inline void
+XLogFilePath(char *path, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)
+{
+ snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X", tli,
+ (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
+ (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)));
+}
+
+/*
+ * Generate a WAL segment file name. Do not use this function in a helper
+ * function allocating the result generated.
+ */
+static inline void
+XLogFileName(char *fname, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)
+{
+ snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli,
+ (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
+ (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)));
+}
+
+static inline void
+XLogFileNameById(char *fname, TimeLineID tli, uint32 log, uint32 seg)
+{
+ snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, log, seg);
+}
+
+static inline bool
+IsXLogFileName(const char *fname)
+{
+ return (strlen(fname) == XLOG_FNAME_LEN && \
+ strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN);
+}
+
+/*
+ * XLOG segment with .partial suffix. Used by pg_receivewal and at end of
+ * archive recovery, when we want to archive a WAL segment but it might not
+ * be complete yet.
+ */
+static inline bool
+IsPartialXLogFileName(const char *fname)
+{
+ return (strlen(fname) == XLOG_FNAME_LEN + strlen(".partial") &&
+ strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN &&
+ strcmp(fname + XLOG_FNAME_LEN, ".partial") == 0);
+}
+
+static inline void
+TLHistoryFileName(char *fname, TimeLineID tli)
+{
+ snprintf(fname, MAXFNAMELEN, "%08X.history", tli);
+}
+
+static inline void
+TLHistoryFilePath(char *path, TimeLineID tli)
+{
+ snprintf(path, MAXPGPATH, XLOGDIR "/%08X.history", tli);
+}
+
+static inline void
+BackupHistoryFileName(char *fname, TimeLineID tli, XLogSegNo logSegNo, XLogRecPtr startpoint, int wal_segsz_bytes)
+{
+ snprintf(fname, MAXFNAMELEN, "%08X%08X%08X.%08X.backup", tli,
+ (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
+ (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)),
+ (uint32) (XLogSegmentOffset(startpoint, wal_segsz_bytes)));
+}
+
+static inline bool
+IsBackupHistoryFileName(const char *fname)
+{
+ return (strlen(fname) > XLOG_FNAME_LEN &&
+ strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN &&
+ strcmp(fname + strlen(fname) - strlen(".backup"), ".backup") == 0);
+}
+
+static inline void
+BackupHistoryFilePath(char *path, TimeLineID tli, XLogSegNo logSegNo, XLogRecPtr startpoint, int wal_segsz_bytes)
+{
+ snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X.%08X.backup", tli,
+ (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
+ (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)),
+ (uint32) (XLogSegmentOffset((startpoint), wal_segsz_bytes)));
+}
+
+
+#endif /* XLOG_FILEPATHS_H */
--
2.48.1
v3-0002-Extract-size-related-macros-from-xlogfilepaths.h.patchtext/x-patch; charset=UTF-8; name=v3-0002-Extract-size-related-macros-from-xlogfilepaths.h.patchDownload
From a0137b4a2f2437bb0a77c833c3fcf393c5364511 Mon Sep 17 00:00:00 2001
From: "Anton A. Melnikov" <a.melnikov@postgrespro.ru>
Date: Sat, 7 Sep 2024 10:18:51 +0300
Subject: [PATCH] Extract size-related macros from xlogfilepaths.h to
xlogfilesize.h
---
src/include/access/xlogfilepaths.h | 65 +----------------------
src/include/access/xlogfilesize.h | 83 ++++++++++++++++++++++++++++++
2 files changed, 85 insertions(+), 63 deletions(-)
create mode 100644 src/include/access/xlogfilesize.h
diff --git a/src/include/access/xlogfilepaths.h b/src/include/access/xlogfilepaths.h
index cdde2ccae4f..ed28cf975e6 100644
--- a/src/include/access/xlogfilepaths.h
+++ b/src/include/access/xlogfilepaths.h
@@ -12,6 +12,7 @@
#define XLOG_FILEPATHS_H
#include "access/xlogdefs.h"
+#include "access/xlogfilesize.h"
/*
* The XLog directory and files (relative to $PGDATA)
@@ -34,75 +35,13 @@
/* files to signal promotion to primary */
#define PROMOTE_SIGNAL_FILE "promote"
-/* wal_segment_size can range from 1MB to 1GB */
-#define WalSegMinSize 1024 * 1024
-#define WalSegMaxSize 1024 * 1024 * 1024
-/* default number of min and max wal segments */
-#define DEFAULT_MIN_WAL_SEGS 5
-#define DEFAULT_MAX_WAL_SEGS 64
-
-
-/*
- * These macros encapsulate knowledge about the exact layout of XLog file
- * names, timeline history file names, and archive-status file names.
- */
+/* Maximum length of XLog file name including possible suffix */
#define MAXFNAMELEN 64
/* Length of XLog file name */
#define XLOG_FNAME_LEN 24
-/* check that the given size is a valid wal_segment_size */
-#define IsPowerOf2(x) (x > 0 && ((x) & ((x)-1)) == 0)
-#define IsValidWalSegSize(size) \
- (IsPowerOf2(size) && \
- ((size) >= WalSegMinSize && (size) <= WalSegMaxSize))
-
-/* Number of segments in a logical XLOG file */
-#define XLogSegmentsPerXLogId(wal_segsz_bytes) \
- (UINT64CONST(0x100000000) / (wal_segsz_bytes))
-
-/*
- * Compute an XLogRecPtr from a segment number and offset.
- */
-#define XLogSegNoOffsetToRecPtr(segno, offset, wal_segsz_bytes, dest) \
- (dest) = (segno) * (wal_segsz_bytes) + (offset)
-/*
- * Compute a segment number from an XLogRecPtr.
- *
- * For XLByteToSeg, do the computation at face value. For XLByteToPrevSeg,
- * a boundary byte is taken to be in the previous segment. This is suitable
- * for deciding which segment to write given a pointer to a record end,
- * for example.
- */
-#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes) \
- logSegNo = (xlrp) / (wal_segsz_bytes)
-
-#define XLByteToPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
- logSegNo = ((xlrp) - 1) / (wal_segsz_bytes)
-
-/* Compute the in-segment offset from an XLogRecPtr. */
-#define XLogSegmentOffset(xlogptr, wal_segsz_bytes) \
- ((xlogptr) & ((wal_segsz_bytes) - 1))
-
-/*
- * Convert values of GUCs measured in megabytes to equiv. segment count.
- * Rounds down.
- */
-#define XLogMBVarToSegs(mbvar, wal_segsz_bytes) \
- ((mbvar) / ((wal_segsz_bytes) / (1024 * 1024)))
-
-/*
- * Is an XLogRecPtr within a particular XLOG segment?
- *
- * For XLByteInSeg, do the computation at face value. For XLByteInPrevSeg,
- * a boundary byte is taken to be in the previous segment.
- */
-#define XLByteInSeg(xlrp, logSegNo, wal_segsz_bytes) \
- (((xlrp) / (wal_segsz_bytes)) == (logSegNo))
-
-#define XLByteInPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
- ((((xlrp) - 1) / (wal_segsz_bytes)) == (logSegNo))
/*
* XLOG file name handling functions
diff --git a/src/include/access/xlogfilesize.h b/src/include/access/xlogfilesize.h
new file mode 100644
index 00000000000..fef30e02a62
--- /dev/null
+++ b/src/include/access/xlogfilesize.h
@@ -0,0 +1,83 @@
+/*
+ * xlogfilesize.h
+ *
+ * Size definitions and handling macros for PostgreSQL write-ahead logs.
+ *
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/include/access/xlogfilesize.h
+ */
+
+#ifndef XLOG_FILESIZE_H
+#define XLOG_FILESIZE_H
+
+#include "access/xlogdefs.h"
+
+/* wal_segment_size can range from 1MB to 1GB */
+#define WalSegMinSize 1024 * 1024
+#define WalSegMaxSize 1024 * 1024 * 1024
+
+/* default number of min and max wal segments */
+#define DEFAULT_MIN_WAL_SEGS 5
+#define DEFAULT_MAX_WAL_SEGS 64
+
+/*
+ * These macros encapsulate knowledge about the exact layout of XLog
+ * files, timeline history fils and archive-status fils.
+ */
+
+/* check that the given size is a valid wal_segment_size */
+#define IsPowerOf2(x) (x > 0 && ((x) & ((x)-1)) == 0)
+#define IsValidWalSegSize(size) \
+ (IsPowerOf2(size) && \
+ ((size) >= WalSegMinSize && (size) <= WalSegMaxSize))
+
+/* Number of segments in a logical XLOG file */
+#define XLogSegmentsPerXLogId(wal_segsz_bytes) \
+ (UINT64CONST(0x100000000) / (wal_segsz_bytes))
+
+/*
+ * Compute an XLogRecPtr from a segment number and offset.
+ */
+#define XLogSegNoOffsetToRecPtr(segno, offset, wal_segsz_bytes, dest) \
+ (dest) = (segno) * (wal_segsz_bytes) + (offset)
+/*
+ * Compute a segment number from an XLogRecPtr.
+ *
+ * For XLByteToSeg, do the computation at face value. For XLByteToPrevSeg,
+ * a boundary byte is taken to be in the previous segment. This is suitable
+ * for deciding which segment to write given a pointer to a record end,
+ * for example.
+ */
+#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ logSegNo = (xlrp) / (wal_segsz_bytes)
+
+#define XLByteToPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ logSegNo = ((xlrp) - 1) / (wal_segsz_bytes)
+
+/* Compute the in-segment offset from an XLogRecPtr. */
+#define XLogSegmentOffset(xlogptr, wal_segsz_bytes) \
+ ((xlogptr) & ((wal_segsz_bytes) - 1))
+
+/*
+ * Convert values of GUCs measured in megabytes to equiv. segment count.
+ * Rounds down.
+ */
+#define XLogMBVarToSegs(mbvar, wal_segsz_bytes) \
+ ((mbvar) / ((wal_segsz_bytes) / (1024 * 1024)))
+
+/*
+ * Is an XLogRecPtr within a particular XLOG segment?
+ *
+ * For XLByteInSeg, do the computation at face value. For XLByteInPrevSeg,
+ * a boundary byte is taken to be in the previous segment.
+ */
+#define XLByteInSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ (((xlrp) / (wal_segsz_bytes)) == (logSegNo))
+
+#define XLByteInPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ ((((xlrp) - 1) / (wal_segsz_bytes)) == (logSegNo))
+
+
+#endif /* XLOG_FILESIZE_H */
--
2.48.1
v3-0003-Use-XLOG_CONTROL_FILE-macro-everywhere-in-C-code.patchtext/x-patch; charset=UTF-8; name=v3-0003-Use-XLOG_CONTROL_FILE-macro-everywhere-in-C-code.patchDownload
From e55a0ab4fe3061f033de0d20becf0a9f2018b603 Mon Sep 17 00:00:00 2001
From: "Anton A. Melnikov" <a.melnikov@postgrespro.ru>
Date: Wed, 4 Sep 2024 16:23:23 +0900
Subject: [PATCH] Use XLOG_CONTROL_FILE macro everywhere in C code
---
src/backend/backup/basebackup.c | 2 +-
src/backend/postmaster/postmaster.c | 2 +-
src/bin/pg_combinebackup/pg_combinebackup.c | 5 +++--
src/bin/pg_controldata/pg_controldata.c | 3 ++-
src/bin/pg_rewind/filemap.c | 3 ++-
src/bin/pg_rewind/pg_rewind.c | 8 ++++----
src/bin/pg_upgrade/controldata.c | 9 +++++----
src/bin/pg_verifybackup/pg_verifybackup.c | 3 ++-
src/common/controldata_utils.c | 2 +-
9 files changed, 21 insertions(+), 16 deletions(-)
diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c
index 3f8a3c55725..f0813eda8d7 100644
--- a/src/backend/backup/basebackup.c
+++ b/src/backend/backup/basebackup.c
@@ -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)
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index a0c37532d2f..7b5f6c37a95 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -1516,7 +1516,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)
diff --git a/src/bin/pg_combinebackup/pg_combinebackup.c b/src/bin/pg_combinebackup/pg_combinebackup.c
index d480dc74436..bbf85144098 100644
--- a/src/bin/pg_combinebackup/pg_combinebackup.c
+++ b/src/bin/pg_combinebackup/pg_combinebackup.c
@@ -24,6 +24,7 @@
#include <linux/fs.h>
#endif
+#include "access/xlogfilepaths.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 %llu, but control file has %llu",
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);
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index 162f087626d..d3714c629b3 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -1,7 +1,8 @@
/*
* pg_controldata
*
- * reads the data from $PGDATA/global/pg_control
+ * reads the data from reads the data from the control file
+ * which is located at $PGDATA/XLOG_CONTROL_FILE
*
* copyright (c) Oliver Elphick <olly@lfix.co.uk>, 2001;
* license: BSD
diff --git a/src/bin/pg_rewind/filemap.c b/src/bin/pg_rewind/filemap.c
index a28d1667d4c..3ef38f329cb 100644
--- a/src/bin/pg_rewind/filemap.c
+++ b/src/bin/pg_rewind/filemap.c
@@ -26,6 +26,7 @@
#include <sys/stat.h>
#include <unistd.h>
+#include "access/xlogfilepaths.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 */
diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c
index a625105fbcc..d32439fbfaf 100644
--- a/src/bin/pg_rewind/pg_rewind.c
+++ b/src/bin/pg_rewind/pg_rewind.c
@@ -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);
diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c
index bd49ea867bf..6c070577003 100644
--- a/src/bin/pg_upgrade/controldata.c
+++ b/src/bin/pg_upgrade/controldata.c
@@ -12,6 +12,7 @@
#include <ctype.h>
#include <limits.h> /* for CHAR_MIN */
+#include "access/xlogfilepaths.h"
#include "common/string.h"
#include "pg_upgrade.h"
@@ -757,10 +758,10 @@ disable_old_cluster(void)
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);
@@ -768,7 +769,7 @@ disable_old_cluster(void)
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/" XLOG_CONTROL_FILE ".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);
diff --git a/src/bin/pg_verifybackup/pg_verifybackup.c b/src/bin/pg_verifybackup/pg_verifybackup.c
index 84edd2cdca5..df5466553fa 100644
--- a/src/bin/pg_verifybackup/pg_verifybackup.c
+++ b/src/bin/pg_verifybackup/pg_verifybackup.c
@@ -18,6 +18,7 @@
#include <sys/stat.h>
#include <time.h>
+#include "access/xlogfilepaths.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 */
diff --git a/src/common/controldata_utils.c b/src/common/controldata_utils.c
index 34d8a3a4e31..fa375dc9129 100644
--- a/src/common/controldata_utils.c
+++ b/src/common/controldata_utils.c
@@ -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);
}
--
2.48.1
Hi!
* Patch needs rebase by CFbot
Rebased the patches onto the current master and marked them as v4.
Best wishes,
--
Anton A. Melnikov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
Attachments:
v4-0001-Split-file-related-parts-from-xlog_internal.h.patchtext/x-patch; charset=UTF-8; name=v4-0001-Split-file-related-parts-from-xlog_internal.h.patchDownload
From 689539285dd813a682507ce310b45c978d67b065 Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Date: Wed, 4 Sep 2024 16:15:16 +0900
Subject: [PATCH 1/3] Split file-related parts from xlog_internal.h
Some modules that require XLOG file manipulation had to include
xlog_internal.h, which contains excessively detailed internal
information. This commit separates the file and file path-related
components into xlogfilepaths.h, thereby avoiding the exposure of
unrelated details of the XLOG module.
---
src/backend/access/transam/timeline.c | 1 -
src/backend/postmaster/pgarch.c | 1 -
src/backend/utils/adt/genfile.c | 1 -
src/bin/initdb/initdb.c | 1 +
src/bin/pg_archivecleanup/pg_archivecleanup.c | 2 +-
src/bin/pg_basebackup/pg_basebackup.c | 4 +-
src/bin/pg_basebackup/pg_receivewal.c | 1 +
src/bin/pg_basebackup/receivelog.c | 2 +-
src/bin/pg_basebackup/streamutil.c | 2 +-
src/bin/pg_controldata/pg_controldata.c | 1 -
src/bin/pg_rewind/pg_rewind.c | 2 +-
src/include/access/xlog.h | 13 +-
src/include/access/xlog_internal.h | 178 +-------------
src/include/access/xlogfilepaths.h | 219 ++++++++++++++++++
14 files changed, 230 insertions(+), 198 deletions(-)
create mode 100644 src/include/access/xlogfilepaths.h
diff --git a/src/backend/access/transam/timeline.c b/src/backend/access/transam/timeline.c
index a27f27cc037..710e92297e3 100644
--- a/src/backend/access/transam/timeline.c
+++ b/src/backend/access/transam/timeline.c
@@ -38,7 +38,6 @@
#include "access/xlog.h"
#include "access/xlog_internal.h"
#include "access/xlogarchive.h"
-#include "access/xlogdefs.h"
#include "pgstat.h"
#include "storage/fd.h"
diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c
index 7e622ae4bd2..4db8a00b849 100644
--- a/src/backend/postmaster/pgarch.c
+++ b/src/backend/postmaster/pgarch.c
@@ -30,7 +30,6 @@
#include <unistd.h>
#include "access/xlog.h"
-#include "access/xlog_internal.h"
#include "archive/archive_module.h"
#include "archive/shell_archive.h"
#include "lib/binaryheap.h"
diff --git a/src/backend/utils/adt/genfile.c b/src/backend/utils/adt/genfile.c
index 80bb807fbe9..af4c148c809 100644
--- a/src/backend/utils/adt/genfile.c
+++ b/src/backend/utils/adt/genfile.c
@@ -21,7 +21,6 @@
#include <dirent.h>
#include "access/htup_details.h"
-#include "access/xlog_internal.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_tablespace_d.h"
#include "catalog/pg_type.h"
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index 22b7d31b165..6768ef84c7c 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -65,6 +65,7 @@
#endif
#include "access/xlog_internal.h"
+#include "lib/stringinfo.h"
#include "catalog/pg_authid_d.h"
#include "catalog/pg_class_d.h"
#include "catalog/pg_collation_d.h"
diff --git a/src/bin/pg_archivecleanup/pg_archivecleanup.c b/src/bin/pg_archivecleanup/pg_archivecleanup.c
index c25348bcb85..edf1828bc73 100644
--- a/src/bin/pg_archivecleanup/pg_archivecleanup.c
+++ b/src/bin/pg_archivecleanup/pg_archivecleanup.c
@@ -15,7 +15,7 @@
#include <signal.h>
#include <sys/time.h>
-#include "access/xlog_internal.h"
+#include "access/xlogfilepaths.h"
#include "common/logging.h"
#include "getopt_long.h"
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 1da4bfc2351..01f36e1c38e 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -25,7 +25,7 @@
#include <zlib.h>
#endif
-#include "access/xlog_internal.h"
+#include "access/xlogfilepaths.h"
#include "astreamer_inject.h"
#include "backup/basebackup.h"
#include "common/compression.h"
@@ -35,6 +35,8 @@
#include "fe_utils/option_utils.h"
#include "fe_utils/recovery_gen.h"
#include "getopt_long.h"
+#include "pgtime.h"
+#include "port/pg_bswap.h"
#include "receivelog.h"
#include "streamutil.h"
diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c
index de3584018b0..4facc35f845 100644
--- a/src/bin/pg_basebackup/pg_receivewal.c
+++ b/src/bin/pg_basebackup/pg_receivewal.c
@@ -27,6 +27,7 @@
#include <zlib.h>
#endif
+//#include "access/xlogfilepaths.h"
#include "access/xlog_internal.h"
#include "common/file_perm.h"
#include "common/logging.h"
diff --git a/src/bin/pg_basebackup/receivelog.c b/src/bin/pg_basebackup/receivelog.c
index 6b6e32dfbdf..4f72ed42e11 100644
--- a/src/bin/pg_basebackup/receivelog.c
+++ b/src/bin/pg_basebackup/receivelog.c
@@ -18,7 +18,7 @@
#include <sys/stat.h>
#include <unistd.h>
-#include "access/xlog_internal.h"
+#include "access/xlogfilepaths.h"
#include "common/logging.h"
#include "libpq-fe.h"
#include "receivelog.h"
diff --git a/src/bin/pg_basebackup/streamutil.c b/src/bin/pg_basebackup/streamutil.c
index 8e605f43ffe..62eb0586dc4 100644
--- a/src/bin/pg_basebackup/streamutil.c
+++ b/src/bin/pg_basebackup/streamutil.c
@@ -17,7 +17,7 @@
#include <sys/time.h>
#include <unistd.h>
-#include "access/xlog_internal.h"
+#include "access/xlogfilepaths.h"
#include "common/connect.h"
#include "common/file_perm.h"
#include "common/logging.h"
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index bea779eef94..162f087626d 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -22,7 +22,6 @@
#include "access/transam.h"
#include "access/xlog.h"
-#include "access/xlog_internal.h"
#include "catalog/pg_control.h"
#include "common/controldata_utils.h"
#include "common/logging.h"
diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c
index 2c8b1a07007..a625105fbcc 100644
--- a/src/bin/pg_rewind/pg_rewind.c
+++ b/src/bin/pg_rewind/pg_rewind.c
@@ -15,7 +15,7 @@
#include <unistd.h>
#include "access/timeline.h"
-#include "access/xlog_internal.h"
+#include "access/xlogfilepaths.h"
#include "catalog/catversion.h"
#include "catalog/pg_control.h"
#include "common/controldata_utils.h"
diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h
index d313099c027..7ef9264fabc 100644
--- a/src/include/access/xlog.h
+++ b/src/include/access/xlog.h
@@ -16,6 +16,7 @@
#include "datatype/timestamp.h"
#include "lib/stringinfo.h"
#include "nodes/pg_list.h"
+#include "access/xlogfilepaths.h"
/* Sync methods */
@@ -299,16 +300,4 @@ extern void do_pg_abort_backup(int code, Datum arg);
extern void register_persistent_abort_backup_handler(void);
extern SessionBackupState get_backup_status(void);
-/* File path names (all relative to $PGDATA) */
-#define RECOVERY_SIGNAL_FILE "recovery.signal"
-#define STANDBY_SIGNAL_FILE "standby.signal"
-#define BACKUP_LABEL_FILE "backup_label"
-#define BACKUP_LABEL_OLD "backup_label.old"
-
-#define TABLESPACE_MAP "tablespace_map"
-#define TABLESPACE_MAP_OLD "tablespace_map.old"
-
-/* files to signal promotion to primary */
-#define PROMOTE_SIGNAL_FILE "promote"
-
#endif /* XLOG_H */
diff --git a/src/include/access/xlog_internal.h b/src/include/access/xlog_internal.h
index 2cf8d55d706..5e846e48073 100644
--- a/src/include/access/xlog_internal.h
+++ b/src/include/access/xlog_internal.h
@@ -21,6 +21,7 @@
#include "access/xlogdefs.h"
#include "access/xlogreader.h"
+#include "access/xlogfilepaths.h"
#include "datatype/timestamp.h"
#include "lib/stringinfo.h"
#include "pgtime.h"
@@ -84,187 +85,10 @@ typedef XLogLongPageHeaderData *XLogLongPageHeader;
#define XLogPageHeaderSize(hdr) \
(((hdr)->xlp_info & XLP_LONG_HEADER) ? SizeOfXLogLongPHD : SizeOfXLogShortPHD)
-/* wal_segment_size can range from 1MB to 1GB */
-#define WalSegMinSize 1024 * 1024
-#define WalSegMaxSize 1024 * 1024 * 1024
-/* default number of min and max wal segments */
-#define DEFAULT_MIN_WAL_SEGS 5
-#define DEFAULT_MAX_WAL_SEGS 64
-
-/* check that the given size is a valid wal_segment_size */
-#define IsPowerOf2(x) (x > 0 && ((x) & ((x)-1)) == 0)
-#define IsValidWalSegSize(size) \
- (IsPowerOf2(size) && \
- ((size) >= WalSegMinSize && (size) <= WalSegMaxSize))
-
-#define XLogSegmentsPerXLogId(wal_segsz_bytes) \
- (UINT64CONST(0x100000000) / (wal_segsz_bytes))
-
-#define XLogSegNoOffsetToRecPtr(segno, offset, wal_segsz_bytes, dest) \
- (dest) = (segno) * (wal_segsz_bytes) + (offset)
-
-#define XLogSegmentOffset(xlogptr, wal_segsz_bytes) \
- ((xlogptr) & ((wal_segsz_bytes) - 1))
-
-/*
- * Compute a segment number from an XLogRecPtr.
- *
- * For XLByteToSeg, do the computation at face value. For XLByteToPrevSeg,
- * a boundary byte is taken to be in the previous segment. This is suitable
- * for deciding which segment to write given a pointer to a record end,
- * for example.
- */
-#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes) \
- logSegNo = (xlrp) / (wal_segsz_bytes)
-
-#define XLByteToPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
- logSegNo = ((xlrp) - 1) / (wal_segsz_bytes)
-
-/*
- * Convert values of GUCs measured in megabytes to equiv. segment count.
- * Rounds down.
- */
-#define XLogMBVarToSegs(mbvar, wal_segsz_bytes) \
- ((mbvar) / ((wal_segsz_bytes) / (1024 * 1024)))
-
-/*
- * Is an XLogRecPtr within a particular XLOG segment?
- *
- * For XLByteInSeg, do the computation at face value. For XLByteInPrevSeg,
- * a boundary byte is taken to be in the previous segment.
- */
-#define XLByteInSeg(xlrp, logSegNo, wal_segsz_bytes) \
- (((xlrp) / (wal_segsz_bytes)) == (logSegNo))
-
-#define XLByteInPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
- ((((xlrp) - 1) / (wal_segsz_bytes)) == (logSegNo))
-
/* Check if an XLogRecPtr value is in a plausible range */
#define XRecOffIsValid(xlrp) \
((xlrp) % XLOG_BLCKSZ >= SizeOfXLogShortPHD)
-/*
- * The XLog directory and control file (relative to $PGDATA)
- */
-#define XLOGDIR "pg_wal"
-#define XLOG_CONTROL_FILE "global/pg_control"
-
-/*
- * These macros encapsulate knowledge about the exact layout of XLog file
- * names, timeline history file names, and archive-status file names.
- */
-#define MAXFNAMELEN 64
-
-/* Length of XLog file name */
-#define XLOG_FNAME_LEN 24
-
-/*
- * Generate a WAL segment file name. Do not use this function in a helper
- * function allocating the result generated.
- */
-static inline void
-XLogFileName(char *fname, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)
-{
- snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli,
- (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
- (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)));
-}
-
-static inline void
-XLogFileNameById(char *fname, TimeLineID tli, uint32 log, uint32 seg)
-{
- snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, log, seg);
-}
-
-static inline bool
-IsXLogFileName(const char *fname)
-{
- return (strlen(fname) == XLOG_FNAME_LEN && \
- strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN);
-}
-
-/*
- * XLOG segment with .partial suffix. Used by pg_receivewal and at end of
- * archive recovery, when we want to archive a WAL segment but it might not
- * be complete yet.
- */
-static inline bool
-IsPartialXLogFileName(const char *fname)
-{
- return (strlen(fname) == XLOG_FNAME_LEN + strlen(".partial") &&
- strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN &&
- strcmp(fname + XLOG_FNAME_LEN, ".partial") == 0);
-}
-
-static inline void
-XLogFromFileName(const char *fname, TimeLineID *tli, XLogSegNo *logSegNo, int wal_segsz_bytes)
-{
- uint32 log;
- uint32 seg;
-
- sscanf(fname, "%08X%08X%08X", tli, &log, &seg);
- *logSegNo = (uint64) log * XLogSegmentsPerXLogId(wal_segsz_bytes) + seg;
-}
-
-static inline void
-XLogFilePath(char *path, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)
-{
- snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X", tli,
- (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
- (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)));
-}
-
-static inline void
-TLHistoryFileName(char *fname, TimeLineID tli)
-{
- snprintf(fname, MAXFNAMELEN, "%08X.history", tli);
-}
-
-static inline bool
-IsTLHistoryFileName(const char *fname)
-{
- return (strlen(fname) == 8 + strlen(".history") &&
- strspn(fname, "0123456789ABCDEF") == 8 &&
- strcmp(fname + 8, ".history") == 0);
-}
-
-static inline void
-TLHistoryFilePath(char *path, TimeLineID tli)
-{
- snprintf(path, MAXPGPATH, XLOGDIR "/%08X.history", tli);
-}
-
-static inline void
-StatusFilePath(char *path, const char *xlog, const char *suffix)
-{
- snprintf(path, MAXPGPATH, XLOGDIR "/archive_status/%s%s", xlog, suffix);
-}
-
-static inline void
-BackupHistoryFileName(char *fname, TimeLineID tli, XLogSegNo logSegNo, XLogRecPtr startpoint, int wal_segsz_bytes)
-{
- snprintf(fname, MAXFNAMELEN, "%08X%08X%08X.%08X.backup", tli,
- (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
- (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)),
- (uint32) (XLogSegmentOffset(startpoint, wal_segsz_bytes)));
-}
-
-static inline bool
-IsBackupHistoryFileName(const char *fname)
-{
- return (strlen(fname) > XLOG_FNAME_LEN &&
- strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN &&
- strcmp(fname + strlen(fname) - strlen(".backup"), ".backup") == 0);
-}
-
-static inline void
-BackupHistoryFilePath(char *path, TimeLineID tli, XLogSegNo logSegNo, XLogRecPtr startpoint, int wal_segsz_bytes)
-{
- snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X.%08X.backup", tli,
- (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
- (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)),
- (uint32) (XLogSegmentOffset((startpoint), wal_segsz_bytes)));
-}
/*
* Information logged when we detect a change in one of the parameters
diff --git a/src/include/access/xlogfilepaths.h b/src/include/access/xlogfilepaths.h
new file mode 100644
index 00000000000..cdde2ccae4f
--- /dev/null
+++ b/src/include/access/xlogfilepaths.h
@@ -0,0 +1,219 @@
+/*
+ * xlogfilepaths.h
+ *
+ * File name definitions and handling macros for PostgreSQL write-ahead logs.
+ *
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/include/access/xlogfilepaths.h
+ */
+#ifndef XLOG_FILEPATHS_H
+#define XLOG_FILEPATHS_H
+
+#include "access/xlogdefs.h"
+
+/*
+ * The XLog directory and files (relative to $PGDATA)
+ */
+#define XLOGDIR "pg_wal"
+
+/* control files */
+#define XLOG_CONTROL_FILE "global/pg_control"
+#define BACKUP_LABEL_FILE "backup_label"
+#define BACKUP_LABEL_OLD "backup_label.old"
+
+/* tablespace map */
+#define TABLESPACE_MAP "tablespace_map"
+#define TABLESPACE_MAP_OLD "tablespace_map.old"
+
+/* files to signal run mode to standby */
+#define RECOVERY_SIGNAL_FILE "recovery.signal"
+#define STANDBY_SIGNAL_FILE "standby.signal"
+
+/* files to signal promotion to primary */
+#define PROMOTE_SIGNAL_FILE "promote"
+
+/* wal_segment_size can range from 1MB to 1GB */
+#define WalSegMinSize 1024 * 1024
+#define WalSegMaxSize 1024 * 1024 * 1024
+
+/* default number of min and max wal segments */
+#define DEFAULT_MIN_WAL_SEGS 5
+#define DEFAULT_MAX_WAL_SEGS 64
+
+
+/*
+ * These macros encapsulate knowledge about the exact layout of XLog file
+ * names, timeline history file names, and archive-status file names.
+ */
+#define MAXFNAMELEN 64
+
+/* Length of XLog file name */
+#define XLOG_FNAME_LEN 24
+
+/* check that the given size is a valid wal_segment_size */
+#define IsPowerOf2(x) (x > 0 && ((x) & ((x)-1)) == 0)
+#define IsValidWalSegSize(size) \
+ (IsPowerOf2(size) && \
+ ((size) >= WalSegMinSize && (size) <= WalSegMaxSize))
+
+/* Number of segments in a logical XLOG file */
+#define XLogSegmentsPerXLogId(wal_segsz_bytes) \
+ (UINT64CONST(0x100000000) / (wal_segsz_bytes))
+
+/*
+ * Compute an XLogRecPtr from a segment number and offset.
+ */
+#define XLogSegNoOffsetToRecPtr(segno, offset, wal_segsz_bytes, dest) \
+ (dest) = (segno) * (wal_segsz_bytes) + (offset)
+/*
+ * Compute a segment number from an XLogRecPtr.
+ *
+ * For XLByteToSeg, do the computation at face value. For XLByteToPrevSeg,
+ * a boundary byte is taken to be in the previous segment. This is suitable
+ * for deciding which segment to write given a pointer to a record end,
+ * for example.
+ */
+#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ logSegNo = (xlrp) / (wal_segsz_bytes)
+
+#define XLByteToPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ logSegNo = ((xlrp) - 1) / (wal_segsz_bytes)
+
+/* Compute the in-segment offset from an XLogRecPtr. */
+#define XLogSegmentOffset(xlogptr, wal_segsz_bytes) \
+ ((xlogptr) & ((wal_segsz_bytes) - 1))
+
+/*
+ * Convert values of GUCs measured in megabytes to equiv. segment count.
+ * Rounds down.
+ */
+#define XLogMBVarToSegs(mbvar, wal_segsz_bytes) \
+ ((mbvar) / ((wal_segsz_bytes) / (1024 * 1024)))
+
+/*
+ * Is an XLogRecPtr within a particular XLOG segment?
+ *
+ * For XLByteInSeg, do the computation at face value. For XLByteInPrevSeg,
+ * a boundary byte is taken to be in the previous segment.
+ */
+#define XLByteInSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ (((xlrp) / (wal_segsz_bytes)) == (logSegNo))
+
+#define XLByteInPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ ((((xlrp) - 1) / (wal_segsz_bytes)) == (logSegNo))
+
+/*
+ * XLOG file name handling functions
+ */
+static inline void
+StatusFilePath(char *path, const char *xlog, const char *suffix)
+{
+ snprintf(path, MAXPGPATH, XLOGDIR "/archive_status/%s%s", xlog, suffix);
+}
+
+static inline bool
+IsTLHistoryFileName(const char *fname)
+{
+ return (strlen(fname) == 8 + strlen(".history") &&
+ strspn(fname, "0123456789ABCDEF") == 8 &&
+ strcmp(fname + 8, ".history") == 0);
+}
+
+static inline void
+XLogFromFileName(const char *fname, TimeLineID *tli, XLogSegNo *logSegNo, int wal_segsz_bytes)
+{
+ uint32 log;
+ uint32 seg;
+
+ sscanf(fname, "%08X%08X%08X", tli, &log, &seg);
+ *logSegNo = (uint64) log * XLogSegmentsPerXLogId(wal_segsz_bytes) + seg;
+}
+
+static inline void
+XLogFilePath(char *path, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)
+{
+ snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X", tli,
+ (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
+ (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)));
+}
+
+/*
+ * Generate a WAL segment file name. Do not use this function in a helper
+ * function allocating the result generated.
+ */
+static inline void
+XLogFileName(char *fname, TimeLineID tli, XLogSegNo logSegNo, int wal_segsz_bytes)
+{
+ snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli,
+ (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
+ (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)));
+}
+
+static inline void
+XLogFileNameById(char *fname, TimeLineID tli, uint32 log, uint32 seg)
+{
+ snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, log, seg);
+}
+
+static inline bool
+IsXLogFileName(const char *fname)
+{
+ return (strlen(fname) == XLOG_FNAME_LEN && \
+ strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN);
+}
+
+/*
+ * XLOG segment with .partial suffix. Used by pg_receivewal and at end of
+ * archive recovery, when we want to archive a WAL segment but it might not
+ * be complete yet.
+ */
+static inline bool
+IsPartialXLogFileName(const char *fname)
+{
+ return (strlen(fname) == XLOG_FNAME_LEN + strlen(".partial") &&
+ strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN &&
+ strcmp(fname + XLOG_FNAME_LEN, ".partial") == 0);
+}
+
+static inline void
+TLHistoryFileName(char *fname, TimeLineID tli)
+{
+ snprintf(fname, MAXFNAMELEN, "%08X.history", tli);
+}
+
+static inline void
+TLHistoryFilePath(char *path, TimeLineID tli)
+{
+ snprintf(path, MAXPGPATH, XLOGDIR "/%08X.history", tli);
+}
+
+static inline void
+BackupHistoryFileName(char *fname, TimeLineID tli, XLogSegNo logSegNo, XLogRecPtr startpoint, int wal_segsz_bytes)
+{
+ snprintf(fname, MAXFNAMELEN, "%08X%08X%08X.%08X.backup", tli,
+ (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
+ (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)),
+ (uint32) (XLogSegmentOffset(startpoint, wal_segsz_bytes)));
+}
+
+static inline bool
+IsBackupHistoryFileName(const char *fname)
+{
+ return (strlen(fname) > XLOG_FNAME_LEN &&
+ strspn(fname, "0123456789ABCDEF") == XLOG_FNAME_LEN &&
+ strcmp(fname + strlen(fname) - strlen(".backup"), ".backup") == 0);
+}
+
+static inline void
+BackupHistoryFilePath(char *path, TimeLineID tli, XLogSegNo logSegNo, XLogRecPtr startpoint, int wal_segsz_bytes)
+{
+ snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X.%08X.backup", tli,
+ (uint32) (logSegNo / XLogSegmentsPerXLogId(wal_segsz_bytes)),
+ (uint32) (logSegNo % XLogSegmentsPerXLogId(wal_segsz_bytes)),
+ (uint32) (XLogSegmentOffset((startpoint), wal_segsz_bytes)));
+}
+
+
+#endif /* XLOG_FILEPATHS_H */
--
2.48.1
v4-0002-Extract-size-related-macros-from-xlogfilepaths.h.patchtext/x-patch; charset=UTF-8; name=v4-0002-Extract-size-related-macros-from-xlogfilepaths.h.patchDownload
From 8c9254604e4fd28658a218070e0f7d30e05d563d Mon Sep 17 00:00:00 2001
From: "Anton A. Melnikov" <a.melnikov@postgrespro.ru>
Date: Sat, 7 Sep 2024 10:18:51 +0300
Subject: [PATCH 2/3] Extract size-related macros from xlogfilepaths.h to
xlogfilesize.h
---
src/include/access/xlogfilepaths.h | 65 +----------------------
src/include/access/xlogfilesize.h | 83 ++++++++++++++++++++++++++++++
2 files changed, 85 insertions(+), 63 deletions(-)
create mode 100644 src/include/access/xlogfilesize.h
diff --git a/src/include/access/xlogfilepaths.h b/src/include/access/xlogfilepaths.h
index cdde2ccae4f..ed28cf975e6 100644
--- a/src/include/access/xlogfilepaths.h
+++ b/src/include/access/xlogfilepaths.h
@@ -12,6 +12,7 @@
#define XLOG_FILEPATHS_H
#include "access/xlogdefs.h"
+#include "access/xlogfilesize.h"
/*
* The XLog directory and files (relative to $PGDATA)
@@ -34,75 +35,13 @@
/* files to signal promotion to primary */
#define PROMOTE_SIGNAL_FILE "promote"
-/* wal_segment_size can range from 1MB to 1GB */
-#define WalSegMinSize 1024 * 1024
-#define WalSegMaxSize 1024 * 1024 * 1024
-/* default number of min and max wal segments */
-#define DEFAULT_MIN_WAL_SEGS 5
-#define DEFAULT_MAX_WAL_SEGS 64
-
-
-/*
- * These macros encapsulate knowledge about the exact layout of XLog file
- * names, timeline history file names, and archive-status file names.
- */
+/* Maximum length of XLog file name including possible suffix */
#define MAXFNAMELEN 64
/* Length of XLog file name */
#define XLOG_FNAME_LEN 24
-/* check that the given size is a valid wal_segment_size */
-#define IsPowerOf2(x) (x > 0 && ((x) & ((x)-1)) == 0)
-#define IsValidWalSegSize(size) \
- (IsPowerOf2(size) && \
- ((size) >= WalSegMinSize && (size) <= WalSegMaxSize))
-
-/* Number of segments in a logical XLOG file */
-#define XLogSegmentsPerXLogId(wal_segsz_bytes) \
- (UINT64CONST(0x100000000) / (wal_segsz_bytes))
-
-/*
- * Compute an XLogRecPtr from a segment number and offset.
- */
-#define XLogSegNoOffsetToRecPtr(segno, offset, wal_segsz_bytes, dest) \
- (dest) = (segno) * (wal_segsz_bytes) + (offset)
-/*
- * Compute a segment number from an XLogRecPtr.
- *
- * For XLByteToSeg, do the computation at face value. For XLByteToPrevSeg,
- * a boundary byte is taken to be in the previous segment. This is suitable
- * for deciding which segment to write given a pointer to a record end,
- * for example.
- */
-#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes) \
- logSegNo = (xlrp) / (wal_segsz_bytes)
-
-#define XLByteToPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
- logSegNo = ((xlrp) - 1) / (wal_segsz_bytes)
-
-/* Compute the in-segment offset from an XLogRecPtr. */
-#define XLogSegmentOffset(xlogptr, wal_segsz_bytes) \
- ((xlogptr) & ((wal_segsz_bytes) - 1))
-
-/*
- * Convert values of GUCs measured in megabytes to equiv. segment count.
- * Rounds down.
- */
-#define XLogMBVarToSegs(mbvar, wal_segsz_bytes) \
- ((mbvar) / ((wal_segsz_bytes) / (1024 * 1024)))
-
-/*
- * Is an XLogRecPtr within a particular XLOG segment?
- *
- * For XLByteInSeg, do the computation at face value. For XLByteInPrevSeg,
- * a boundary byte is taken to be in the previous segment.
- */
-#define XLByteInSeg(xlrp, logSegNo, wal_segsz_bytes) \
- (((xlrp) / (wal_segsz_bytes)) == (logSegNo))
-
-#define XLByteInPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
- ((((xlrp) - 1) / (wal_segsz_bytes)) == (logSegNo))
/*
* XLOG file name handling functions
diff --git a/src/include/access/xlogfilesize.h b/src/include/access/xlogfilesize.h
new file mode 100644
index 00000000000..fef30e02a62
--- /dev/null
+++ b/src/include/access/xlogfilesize.h
@@ -0,0 +1,83 @@
+/*
+ * xlogfilesize.h
+ *
+ * Size definitions and handling macros for PostgreSQL write-ahead logs.
+ *
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/include/access/xlogfilesize.h
+ */
+
+#ifndef XLOG_FILESIZE_H
+#define XLOG_FILESIZE_H
+
+#include "access/xlogdefs.h"
+
+/* wal_segment_size can range from 1MB to 1GB */
+#define WalSegMinSize 1024 * 1024
+#define WalSegMaxSize 1024 * 1024 * 1024
+
+/* default number of min and max wal segments */
+#define DEFAULT_MIN_WAL_SEGS 5
+#define DEFAULT_MAX_WAL_SEGS 64
+
+/*
+ * These macros encapsulate knowledge about the exact layout of XLog
+ * files, timeline history fils and archive-status fils.
+ */
+
+/* check that the given size is a valid wal_segment_size */
+#define IsPowerOf2(x) (x > 0 && ((x) & ((x)-1)) == 0)
+#define IsValidWalSegSize(size) \
+ (IsPowerOf2(size) && \
+ ((size) >= WalSegMinSize && (size) <= WalSegMaxSize))
+
+/* Number of segments in a logical XLOG file */
+#define XLogSegmentsPerXLogId(wal_segsz_bytes) \
+ (UINT64CONST(0x100000000) / (wal_segsz_bytes))
+
+/*
+ * Compute an XLogRecPtr from a segment number and offset.
+ */
+#define XLogSegNoOffsetToRecPtr(segno, offset, wal_segsz_bytes, dest) \
+ (dest) = (segno) * (wal_segsz_bytes) + (offset)
+/*
+ * Compute a segment number from an XLogRecPtr.
+ *
+ * For XLByteToSeg, do the computation at face value. For XLByteToPrevSeg,
+ * a boundary byte is taken to be in the previous segment. This is suitable
+ * for deciding which segment to write given a pointer to a record end,
+ * for example.
+ */
+#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ logSegNo = (xlrp) / (wal_segsz_bytes)
+
+#define XLByteToPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ logSegNo = ((xlrp) - 1) / (wal_segsz_bytes)
+
+/* Compute the in-segment offset from an XLogRecPtr. */
+#define XLogSegmentOffset(xlogptr, wal_segsz_bytes) \
+ ((xlogptr) & ((wal_segsz_bytes) - 1))
+
+/*
+ * Convert values of GUCs measured in megabytes to equiv. segment count.
+ * Rounds down.
+ */
+#define XLogMBVarToSegs(mbvar, wal_segsz_bytes) \
+ ((mbvar) / ((wal_segsz_bytes) / (1024 * 1024)))
+
+/*
+ * Is an XLogRecPtr within a particular XLOG segment?
+ *
+ * For XLByteInSeg, do the computation at face value. For XLByteInPrevSeg,
+ * a boundary byte is taken to be in the previous segment.
+ */
+#define XLByteInSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ (((xlrp) / (wal_segsz_bytes)) == (logSegNo))
+
+#define XLByteInPrevSeg(xlrp, logSegNo, wal_segsz_bytes) \
+ ((((xlrp) - 1) / (wal_segsz_bytes)) == (logSegNo))
+
+
+#endif /* XLOG_FILESIZE_H */
--
2.48.1
v4-0003-Use-XLOG_CONTROL_FILE-macro-everywhere-in-C-code.patchtext/x-patch; charset=UTF-8; name=v4-0003-Use-XLOG_CONTROL_FILE-macro-everywhere-in-C-code.patchDownload
From 2df6b6cb767c9bddcb27da838cbce5ea40053a4e Mon Sep 17 00:00:00 2001
From: "Anton A. Melnikov" <a.melnikov@postgrespro.ru>
Date: Wed, 4 Sep 2024 16:23:23 +0900
Subject: [PATCH 3/3] Use XLOG_CONTROL_FILE macro everywhere in C code
---
src/backend/backup/basebackup.c | 2 +-
src/backend/postmaster/postmaster.c | 2 +-
src/bin/pg_combinebackup/pg_combinebackup.c | 5 +++--
src/bin/pg_controldata/pg_controldata.c | 3 ++-
src/bin/pg_rewind/filemap.c | 3 ++-
src/bin/pg_rewind/pg_rewind.c | 8 ++++----
src/bin/pg_upgrade/controldata.c | 7 ++++---
src/bin/pg_verifybackup/pg_verifybackup.c | 3 ++-
src/common/controldata_utils.c | 2 +-
9 files changed, 20 insertions(+), 15 deletions(-)
diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c
index 3f8a3c55725..f0813eda8d7 100644
--- a/src/backend/backup/basebackup.c
+++ b/src/backend/backup/basebackup.c
@@ -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)
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index a0c37532d2f..7b5f6c37a95 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -1516,7 +1516,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)
diff --git a/src/bin/pg_combinebackup/pg_combinebackup.c b/src/bin/pg_combinebackup/pg_combinebackup.c
index 050260ee832..01241a8fb60 100644
--- a/src/bin/pg_combinebackup/pg_combinebackup.c
+++ b/src/bin/pg_combinebackup/pg_combinebackup.c
@@ -24,6 +24,7 @@
#include <linux/fs.h>
#endif
+#include "access/xlogfilepaths.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 %llu, but control file has %llu",
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);
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index 162f087626d..d3714c629b3 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -1,7 +1,8 @@
/*
* pg_controldata
*
- * reads the data from $PGDATA/global/pg_control
+ * reads the data from reads the data from the control file
+ * which is located at $PGDATA/XLOG_CONTROL_FILE
*
* copyright (c) Oliver Elphick <olly@lfix.co.uk>, 2001;
* license: BSD
diff --git a/src/bin/pg_rewind/filemap.c b/src/bin/pg_rewind/filemap.c
index a28d1667d4c..3ef38f329cb 100644
--- a/src/bin/pg_rewind/filemap.c
+++ b/src/bin/pg_rewind/filemap.c
@@ -26,6 +26,7 @@
#include <sys/stat.h>
#include <unistd.h>
+#include "access/xlogfilepaths.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 */
diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c
index a625105fbcc..d32439fbfaf 100644
--- a/src/bin/pg_rewind/pg_rewind.c
+++ b/src/bin/pg_rewind/pg_rewind.c
@@ -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);
diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c
index 47ee27ec835..4af699d7d1e 100644
--- a/src/bin/pg_upgrade/controldata.c
+++ b/src/bin/pg_upgrade/controldata.c
@@ -12,6 +12,7 @@
#include <ctype.h>
#include <limits.h> /* for CHAR_MIN */
+#include "access/xlogfilepaths.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);
diff --git a/src/bin/pg_verifybackup/pg_verifybackup.c b/src/bin/pg_verifybackup/pg_verifybackup.c
index 84edd2cdca5..df5466553fa 100644
--- a/src/bin/pg_verifybackup/pg_verifybackup.c
+++ b/src/bin/pg_verifybackup/pg_verifybackup.c
@@ -18,6 +18,7 @@
#include <sys/stat.h>
#include <time.h>
+#include "access/xlogfilepaths.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 */
diff --git a/src/common/controldata_utils.c b/src/common/controldata_utils.c
index 34d8a3a4e31..fa375dc9129 100644
--- a/src/common/controldata_utils.c
+++ b/src/common/controldata_utils.c
@@ -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);
}
--
2.48.1
On 2025/03/28 13:09, Anton A. Melnikov wrote:
Hi!
* Patch needs rebase by CFbot
Rebased the patches onto the current master and marked them as v4.
I'm not sure there's clear consensus yet on the changes in the 0001 and
0002 patches, and it might not be worth rushing them in right before
the feature freeze. So for now, I reviewed and updated only the 0003 patch,
since there seems to be agreement on that one.
I've attached the updated version. It fixes a typo and replaces
the remaining hardcoded control file name with the XLOG_CONTROL_FILE macro.
How about committing the attached patch first? We can consider applying
the others later if consensus is reached.
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
Attachments:
v5-0001-Use-XLOG_CONTROL_FILE-macro-consistently-for-cont.patchtext/plain; charset=UTF-8; name=v5-0001-Use-XLOG_CONTROL_FILE-macro-consistently-for-cont.patchDownload
From 3c2891e042fec2d8251907782b02f5acdbd31ae6 Mon Sep 17 00:00:00 2001
From: Fujii Masao <fujii@postgresql.org>
Date: Sat, 5 Apr 2025 00:20:32 +0900
Subject: [PATCH v5] 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.
---
src/backend/backup/basebackup.c | 2 +-
src/backend/postmaster/postmaster.c | 3 ++-
src/bin/pg_combinebackup/pg_combinebackup.c | 5 +++--
src/bin/pg_controldata/pg_controldata.c | 2 +-
src/bin/pg_rewind/filemap.c | 3 ++-
src/bin/pg_rewind/pg_rewind.c | 8 ++++----
src/bin/pg_upgrade/controldata.c | 11 ++++++-----
src/bin/pg_verifybackup/astreamer_verify.c | 5 +++--
src/bin/pg_verifybackup/pg_verifybackup.c | 3 ++-
src/common/controldata_utils.c | 2 +-
10 files changed, 25 insertions(+), 19 deletions(-)
diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c
index 891637e3a44..f0f88838dc2 100644
--- a/src/backend/backup/basebackup.c
+++ b/src/backend/backup/basebackup.c
@@ -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)
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 3fe45de5da0..17fed96fe20 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -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)
diff --git a/src/bin/pg_combinebackup/pg_combinebackup.c b/src/bin/pg_combinebackup/pg_combinebackup.c
index d61bde42f49..4f8ba156336 100644
--- a/src/bin/pg_combinebackup/pg_combinebackup.c
+++ b/src/bin/pg_combinebackup/pg_combinebackup.c
@@ -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);
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index 9901a2bae51..7bb801bb886 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -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 <olly@lfix.co.uk>, 2001;
* license: BSD
diff --git a/src/bin/pg_rewind/filemap.c b/src/bin/pg_rewind/filemap.c
index a28d1667d4c..c933871ca9f 100644
--- a/src/bin/pg_rewind/filemap.c
+++ b/src/bin/pg_rewind/filemap.c
@@ -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 */
diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c
index 2c8b1a07007..9d16c1e6b47 100644
--- a/src/bin/pg_rewind/pg_rewind.c
+++ b/src/bin/pg_rewind/pg_rewind.c
@@ -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);
diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c
index 47ee27ec835..8b7c349a875 100644
--- a/src/bin/pg_upgrade/controldata.c
+++ b/src/bin/pg_upgrade/controldata.c
@@ -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"
diff --git a/src/bin/pg_verifybackup/astreamer_verify.c b/src/bin/pg_verifybackup/astreamer_verify.c
index 079c3970410..268c5f0e246 100644
--- a/src/bin/pg_verifybackup/astreamer_verify.c
+++ b/src/bin/pg_verifybackup/astreamer_verify.c
@@ -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);
/*
diff --git a/src/bin/pg_verifybackup/pg_verifybackup.c b/src/bin/pg_verifybackup/pg_verifybackup.c
index 383668a8b6a..3ce233f3c20 100644
--- a/src/bin/pg_verifybackup/pg_verifybackup.c
+++ b/src/bin/pg_verifybackup/pg_verifybackup.c
@@ -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 */
diff --git a/src/common/controldata_utils.c b/src/common/controldata_utils.c
index 34d8a3a4e31..fa375dc9129 100644
--- a/src/common/controldata_utils.c
+++ b/src/common/controldata_utils.c
@@ -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);
}
--
2.48.1
Hi!
On 04.04.2025 19:32, Fujii Masao wrote:
I'm not sure there's clear consensus yet on the changes in the 0001 and
0002 patches, and it might not be worth rushing them in right before
the feature freeze. So for now, I reviewed and updated only the 0003 patch,
since there seems to be agreement on that one.I've attached the updated version. It fixes a typo and replaces
the remaining hardcoded control file name with the XLOG_CONTROL_FILE macro.
Thanks! Looks good for me.
Maybe extend this to perl tests since there are several hardcoded names too?
The patch attached tries to do this.
How about committing the attached patch first? We can consider applying
the others later if consensus is reached
Yes, of cause. IMO, this is the best way now.
Best wishes,
--
Anton A. Melnikov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
Attachments:
0004-Use-XLOG_CONTROL_FILE-macro-in-TAP-tests.patchtext/x-patch; charset=UTF-8; name=0004-Use-XLOG_CONTROL_FILE-macro-in-TAP-tests.patchDownload
From 370137af0dba390da825a4c556f7dc91e6c6b00a Mon Sep 17 00:00:00 2001
From: "Anton A. Melnikov" <a.melnikov@postgrespro.ru>
Date: Sat, 5 Apr 2025 01:38:45 +0300
Subject: [PATCH] Use XLOG_CONTROL_FILE macro in TAP tests.
---
.../pg_controldata/t/001_pg_controldata.pl | 2 +-
src/bin/pg_resetwal/t/002_corrupted.pl | 2 +-
src/bin/pg_verifybackup/t/003_corruption.pl | 3 ++-
src/test/perl/PostgreSQL/Test/Cluster.pm | 21 ++++++++++++++++++-
src/test/recovery/t/042_low_level_backup.pl | 11 +++++-----
5 files changed, 30 insertions(+), 9 deletions(-)
diff --git a/src/bin/pg_controldata/t/001_pg_controldata.pl b/src/bin/pg_controldata/t/001_pg_controldata.pl
index 4aea00d6d5a..7412c76e837 100644
--- a/src/bin/pg_controldata/t/001_pg_controldata.pl
+++ b/src/bin/pg_controldata/t/001_pg_controldata.pl
@@ -23,7 +23,7 @@ command_like([ 'pg_controldata', $node->data_dir ],
# check with a corrupted pg_control
-my $pg_control = $node->data_dir . '/global/pg_control';
+my $pg_control = $node->data_dir . '/' . $node->controlfile;
my $size = -s $pg_control;
open my $fh, '>', $pg_control or BAIL_OUT($!);
diff --git a/src/bin/pg_resetwal/t/002_corrupted.pl b/src/bin/pg_resetwal/t/002_corrupted.pl
index 3c80f6309c9..3bf08030443 100644
--- a/src/bin/pg_resetwal/t/002_corrupted.pl
+++ b/src/bin/pg_resetwal/t/002_corrupted.pl
@@ -13,7 +13,7 @@ use Test::More;
my $node = PostgreSQL::Test::Cluster->new('main');
$node->init;
-my $pg_control = $node->data_dir . '/global/pg_control';
+my $pg_control = $node->data_dir . '/' . $node->controlfile;
my $size = -s $pg_control;
# Read out the head of the file to get PG_CONTROL_VERSION in
diff --git a/src/bin/pg_verifybackup/t/003_corruption.pl b/src/bin/pg_verifybackup/t/003_corruption.pl
index 84f23b8bc3d..af39d57fbc6 100644
--- a/src/bin/pg_verifybackup/t/003_corruption.pl
+++ b/src/bin/pg_verifybackup/t/003_corruption.pl
@@ -23,6 +23,7 @@ $primary->start;
my $source_ts_path = PostgreSQL::Test::Utils::tempdir_short();
my $source_ts_prefix = $source_ts_path;
$source_ts_prefix =~ s!(^[A-Z]:/[^/]*)/.*!$1!;
+my $controlfile = $primary->controlfile;
$primary->safe_psql('postgres', <<EOM);
CREATE TABLE x1 (a int);
@@ -280,7 +281,7 @@ sub mutilate_missing_tablespace
sub mutilate_append_to_file
{
my ($backup_path) = @_;
- append_to_file "$backup_path/global/pg_control", 'x';
+ append_to_file "$backup_path/$controlfile", 'x';
return;
}
diff --git a/src/test/perl/PostgreSQL/Test/Cluster.pm b/src/test/perl/PostgreSQL/Test/Cluster.pm
index 8759ed2cbba..17ff8ce8fa3 100644
--- a/src/test/perl/PostgreSQL/Test/Cluster.pm
+++ b/src/test/perl/PostgreSQL/Test/Cluster.pm
@@ -263,6 +263,20 @@ sub logfile
=pod
+=item $node->controlfile()
+
+Path to the PostgreSQL control file for this instance.
+
+=cut
+
+sub controlfile
+{
+ my ($self) = @_;
+ return $self->{_controlfile};
+}
+
+=pod
+
=item $node->connstr()
Get a libpq connection string that will establish a connection to
@@ -1595,6 +1609,10 @@ sub new
}
}
+ my @scan_result = PostgreSQL::Test::Utils::scan_server_header(
+ 'access/xlog_internal.h',
+ '#define\s+XLOG_CONTROL_FILE\s+"(.*)"');
+ my $controlfile = $scan_result[0];
my $testname = basename($0);
$testname =~ s/\.[^.]+$//;
my $node = {
@@ -1607,7 +1625,8 @@ sub new
_logfile_base =>
"$PostgreSQL::Test::Utils::log_path/${testname}_${name}",
_logfile =>
- "$PostgreSQL::Test::Utils::log_path/${testname}_${name}.log"
+ "$PostgreSQL::Test::Utils::log_path/${testname}_${name}.log",
+ _controlfile => $controlfile
};
if ($params{install_path})
diff --git a/src/test/recovery/t/042_low_level_backup.pl b/src/test/recovery/t/042_low_level_backup.pl
index 5749a1df533..e2962536b2b 100644
--- a/src/test/recovery/t/042_low_level_backup.pl
+++ b/src/test/recovery/t/042_low_level_backup.pl
@@ -41,8 +41,9 @@ unlink("$backup_dir/postmaster.pid")
or BAIL_OUT("unable to unlink $backup_dir/postmaster.pid");
unlink("$backup_dir/postmaster.opts")
or BAIL_OUT("unable to unlink $backup_dir/postmaster.opts");
-unlink("$backup_dir/global/pg_control")
- or BAIL_OUT("unable to unlink $backup_dir/global/pg_control");
+my $controlfile = $node_primary->controlfile;
+unlink("$backup_dir/$controlfile")
+ or BAIL_OUT("unable to unlink $backup_dir/$controlfile");
rmtree("$backup_dir/pg_wal")
or BAIL_OUT("unable to unlink contents of $backup_dir/pg_wal");
@@ -69,9 +70,9 @@ $node_primary->poll_query_until('postgres',
$node_primary->safe_psql('postgres', "checkpoint");
# Copy pg_control last so it contains the new checkpoint.
-copy($node_primary->data_dir . '/global/pg_control',
- "$backup_dir/global/pg_control")
- or BAIL_OUT("unable to copy global/pg_control");
+copy($node_primary->data_dir . '/' . $controlfile,
+ "$backup_dir/$controlfile")
+ or BAIL_OUT("unable to copy $controlfile");
# Save the name segment that will be archived by pg_backup_stop().
# This is copied to the pg_wal directory of the node whose recovery
--
2.48.1
On 2025/04/05 8:27, Anton A. Melnikov wrote:
Hi!
On 04.04.2025 19:32, Fujii Masao wrote:
I'm not sure there's clear consensus yet on the changes in the 0001 and
0002 patches, and it might not be worth rushing them in right before
the feature freeze. So for now, I reviewed and updated only the 0003 patch,
since there seems to be agreement on that one.I've attached the updated version. It fixes a typo and replaces
the remaining hardcoded control file name with the XLOG_CONTROL_FILE macro.Thanks! Looks good for me.
Thanks for checking! Barring any objections, I'll go ahead and commit the patch.
Maybe extend this to perl tests since there are several hardcoded names too?
The patch attached tries to do this.
I had the same thought, i.e., we could use scan_server_header() to pull
XLOG_CONTROL_FILE from xlog_internal.h and replace the hardcoded "global/pg_control"
in the TAP tests. But for now, that feels like overkill, since the TAP tests already
have other hardcoded values like the WAL directory (pg_wal), and we haven't used
macros like XLOGDIR there either. Replacing just "global/pg_control" might feel
inconsistent, and handling the other cases properly would take more time beyond
feature freeze. So I'm thinking it's better to use XLOG_CONTROL_FILE only in
C code for now.
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
Hi!
On 05.04.2025 06:11, Fujii Masao wrote:
Thanks for checking! Barring any objections, I'll go ahead and commit the patch.
As for me all is ok. Thanks!
Maybe extend this to perl tests since there are several hardcoded names too?
The patch attached tries to do this.I had the same thought, i.e., we could use scan_server_header() to pull
XLOG_CONTROL_FILE from xlog_internal.h and replace the hardcoded "global/pg_control"
in the TAP tests. But for now, that feels like overkill, since the TAP tests already
have other hardcoded values like the WAL directory (pg_wal), and we haven't used
macros like XLOGDIR there either. Replacing just "global/pg_control" might feel
inconsistent, and handling the other cases properly would take more time beyond
feature freeze. So I'm thinking it's better to use XLOG_CONTROL_FILE only in
C code for now.
Agreed. Also think that it is better to fix all such places at once and some later.
Best wishes!
--
Anton A. Melnikov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
On 2025/04/06 4:10, Anton A. Melnikov wrote:
Hi!
On 05.04.2025 06:11, Fujii Masao wrote:
Thanks for checking! Barring any objections, I'll go ahead and commit the patch.
As for me all is ok. Thanks!
I've pushed the patch. Thanks!
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
On 07.04.2025 03:32, Fujii Masao wrote:
I've pushed the patch. Thanks!
Thanks! Have a nice day!
--
Anton A. Melnikov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company