mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Refactor XLogReadRecord(), adding XLogBeginRead() function.
The signature of XLogReadRecord() required the caller to pass the starting WAL position as argument, or InvalidXLogRecPtr to continue reading at the end of previous record. That's slightly awkward to the callers, as most of them don't want to randomly jump around in the WAL stream, but start reading at one position and then read everything from that point onwards. Remove the 'RecPtr' argument and add a new function XLogBeginRead() to specify the starting position instead. That's more convenient for the callers. Also, xlogreader holds state that is reset when you change the starting position, so having a separate function for doing that feels like a more natural fit. This changes XLogFindNextRecord() function so that it doesn't reset the xlogreader's state to what it was before the call anymore. Instead, it positions the xlogreader to the found record, like XLogBeginRead(). Reviewed-by: Kyotaro Horiguchi, Alvaro Herrera Discussion: https://www.postgresql.org/message-id/5382a7a3-debe-be31-c860-cb810c08f366%40iki.fi
This commit is contained in:
@@ -391,7 +391,6 @@ pg_logical_replication_slot_advance(XLogRecPtr moveto)
|
||||
{
|
||||
LogicalDecodingContext *ctx;
|
||||
ResourceOwner old_resowner = CurrentResourceOwner;
|
||||
XLogRecPtr startlsn;
|
||||
XLogRecPtr retlsn;
|
||||
|
||||
PG_TRY();
|
||||
@@ -411,7 +410,7 @@ pg_logical_replication_slot_advance(XLogRecPtr moveto)
|
||||
* Start reading at the slot's restart_lsn, which we know to point to
|
||||
* a valid record.
|
||||
*/
|
||||
startlsn = MyReplicationSlot->data.restart_lsn;
|
||||
XLogBeginRead(ctx->reader, MyReplicationSlot->data.restart_lsn);
|
||||
|
||||
/* Initialize our return value in case we don't do anything */
|
||||
retlsn = MyReplicationSlot->data.confirmed_flush;
|
||||
@@ -420,10 +419,7 @@ pg_logical_replication_slot_advance(XLogRecPtr moveto)
|
||||
InvalidateSystemCaches();
|
||||
|
||||
/* Decode at least one record, until we run out of records */
|
||||
while ((!XLogRecPtrIsInvalid(startlsn) &&
|
||||
startlsn < moveto) ||
|
||||
(!XLogRecPtrIsInvalid(ctx->reader->EndRecPtr) &&
|
||||
ctx->reader->EndRecPtr < moveto))
|
||||
while (ctx->reader->EndRecPtr < moveto)
|
||||
{
|
||||
char *errm = NULL;
|
||||
XLogRecord *record;
|
||||
@@ -432,13 +428,10 @@ pg_logical_replication_slot_advance(XLogRecPtr moveto)
|
||||
* Read records. No changes are generated in fast_forward mode,
|
||||
* but snapbuilder/slot statuses are updated properly.
|
||||
*/
|
||||
record = XLogReadRecord(ctx->reader, startlsn, &errm);
|
||||
record = XLogReadRecord(ctx->reader, &errm);
|
||||
if (errm)
|
||||
elog(ERROR, "%s", errm);
|
||||
|
||||
/* Read sequentially from now on */
|
||||
startlsn = InvalidXLogRecPtr;
|
||||
|
||||
/*
|
||||
* Process the record. Storage-level changes are ignored in
|
||||
* fast_forward mode, but other modules (such as snapbuilder)
|
||||
|
Reference in New Issue
Block a user