Class PostgresReadOnlyIncrementalSnapshotChangeEventSource<P extends PostgresPartition>

java.lang.Object
io.debezium.pipeline.source.snapshot.incremental.AbstractIncrementalSnapshotChangeEventSource<P,TableId>
io.debezium.connector.postgresql.PostgresReadOnlyIncrementalSnapshotChangeEventSource<P>
All Implemented Interfaces:
IncrementalSnapshotChangeEventSource<P,TableId>

public class PostgresReadOnlyIncrementalSnapshotChangeEventSource<P extends PostgresPartition> extends AbstractIncrementalSnapshotChangeEventSource<P,TableId>
A PostgreSQL specific read-only incremental snapshot change event source. Uses PgSnapshot as low/high watermarks for incremental snapshot window.

Prerequisites

  • PostgreSQL version >= 13

How a chunk is snapshotted

  • a pg_current_snapshot() query is executed and the low watermark is set to lowWatermark
  • a new data chunk is read from a database by generating the SELECT statement and placed into a window buffer keyed by primary keys
  • a pg_current_snapshot() query is executed and the high watermark is set to highWatermark

During the subsequent streaming

  • if WAL event is received and its txId is greater then or equal to xMin of the low watermark, then window processing mode is enabled
  • if WAL event is received and its txId is greater then the xMax of high watermark, then window processing mode is disabled and the rest of the window’s buffer is streamed
  • if window processing mode is enabled then if the event key is contained in the window buffer then it is removed from the window buffer
  • event is streamed



No binlog events

Heartbeat events (events that are sent when there are not changes from the WAL) are used to update the window processing mode when the rate of WAL updates is low.

The heartbeat has the same txId as the latest WAL event at the moment and it will used to continue to read chunks even there are not event coming from the WAL. This processing will end if the watermarks changes because that means there are some transaction potentially modifying data.


No changes between watermarks

A window can be opened and closed right away by the same event. This can happen when a high watermark and low watermark are the same, which means there were no active transaction during the chunk select. Chunk will get inserted right after the low watermark, no events will be deduplicated from the chunk


Author:
Mario Fiore Vitale