diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2020-01-26 11:39:00 +0200 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2020-01-26 11:39:00 +0200 |
commit | 38a957316d7e46d4b00de40f43966984a463d80a (patch) | |
tree | 934783998a89f750ce3306561b9ea23acd185e51 /src/backend/replication/logical/logical.c | |
parent | 10013684970453a0ddc86050bba813c611114321 (diff) | |
download | postgresql-38a957316d7e46d4b00de40f43966984a463d80a.tar.gz |
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
Diffstat (limited to 'src/backend/replication/logical/logical.c')
-rw-r--r-- | src/backend/replication/logical/logical.c | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c index bdf4389a57..cf93200618 100644 --- a/src/backend/replication/logical/logical.c +++ b/src/backend/replication/logical/logical.c @@ -461,11 +461,10 @@ DecodingContextReady(LogicalDecodingContext *ctx) void DecodingContextFindStartpoint(LogicalDecodingContext *ctx) { - XLogRecPtr startptr; ReplicationSlot *slot = ctx->slot; /* Initialize from where to start reading WAL. */ - startptr = slot->data.restart_lsn; + XLogBeginRead(ctx->reader, slot->data.restart_lsn); elog(DEBUG1, "searching for logical decoding starting point, starting at %X/%X", (uint32) (slot->data.restart_lsn >> 32), @@ -478,14 +477,12 @@ DecodingContextFindStartpoint(LogicalDecodingContext *ctx) char *err = NULL; /* the read_page callback waits for new WAL */ - record = XLogReadRecord(ctx->reader, startptr, &err); + record = XLogReadRecord(ctx->reader, &err); if (err) elog(ERROR, "%s", err); if (!record) elog(ERROR, "no record found"); /* shouldn't happen */ - startptr = InvalidXLogRecPtr; - LogicalDecodingProcessRecord(ctx, ctx->reader); /* only continue till we found a consistent spot */ |