mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +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:
@ -127,7 +127,6 @@ pg_logical_slot_get_changes_guts(FunctionCallInfo fcinfo, bool confirm, bool bin
|
||||
MemoryContext per_query_ctx;
|
||||
MemoryContext oldcontext;
|
||||
XLogRecPtr end_of_wal;
|
||||
XLogRecPtr startptr;
|
||||
LogicalDecodingContext *ctx;
|
||||
ResourceOwner old_resowner = CurrentResourceOwner;
|
||||
ArrayType *arr;
|
||||
@ -269,28 +268,21 @@ pg_logical_slot_get_changes_guts(FunctionCallInfo fcinfo, bool confirm, bool bin
|
||||
* xacts that committed after the slot's confirmed_flush can be
|
||||
* accumulated into reorder buffers.
|
||||
*/
|
||||
startptr = MyReplicationSlot->data.restart_lsn;
|
||||
XLogBeginRead(ctx->reader, MyReplicationSlot->data.restart_lsn);
|
||||
|
||||
/* invalidate non-timetravel entries */
|
||||
InvalidateSystemCaches();
|
||||
|
||||
/* Decode until we run out of records */
|
||||
while ((startptr != InvalidXLogRecPtr && startptr < end_of_wal) ||
|
||||
(ctx->reader->EndRecPtr != InvalidXLogRecPtr && ctx->reader->EndRecPtr < end_of_wal))
|
||||
while (ctx->reader->EndRecPtr < end_of_wal)
|
||||
{
|
||||
XLogRecord *record;
|
||||
char *errm = NULL;
|
||||
|
||||
record = XLogReadRecord(ctx->reader, startptr, &errm);
|
||||
record = XLogReadRecord(ctx->reader, &errm);
|
||||
if (errm)
|
||||
elog(ERROR, "%s", errm);
|
||||
|
||||
/*
|
||||
* Now that we've set up the xlog reader state, subsequent calls
|
||||
* pass InvalidXLogRecPtr to say "continue from last record"
|
||||
*/
|
||||
startptr = InvalidXLogRecPtr;
|
||||
|
||||
/*
|
||||
* The {begin_txn,change,commit_txn}_wrapper callbacks above will
|
||||
* store the description into our tuplestore.
|
||||
|
Reference in New Issue
Block a user