Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 234a266

Browse files
committed
Fix code comments regarding logical decoding
Back in 3b02ea4 I added some comments in various places to explain how logical decoding and other things worked. Not all of the changes were welcome, because they were misleading or wrong. This changes them a little bit to make them more accurate. Some other comments are also changed to be more accurate. Also, fix a bunch of typos. Author: Álvaro Herrera, Craig Ringer Andres Freund reviewed some parts of this.
1 parent 21c2b1c commit 234a266

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

src/backend/replication/logical/logical.c

+15-7
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,18 @@ CreateInitDecodingContext(char *plugin,
305305
* Create a new decoding context, for a logical slot that has previously been
306306
* used already.
307307
*
308-
* start_lsn contains the LSN of the last received data or InvalidXLogRecPtr
309-
* output_plugin_options contains options passed to the output plugin
310-
* read_page, prepare_write, do_write are callbacks that have to be filled to
311-
* perform the use-case dependent, actual, work.
308+
* start_lsn
309+
* The LSN at which to start decoding. If InvalidXLogRecPtr, restart
310+
* from the slot's confirmed_flush; otherwise, start from the specified
311+
* location (but move it forwards to confirmed_flush if it's older than
312+
* that, see below).
313+
*
314+
* output_plugin_options
315+
* contains options passed to the output plugin.
316+
*
317+
* read_page, prepare_write, do_write
318+
* callbacks that have to be filled to perform the use-case dependent,
319+
* actual work.
312320
*
313321
* Needs to be called while in a memory context that's at least as long lived
314322
* as the decoding context because further memory contexts will be created
@@ -745,7 +753,7 @@ message_cb_wrapper(ReorderBuffer *cache, ReorderBufferTXN *txn,
745753
* replication slot.
746754
*
747755
* Note that in the most cases, we won't be able to immediately use the xmin
748-
* to increase the xmin horizon, we need to wait till the client has confirmed
756+
* to increase the xmin horizon: we need to wait till the client has confirmed
749757
* receiving current_lsn with LogicalConfirmReceivedLocation().
750758
*/
751759
void
@@ -890,7 +898,7 @@ LogicalConfirmReceivedLocation(XLogRecPtr lsn)
890898

891899
MyReplicationSlot->data.confirmed_flush = lsn;
892900

893-
/* if were past the location required for bumping xmin, do so */
901+
/* if we're past the location required for bumping xmin, do so */
894902
if (MyReplicationSlot->candidate_xmin_lsn != InvalidXLogRecPtr &&
895903
MyReplicationSlot->candidate_xmin_lsn <= lsn)
896904
{
@@ -926,7 +934,7 @@ LogicalConfirmReceivedLocation(XLogRecPtr lsn)
926934

927935
SpinLockRelease(&MyReplicationSlot->mutex);
928936

929-
/* first write new xmin to disk, so we know whats up after a crash */
937+
/* first write new xmin to disk, so we know what's up after a crash */
930938
if (updated_xmin || updated_restart)
931939
{
932940
ReplicationSlotMarkDirty();

src/backend/replication/logical/logicalfuncs.c

+4-11
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,7 @@ pg_logical_slot_get_changes_guts(FunctionCallInfo fcinfo, bool confirm, bool bin
238238

239239
PG_TRY();
240240
{
241-
/*
242-
* Passing InvalidXLogRecPtr here causes replay to start at the slot's
243-
* confirmed_flush.
244-
*/
241+
/* restart at slot's confirmed_flush */
245242
ctx = CreateDecodingContext(InvalidXLogRecPtr,
246243
options,
247244
logical_read_local_xlog_page,
@@ -265,13 +262,9 @@ pg_logical_slot_get_changes_guts(FunctionCallInfo fcinfo, bool confirm, bool bin
265262
ctx->output_writer_private = p;
266263

267264
/*
268-
* We start reading xlog from the restart lsn, even though in
269-
* CreateDecodingContext we set the snapshot builder up using the
270-
* slot's confirmed_flush. This means we might read xlog we don't
271-
* actually decode rows from, but the snapshot builder might need it
272-
* to get to a consistent point. The point we start returning data to
273-
* *users* at is the confirmed_flush lsn set up in the decoding
274-
* context.
265+
* Decoding of WAL must start at restart_lsn so that the entirety of
266+
* xacts that committed after the slot's confirmed_flush can be
267+
* accumulated into reorder buffers.
275268
*/
276269
startptr = MyReplicationSlot->data.restart_lsn;
277270

src/include/replication/slot.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ typedef struct ReplicationSlotPersistentData
6666
/* oldest LSN that might be required by this replication slot */
6767
XLogRecPtr restart_lsn;
6868

69-
/* oldest LSN that the client has acked receipt for */
69+
/*
70+
* Oldest LSN that the client has acked receipt for. This is used as the
71+
* start_lsn point in case the client doesn't specify one, and also as a
72+
* safety measure to back off in case the client specifies a start_lsn
73+
* that's further in the future than this value.
74+
*/
7075
XLogRecPtr confirmed_flush;
7176

7277
/* plugin name */
@@ -113,11 +118,10 @@ typedef struct ReplicationSlot
113118

114119
/* all the remaining data is only used for logical slots */
115120

116-
/* ----
121+
/*
117122
* When the client has confirmed flushes >= candidate_xmin_lsn we can
118-
* advance the catalog xmin, when restart_valid has been passed,
123+
* advance the catalog xmin. When restart_valid has been passed,
119124
* restart_lsn can be increased.
120-
* ----
121125
*/
122126
TransactionId candidate_catalog_xmin;
123127
XLogRecPtr candidate_xmin_lsn;

0 commit comments

Comments
 (0)