public class Db2StreamingChangeEventSource extends Object implements io.debezium.pipeline.source.spi.StreamingChangeEventSource
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.
| Modifier and Type | Class and Description |
|---|---|
private static class |
Db2StreamingChangeEventSource.ChangeTablePointer
The logical representation of a position for the change in the transaction log.
|
| Modifier and Type | Field and Description |
|---|---|
private io.debezium.util.Clock |
clock |
private static int |
COL_COMMIT_LSN |
private static int |
COL_DATA |
private static int |
COL_OPERATION |
private static int |
COL_ROW_LSN |
private Db2ConnectorConfig |
connectorConfig |
private Db2Connection |
dataConnection
Connection used for reading CDC tables.
|
private io.debezium.pipeline.EventDispatcher<io.debezium.relational.TableId> |
dispatcher |
private io.debezium.pipeline.ErrorHandler |
errorHandler |
private static org.slf4j.Logger |
LOGGER |
private Db2Connection |
metadataConnection
A separate connection for retrieving timestamps; without it, adaptive
buffering will not work.
|
private static Pattern |
MISSING_CDC_FUNCTION_CHANGES_ERROR |
private Db2OffsetContext |
offsetContext |
private Duration |
pollInterval |
private Db2DatabaseSchema |
schema |
| Constructor and Description |
|---|
Db2StreamingChangeEventSource(Db2ConnectorConfig connectorConfig,
Db2OffsetContext offsetContext,
Db2Connection dataConnection,
Db2Connection metadataConnection,
io.debezium.pipeline.EventDispatcher<io.debezium.relational.TableId> dispatcher,
io.debezium.pipeline.ErrorHandler errorHandler,
io.debezium.util.Clock clock,
Db2DatabaseSchema schema) |
| Modifier and Type | Method and Description |
|---|---|
void |
execute(io.debezium.pipeline.source.spi.ChangeEventSource.ChangeEventSourceContext context) |
private Db2ChangeTable[] |
getCdcTablesToQuery() |
private void |
migrateTable(Queue<Db2ChangeTable> schemaChangeCheckpoints) |
private Db2ChangeTable[] |
processErrorFromChangeTableQuery(SQLException exception,
Db2ChangeTable[] currentChangeTables) |
private static final int COL_COMMIT_LSN
private static final int COL_ROW_LSN
private static final int COL_OPERATION
private static final int COL_DATA
private static final Pattern MISSING_CDC_FUNCTION_CHANGES_ERROR
private static final org.slf4j.Logger LOGGER
private final Db2Connection dataConnection
private final Db2Connection metadataConnection
private final io.debezium.pipeline.EventDispatcher<io.debezium.relational.TableId> dispatcher
private final io.debezium.pipeline.ErrorHandler errorHandler
private final io.debezium.util.Clock clock
private final Db2DatabaseSchema schema
private final Db2OffsetContext offsetContext
private final Duration pollInterval
private final Db2ConnectorConfig connectorConfig
public Db2StreamingChangeEventSource(Db2ConnectorConfig connectorConfig, Db2OffsetContext offsetContext, Db2Connection dataConnection, Db2Connection metadataConnection, io.debezium.pipeline.EventDispatcher<io.debezium.relational.TableId> dispatcher, io.debezium.pipeline.ErrorHandler errorHandler, io.debezium.util.Clock clock, Db2DatabaseSchema schema)
public void execute(io.debezium.pipeline.source.spi.ChangeEventSource.ChangeEventSourceContext context)
throws InterruptedException
execute in interface io.debezium.pipeline.source.spi.StreamingChangeEventSourceInterruptedExceptionprivate void migrateTable(Queue<Db2ChangeTable> schemaChangeCheckpoints) throws InterruptedException, SQLException
InterruptedExceptionSQLExceptionprivate Db2ChangeTable[] processErrorFromChangeTableQuery(SQLException exception, Db2ChangeTable[] currentChangeTables) throws Exception
Exceptionprivate Db2ChangeTable[] getCdcTablesToQuery() throws SQLException, InterruptedException
SQLExceptionInterruptedExceptionCopyright © 2020 JBoss by Red Hat. All rights reserved.