From: Anton A. Melnikov <a.melnikov@postgrespro.ru>
To: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Cc: daniel@yesql.se
Cc: peter@eisentraut.org
Cc: tgl@sss.pgh.pa.us
Cc: robertmhaas@gmail.com
Cc: michael@paquier.xyz
Cc: pgsql-hackers@postgresql.org
Subject: Re: Use XLOG_CONTROL_FILE macro everywhere?
Date: Sat, 7 Sep 2024 10:38:06 +0300
Message-ID: <a131bf48-6d62-4b67-87e4-ff2c069350b2@postgrespro.ru> (raw)
In-Reply-To: <20240904.170927.1051663922860738119.horikyota.ntt@gmail.com>
References: <54B16BF2-6979-4BB0-BE39-118D32B1BC58@yesql.se>
<20240903.143756.562059416508617821.horikyota.ntt@gmail.com>
<fc33823e-dbdf-4f31-b9aa-bf7f758019b9@postgrespro.ru>
<20240904.170927.1051663922860738119.horikyota.ntt@gmail.com>
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.patch (text/x-patch, 6.2K) download
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.hindex 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.hnew file mode 100644index 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: a.melnikov@postgrespro.ru, horikyota.ntt@gmail.com, daniel@yesql.se, peter@eisentraut.org, tgl@sss.pgh.pa.us, robertmhaas@gmail.com, michael@paquier.xyz
Subject: Re: Use XLOG_CONTROL_FILE macro everywhere?
In-Reply-To: <a131bf48-6d62-4b67-87e4-ff2c069350b2@postgrespro.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox