Class Db2StreamingChangeEventSource
- All Implemented Interfaces:
io.debezium.pipeline.source.spi.ChangeEventSource,io.debezium.pipeline.source.spi.StreamingChangeEventSource<Db2Partition,Db2OffsetContext>
A StreamingChangeEventSource based on DB2 change data capture functionality.
A main loop polls database DDL change and change data tables and turns them into change events.
The connector uses CDC functionality of DB2 that is implemented as as a process that monitors source table and write changes from the table into the change table.
The main loop keeps a pointer to the LSN of changes that were already processed. It queries all change tables and get result set of changes. It always finds the smallest LSN across all tables and the change is converted into the event message and sent downstream. The process repeats until all result sets are empty. The LSN is marked and the procedure repeats.
The schema changes detection follows the procedure recommended by DB2 CDC documentation. The database operator should create one more capture process (and table) when a table schema is updated. The code detects presence of two change tables for a single source table. It decides which table is the new one depending on LSNs stored in them. The loop streams changes from the older table till there are events in new table with the LSN larger than in the old one. Then the change table is switched and streaming is executed from the new one.
- Author:
- Jiri Pechanec, Peter Urbanetz
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classThe logical representation of a position for the change in the transaction log.Nested classes/interfaces inherited from interface io.debezium.pipeline.source.spi.ChangeEventSource
io.debezium.pipeline.source.spi.ChangeEventSource.ChangeEventSourceContext -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final io.debezium.util.Clockprivate static final intprivate static final intprivate static final intprivate static final intprivate final Db2ConnectorConfigprivate final Db2ConnectionConnection used for reading CDC tables.private final io.debezium.pipeline.EventDispatcher<Db2Partition,io.debezium.relational.TableId> private final io.debezium.pipeline.ErrorHandlerprivate static final org.slf4j.Loggerprivate final Db2ConnectionA separate connection for retrieving timestamps; without it, adaptive buffering will not work.private static final Patternprivate final Durationprivate final Db2DatabaseSchema -
Constructor Summary
ConstructorsConstructorDescriptionDb2StreamingChangeEventSource(Db2ConnectorConfig connectorConfig, Db2Connection dataConnection, Db2Connection metadataConnection, io.debezium.pipeline.EventDispatcher<Db2Partition, io.debezium.relational.TableId> dispatcher, io.debezium.pipeline.ErrorHandler errorHandler, io.debezium.util.Clock clock, Db2DatabaseSchema schema) -
Method Summary
Modifier and TypeMethodDescriptionvoidexecute(io.debezium.pipeline.source.spi.ChangeEventSource.ChangeEventSourceContext context, Db2Partition partition, Db2OffsetContext offsetContext) private Db2ChangeTable[]getCdcTablesToQuery(Db2Partition partition, Db2OffsetContext offsetContext) private voidmigrateTable(Db2Partition partition, Db2OffsetContext offsetContext, Queue<Db2ChangeTable> schemaChangeCheckpoints) private Db2ChangeTable[]processErrorFromChangeTableQuery(SQLException exception, Db2ChangeTable[] currentChangeTables) Methods 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
commitOffset, executeIteration, init
-
Field Details
-
COL_COMMIT_LSN
private static final int COL_COMMIT_LSN- See Also:
-
COL_ROW_LSN
private static final int COL_ROW_LSN- See Also:
-
COL_OPERATION
private static final int COL_OPERATION- See Also:
-
COL_DATA
private static final int COL_DATA- See Also:
-
MISSING_CDC_FUNCTION_CHANGES_ERROR
-
LOGGER
private static final org.slf4j.Logger LOGGER -
dataConnection
Connection used for reading CDC tables. -
metadataConnection
A separate connection for retrieving timestamps; without it, adaptive buffering will not work. -
dispatcher
private final io.debezium.pipeline.EventDispatcher<Db2Partition,io.debezium.relational.TableId> dispatcher -
errorHandler
private final io.debezium.pipeline.ErrorHandler errorHandler -
clock
private final io.debezium.util.Clock clock -
schema
-
pollInterval
-
connectorConfig
-
-
Constructor Details
-
Db2StreamingChangeEventSource
public Db2StreamingChangeEventSource(Db2ConnectorConfig connectorConfig, Db2Connection dataConnection, Db2Connection metadataConnection, io.debezium.pipeline.EventDispatcher<Db2Partition, io.debezium.relational.TableId> dispatcher, io.debezium.pipeline.ErrorHandler errorHandler, io.debezium.util.Clock clock, Db2DatabaseSchema schema)
-
-
Method Details
-
execute
public void execute(io.debezium.pipeline.source.spi.ChangeEventSource.ChangeEventSourceContext context, Db2Partition partition, Db2OffsetContext offsetContext) throws InterruptedException - Specified by:
executein interfaceio.debezium.pipeline.source.spi.StreamingChangeEventSource<Db2Partition,Db2OffsetContext> - Throws:
InterruptedException
-
migrateTable
private void migrateTable(Db2Partition partition, Db2OffsetContext offsetContext, Queue<Db2ChangeTable> schemaChangeCheckpoints) throws InterruptedException, SQLException - Throws:
InterruptedExceptionSQLException
-
processErrorFromChangeTableQuery
private Db2ChangeTable[] processErrorFromChangeTableQuery(SQLException exception, Db2ChangeTable[] currentChangeTables) throws Exception - Throws:
Exception
-
getCdcTablesToQuery
private Db2ChangeTable[] getCdcTablesToQuery(Db2Partition partition, Db2OffsetContext offsetContext) throws SQLException, InterruptedException - Throws:
SQLExceptionInterruptedException
-