Re: [HACKERS] Logical decoding - Mailing list pgsql-committers

From Craig Ringer
Subject Re: [HACKERS] Logical decoding
Date
Msg-id CAMsr+YE029uoBuQoGBJEckReat=r7ZYhc24LTrE53MxXL2u7oQ@mail.gmail.com
Whole thread Raw
In response to Logical decoding  (Joshua Bay <joshuabay93@gmail.com>)
List pgsql-committers


On 9 July 2016 at 01:57, Joshua Bay <joshuabay93@gmail.com> wrote:
 

where are the entry points to logical decoding? 


Well, it depends on what level you're looking at.

Data is read using the xlogreader and fed into the decoding system by the walsender (when using a logical slot) and the SQL level pg_logical_slot_[get|peek]_changes functions. See XLogSendLogical() as called by WalSndLoop() and see pg_logical_slot_get_changes_guts() .

WAL records are passed through to logical decoding and depending on the xlog entry type the reorder buffer and/or snapshot builder. Then when a transaction commit is detected the registered output plugin is invoked and its callbacks are used to process the buffered transaction.
 

Specifically, we want to know whether logical decoding happens immediately after commit, or whether there is a polling thread that scans the Write Ahead Log and then dumps to the special table?


There's no "polling thread", but that's probably the closer of the two. A walsender using a logical slot reads WAL as it becomes available. It sleeps on a latch if it runs out of WAL to read and is woken when there's more. It isn't dumped to some special table, it's managed by the reorder buffer infrastructure which uses its own special data structures. Reading may lag behind WAL generation since it's "pulled" by the client and happens lazily after commit.
 

and where are this code is in the codebase?



src/backend/replication/logical/*
src/backend/replication/walsender.c
src/backend/access/transam/xlogreader.c
src/include/access/xlogreader.h
src/include/replication/output_plugin.h
contrib/test_decoding/
doc/src/sgml/logicaldecoding.sgml




--
 Craig Ringer                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Revert "Add some temporary code to record stack usage at server
Next
From: Magnus Hagander
Date:
Subject: pgsql: Fix start WAL filename for concurrent backups from standby