Package io.debezium.connector.postgresql
Class PostgresStreamingChangeEventSource
java.lang.Object
io.debezium.connector.postgresql.PostgresStreamingChangeEventSource
- All Implemented Interfaces:
ChangeEventSource,StreamingChangeEventSource<PostgresPartition,PostgresOffsetContext>
public class PostgresStreamingChangeEventSource
extends Object
implements StreamingChangeEventSource<PostgresPartition,PostgresOffsetContext>
- Author:
- Horia Chiorean (hchiorea@redhat.com), Jiri Pechanec
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceNested classes/interfaces inherited from interface io.debezium.pipeline.source.spi.ChangeEventSource
ChangeEventSource.ChangeEventSourceContext -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Clockprivate final PostgresConnectionprivate final ElapsedTimeStrategyprivate final PostgresConnectorConfigprivate final PostgresEventDispatcher<TableId>private final ErrorHandlerprivate static final intNumber of received events without sending anything to Kafka which will trigger a "WAL backlog growing" warning.private static final Stringprivate Lsnprivate static final org.slf4j.Loggerprivate booleanprivate longThe minimum of (number of event received since the last event sent to Kafka, number of event received since last WAL growing warning issued).private final DelayStrategyprivate final ReplicationConnectionprivate final AtomicReference<ReplicationStream>private final PostgresSchemaprivate final Snapshotterprivate final PostgresTaskContextprivate static final int -
Constructor Summary
ConstructorsConstructorDescriptionPostgresStreamingChangeEventSource(PostgresConnectorConfig connectorConfig, Snapshotter snapshotter, PostgresConnection connection, PostgresEventDispatcher<TableId> dispatcher, ErrorHandler errorHandler, Clock clock, PostgresSchema schema, PostgresTaskContext taskContext, ReplicationConnection replicationConnection) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcommitMessage(PostgresPartition partition, PostgresOffsetContext offsetContext, Lsn lsn) voidcommitOffset(Map<String, ?> partition, Map<String, ?> offset) voidexecute(ChangeEventSource.ChangeEventSourceContext context, PostgresPartition partition, PostgresOffsetContext offsetContext) voidinit()private booleanisInPreSnapshotCatchUpStreaming(PostgresOffsetContext offsetContext) Returns whether the current streaming phase is running a catch up streaming phase that runs before a snapshot.private voidmaybeWarnAboutGrowingWalBacklog(boolean dispatched) If we receive change events but all of them get filtered out, we cannot commit any new offset with Apache Kafka.private voidprivate voidprocessMessages(ChangeEventSource.ChangeEventSourceContext context, PostgresPartition partition, PostgresOffsetContext offsetContext, ReplicationStream stream) private voidsearchWalPosition(ChangeEventSource.ChangeEventSourceContext context, ReplicationStream stream, WalPositionLocator walPosition) private Longprivate StringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.debezium.pipeline.source.spi.StreamingChangeEventSource
executeIteration
-
Field Details
-
KEEP_ALIVE_THREAD_NAME
- See Also:
-
GROWING_WAL_WARNING_LOG_INTERVAL
private static final int GROWING_WAL_WARNING_LOG_INTERVALNumber of received events without sending anything to Kafka which will trigger a "WAL backlog growing" warning.- See Also:
-
LOGGER
private static final org.slf4j.Logger LOGGER -
THROTTLE_NO_MESSAGE_BEFORE_PAUSE
private static final int THROTTLE_NO_MESSAGE_BEFORE_PAUSE- See Also:
-
connection
-
dispatcher
-
errorHandler
-
clock
-
schema
-
connectorConfig
-
taskContext
-
replicationConnection
-
replicationStream
-
snapshotter
-
pauseNoMessage
-
connectionProbeTimer
-
lsnFlushingAllowed
private volatile boolean lsnFlushingAllowed -
numberOfEventsSinceLastEventSentOrWalGrowingWarning
private long numberOfEventsSinceLastEventSentOrWalGrowingWarningThe minimum of (number of event received since the last event sent to Kafka, number of event received since last WAL growing warning issued). -
lastCompletelyProcessedLsn
-
-
Constructor Details
-
PostgresStreamingChangeEventSource
public PostgresStreamingChangeEventSource(PostgresConnectorConfig connectorConfig, Snapshotter snapshotter, PostgresConnection connection, PostgresEventDispatcher<TableId> dispatcher, ErrorHandler errorHandler, Clock clock, PostgresSchema schema, PostgresTaskContext taskContext, ReplicationConnection replicationConnection)
-
-
Method Details
-
init
public void init()- Specified by:
initin interfaceStreamingChangeEventSource<PostgresPartition,PostgresOffsetContext>
-
execute
public void execute(ChangeEventSource.ChangeEventSourceContext context, PostgresPartition partition, PostgresOffsetContext offsetContext) throws InterruptedException - Specified by:
executein interfaceStreamingChangeEventSource<PostgresPartition,PostgresOffsetContext> - Throws:
InterruptedException
-
processMessages
private void processMessages(ChangeEventSource.ChangeEventSourceContext context, PostgresPartition partition, PostgresOffsetContext offsetContext, ReplicationStream stream) throws SQLException, InterruptedException - Throws:
SQLExceptionInterruptedException
-
searchWalPosition
private void searchWalPosition(ChangeEventSource.ChangeEventSourceContext context, ReplicationStream stream, WalPositionLocator walPosition) throws SQLException, InterruptedException - Throws:
SQLExceptionInterruptedException
-
probeConnectionIfNeeded
- Throws:
SQLException
-
commitMessage
private void commitMessage(PostgresPartition partition, PostgresOffsetContext offsetContext, Lsn lsn) throws SQLException, InterruptedException - Throws:
SQLExceptionInterruptedException
-
maybeWarnAboutGrowingWalBacklog
private void maybeWarnAboutGrowingWalBacklog(boolean dispatched) If we receive change events but all of them get filtered out, we cannot commit any new offset with Apache Kafka. This in turn means no LSN is ever acknowledged with the replication slot, causing any ever growing WAL backlog.This situation typically occurs if there are changes on the database server, (e.g. in an excluded database), but none of them is in table.include.list. To prevent this, heartbeats can be used, as they will allow us to commit offsets also when not propagating any "real" change event.
The purpose of this method is to detect this situation and log a warning every
GROWING_WAL_WARNING_LOG_INTERVALfiltered events.- Parameters:
dispatched- Whether an event was sent to the broker or not
-
commitOffset
- Specified by:
commitOffsetin interfaceStreamingChangeEventSource<PostgresPartition,PostgresOffsetContext>
-
isInPreSnapshotCatchUpStreaming
Returns whether the current streaming phase is running a catch up streaming phase that runs before a snapshot. This is useful for transaction management. During pre-snapshot catch up streaming, we open the snapshot transaction early and hold the transaction open throughout the pre snapshot catch up streaming phase so that we know where to stop streaming and can start the snapshot phase at a consistent location. This is opposed the regular streaming, where we do not a lingering open transaction.- Returns:
- true if the current streaming phase is performing catch up streaming
-
toLong
-
toString
-