Class PostgresReadOnlyIncrementalSnapshotChangeEventSource<P extends PostgresPartition>
- All Implemented Interfaces:
IncrementalSnapshotChangeEventSource<P,TableId>
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
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final Stringprivate final PostgresConnectionprivate static final org.slf4j.Loggerprivate final PostgresSchemaFields inherited from class io.debezium.pipeline.source.snapshot.incremental.AbstractIncrementalSnapshotChangeEventSource
chunkQueryBuilder, connectorConfig, context, dispatcher, notificationService, window -
Constructor Summary
ConstructorsConstructorDescriptionPostgresReadOnlyIncrementalSnapshotChangeEventSource(RelationalDatabaseConnectorConfig config, JdbcConnection jdbcConnection, EventDispatcher<P, TableId> dispatcher, DatabaseSchema<?> databaseSchema, Clock clock, SnapshotProgressListener<P> progressListener, DataChangeEventListener<P> dataChangeEventListener, NotificationService<P, ? extends OffsetContext> notificationService) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidemitWindowClose(P partition, OffsetContext offsetContext) protected voidprivate voidprivate voidgetCurrentSnapshot(Consumer<PgSnapshot> watermark) private booleanmaxInProgressTransactionCommitted(Long eventTxId) protected voidvoidprocessHeartbeat(P partition, OffsetContext offsetContext) voidprocessMessage(P partition, io.debezium.spi.schema.DataCollectionId dataCollectionId, Object key, OffsetContext offsetContext) voidprocessTransactionCommittedEvent(P partition, OffsetContext offsetContext) private voidreadUntilNewTransactionChange(P partition, OffsetContext offsetContext) protected TablerefreshTableSchema(Table table) Methods inherited from class io.debezium.pipeline.source.snapshot.incremental.AbstractIncrementalSnapshotChangeEventSource
addDataCollectionNamesToSnapshot, closeWindow, deduplicateWindow, getChangeRecordEmitter, getSignalTableName, init, pauseSnapshot, postIncrementalSnapshotCompleted, postReadChunk, preReadChunk, processSchemaChange, readChunk, rereadChunk, resumeSnapshot, sendEvent, sendWindowEvents, setContext, stopSnapshotMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.debezium.pipeline.source.snapshot.incremental.IncrementalSnapshotChangeEventSource
processFilteredEvent, processTransactionStartedEvent
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
FORCE_NEW_TRANSACTION
- See Also:
-
CURRENT_SNAPSHOT
- See Also:
-
jdbcConnection
-
schema
-
-
Constructor Details
-
PostgresReadOnlyIncrementalSnapshotChangeEventSource
public PostgresReadOnlyIncrementalSnapshotChangeEventSource(RelationalDatabaseConnectorConfig config, JdbcConnection jdbcConnection, EventDispatcher<P, TableId> dispatcher, DatabaseSchema<?> databaseSchema, Clock clock, SnapshotProgressListener<P> progressListener, DataChangeEventListener<P> dataChangeEventListener, NotificationService<P, ? extends OffsetContext> notificationService)
-
-
Method Details
-
preIncrementalSnapshotStart
protected void preIncrementalSnapshotStart()- Overrides:
preIncrementalSnapshotStartin classAbstractIncrementalSnapshotChangeEventSource<P extends PostgresPartition,TableId>
-
getContext
-
emitWindowOpen
protected void emitWindowOpen()- Specified by:
emitWindowOpenin classAbstractIncrementalSnapshotChangeEventSource<P extends PostgresPartition,TableId>
-
emitWindowClose
- Specified by:
emitWindowClosein classAbstractIncrementalSnapshotChangeEventSource<P extends PostgresPartition,TableId>
-
processMessage
public void processMessage(P partition, io.debezium.spi.schema.DataCollectionId dataCollectionId, Object key, OffsetContext offsetContext) throws InterruptedException - Throws:
InterruptedException
-
processTransactionCommittedEvent
public void processTransactionCommittedEvent(P partition, OffsetContext offsetContext) throws InterruptedException - Throws:
InterruptedException
-
processHeartbeat
- Throws:
InterruptedException
-
refreshTableSchema
- Overrides:
refreshTableSchemain classAbstractIncrementalSnapshotChangeEventSource<P extends PostgresPartition,TableId> - Throws:
SQLException
-
readUntilNewTransactionChange
private void readUntilNewTransactionChange(P partition, OffsetContext offsetContext) throws InterruptedException - Throws:
InterruptedException
-
getCurrentSnapshot
-
maxInProgressTransactionCommitted
-
forceNewTransactionId
private void forceNewTransactionId()
-