[PATCH] Add missing XLogEnsureRecordSpace() call in LogLogicalMessage - Mailing list pgsql-hackers

From Henson Choi
Subject [PATCH] Add missing XLogEnsureRecordSpace() call in LogLogicalMessage
Date
Msg-id CAAAe_zC44MXjAOp394mwjWVqUUenyQuaAb7XTghrsGjG7y4Y4A@mail.gmail.com
Whole thread Raw
Responses Re: [PATCH] Add missing XLogEnsureRecordSpace() call in LogLogicalMessage
List pgsql-hackers
Hi hackers,

LogLogicalMessage() in src/backend/replication/logical/message.c is
missing the XLogEnsureRecordSpace() call that appears before every
other XLogBeginInsert() in the codebase.

While this currently works because the 3 rdatas used here fit within
the default allocation of MAX_GENERIC_XLOG_RDATAS (20), this pattern
inconsistency could cause issues if:

1. MAX_GENERIC_XLOG_RDATAS is reduced in the future
2. This function is modified to use more rdatas
3. Someone copies this code without realizing the omission

All other WAL insertion code follows the pattern of calling
XLogEnsureRecordSpace() before XLogBeginInsert(). This patch adds
the missing call for consistency.

 XLogRecPtr
 LogLogicalMessage(const char *prefix, const char *message, size_t size,
                   bool transactional, bool flush)
 {
     ...
     xlrec.prefix_size = strlen(prefix) + 1;
     xlrec.message_size = size;
     
+    XLogEnsureRecordSpace(0, 3);
     XLogBeginInsert();
     XLogRegisterData(&xlrec, SizeOfLogicalMessage);
     XLogRegisterData(prefix, xlrec.prefix_size);
     XLogRegisterData(message, size);
     ...
 }

Best regards,
Henson

pgsql-hackers by date:

Previous
From: Tomas Vondra
Date:
Subject: Re: RFC: PostgreSQL Storage I/O Transformation Hooks
Next
From: jian he
Date:
Subject: Re: Fix ALTER TABLE DROP EXPRESSION with inheritance hierarchy