Pass correct count to WALRead().
authorJeff Davis <jdavis@postgresql.org>
Fri, 16 Feb 2024 19:09:11 +0000 (11:09 -0800)
committerJeff Davis <jdavis@postgresql.org>
Fri, 16 Feb 2024 19:09:11 +0000 (11:09 -0800)
Previously, some callers requested XLOG_BLCKSZ bytes
unconditionally. While this did not cause a problem, because the extra
bytes are ignored, it's confusing and makes it harder to add safety
checks. Additionally, the comment about zero padding was incorrect.

With this commit, all callers request the number of bytes they
actually need.

Author: Bharath Rupireddy
Reviewed-by: Kyotaro Horiguchi
Discussion: https://postgr.es/m/CALj2ACWBRFac2TingD3PE3w2EBHXUHY3=AEEZPJmqhpEOBGExg@mail.gmail.com

src/backend/access/transam/xlogutils.c
src/backend/postmaster/walsummarizer.c
src/backend/replication/walsender.c

index 945f1f790d5ba70ee79b92f37e57ee8d25f5b06a..ad93035d508aa752f6c4262ee72c982629fc6a77 100644 (file)
@@ -1007,12 +1007,7 @@ read_local_xlog_page_guts(XLogReaderState *state, XLogRecPtr targetPagePtr,
        count = read_upto - targetPagePtr;
    }
 
-   /*
-    * Even though we just determined how much of the page can be validly read
-    * as 'count', read the whole page anyway. It's guaranteed to be
-    * zero-padded up to the page boundary if it's incomplete.
-    */
-   if (!WALRead(state, cur_page, targetPagePtr, XLOG_BLCKSZ, tli,
+   if (!WALRead(state, cur_page, targetPagePtr, count, tli,
                 &errinfo))
        WALReadRaiseError(&errinfo);
 
index 3e1b146538689a6ff673b6eb7567b65a51866b74..e85d4970347b41ddb8d30a08a693412a4c64f9b6 100644 (file)
@@ -1318,12 +1318,7 @@ summarizer_read_local_xlog_page(XLogReaderState *state,
        }
    }
 
-   /*
-    * Even though we just determined how much of the page can be validly read
-    * as 'count', read the whole page anyway. It's guaranteed to be
-    * zero-padded up to the page boundary if it's incomplete.
-    */
-   if (!WALRead(state, cur_page, targetPagePtr, XLOG_BLCKSZ,
+   if (!WALRead(state, cur_page, targetPagePtr, count,
                 private_data->tli, &errinfo))
        WALReadRaiseError(&errinfo);
 
index e5477c1de1b986f99c1ebade0ed49dd0a826da42..631d1e0c9fd49f84cfdfd94c4485c960b3bcb314 100644 (file)
@@ -1099,7 +1099,7 @@ logical_read_xlog_page(XLogReaderState *state, XLogRecPtr targetPagePtr, int req
    if (!WALRead(state,
                 cur_page,
                 targetPagePtr,
-                XLOG_BLCKSZ,
+                count,
                 currTLI,       /* Pass the current TLI because only
                                 * WalSndSegmentOpen controls whether new TLI
                                 * is needed. */