Simplify xlogreader.c with XLogRec* macros

Started by Yuhang Qiualmost 3 years ago5 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

appliessuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t48673
psql -h localhost -U postgres

Built from patchset v3 (message #3), October 06, 2026 at 08:19 AM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t48673_3 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t48673_3 && git checkout t48673_3

Patchset v3 (message #3) is on t48673_3

Jump to latest
#1Yuhang Qiu
iamqyh@gmail.com

Hello hackers,

Commit 3f1ce97 refactored XLog record access macros, but missed in a few places. I fixed this, and patch is attached.

--
Yuhang Qiu

Attachments:

0001-Simplify-xlogreader.c-with-XLogRec-macros.patchapplication/octet-stream; name=0001-Simplify-xlogreader.c-with-XLogRec-macros.patch; x-unix-mode=0644Download+7-9
#2Junwang Zhao
zhjwpku@gmail.com
In reply to: Yuhang Qiu (#1)
Re: Simplify xlogreader.c with XLogRec* macros

On Tue, Oct 31, 2023 at 5:23 PM 邱宇航 <iamqyh@gmail.com> wrote:

Hello hackers,

Commit 3f1ce97 refactored XLog record access macros, but missed in a few places. I fixed this, and patch is attached.

--
Yuhang Qiu

@@ -2036,8 +2035,8 @@ RestoreBlockImage(XLogReaderState *record, uint8
block_id, char *page)
char *ptr;
PGAlignedBlock tmp;

- if (block_id > record->record->max_block_id ||
- !record->record->blocks[block_id].in_use)
+ if (block_id > XLogRecMaxBlockId(record) ||
+ !XLogRecGetBlock(record, block_id)->in_use)

I thought these can also be rewrite to:

if (!XLogRecHasBlockRef(record, block_id))

--
Regards
Junwang Zhao

#3Yuhang Qiu
iamqyh@gmail.com
In reply to: Junwang Zhao (#2)
Re: Simplify xlogreader.c with XLogRec* macros

@@ -2036,8 +2035,8 @@ RestoreBlockImage(XLogReaderState *record, uint8
block_id, char *page)
char *ptr;
PGAlignedBlock tmp;

- if (block_id > record->record->max_block_id ||
- !record->record->blocks[block_id].in_use)
+ if (block_id > XLogRecMaxBlockId(record) ||
+ !XLogRecGetBlock(record, block_id)->in_use)

I thought these can also be rewrite to:

if (!XLogRecHasBlockRef(record, block_id))

Oops, I missed that. New version is attached.

--
Yuhang Qiu

Attachments:

t48673_3
v2-0001-Simplify-xlogreader.c-with-XLogRec-macros.patchapplication/octet-stream; name=v2-0001-Simplify-xlogreader.c-with-XLogRec-macros.patch; x-unix-mode=0644Download+6-9
#4Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com
In reply to: Yuhang Qiu (#3)
Re: Simplify xlogreader.c with XLogRec* macros

On Tue, Oct 31, 2023 at 4:12 PM 邱宇航 <iamqyh@gmail.com> wrote:

I thought these can also be rewrite to:

if (!XLogRecHasBlockRef(record, block_id))

Oops, I missed that. New version is attached.

+1. Indeed a reasonable change. The attached v2 patch LGTM.

--
Bharath Rupireddy
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

#5Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com
In reply to: Bharath Rupireddy (#4)
Re: Simplify xlogreader.c with XLogRec* macros

On Fri, Nov 3, 2023 at 12:01 AM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:

On Tue, Oct 31, 2023 at 4:12 PM 邱宇航 <iamqyh@gmail.com> wrote:

I thought these can also be rewrite to:

if (!XLogRecHasBlockRef(record, block_id))

Oops, I missed that. New version is attached.

+1. Indeed a reasonable change. The attached v2 patch LGTM.

This patch basically uses the macros introduced by commit 3f1ce97 [1]commit 3f1ce973467a0d285961bf2f99b11d06e264e2c1 Author: Thomas Munro <tmunro@postgresql.org> Date: Fri Mar 18 17:45:04 2022 +1300
more extensively. I don't see a CF entry added for this patch. Please
add one if not added.

[1]: commit 3f1ce973467a0d285961bf2f99b11d06e264e2c1 Author: Thomas Munro <tmunro@postgresql.org> Date: Fri Mar 18 17:45:04 2022 +1300
commit 3f1ce973467a0d285961bf2f99b11d06e264e2c1
Author: Thomas Munro <tmunro@postgresql.org>
Date: Fri Mar 18 17:45:04 2022 +1300

Add circular WAL decoding buffer, take II.

--
Bharath Rupireddy
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com