Class SqlServerStreamingChangeEventSource
- java.lang.Object
-
- io.debezium.connector.sqlserver.SqlServerStreamingChangeEventSource
-
- All Implemented Interfaces:
ChangeEventSource,StreamingChangeEventSource
public class SqlServerStreamingChangeEventSource extends Object implements StreamingChangeEventSource
A
StreamingChangeEventSourcebased on SQL Server 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 SQL Server 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 SQL Server 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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.debezium.pipeline.source.spi.ChangeEventSource
ChangeEventSource.ChangeEventSourceContext
-
-
Field Summary
Fields Modifier and Type Field Description private Clockclockprivate SqlServerConnectorConfigconnectorConfigprivate SqlServerConnectiondataConnectionConnection used for reading CDC tables.private EventDispatcher<TableId>dispatcherprivate ErrorHandlererrorHandlerprivate static org.slf4j.LoggerLOGGERprivate SqlServerConnectionmetadataConnectionA separate connection for retrieving timestamps; without it, adaptive buffering will not work.private static PatternMISSING_CDC_FUNCTION_CHANGES_ERRORprivate SqlServerOffsetContextoffsetContextprivate DurationpollIntervalprivate SqlServerDatabaseSchemaschema
-
Constructor Summary
Constructors Constructor Description SqlServerStreamingChangeEventSource(SqlServerConnectorConfig connectorConfig, SqlServerOffsetContext offsetContext, SqlServerConnection dataConnection, SqlServerConnection metadataConnection, EventDispatcher<TableId> dispatcher, ErrorHandler errorHandler, Clock clock, SqlServerDatabaseSchema schema)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidexecute(ChangeEventSource.ChangeEventSourceContext context)private SqlServerChangeTable[]getCdcTablesToQuery()private voidmigrateTable(Queue<SqlServerChangeTable> schemaChangeCheckpoints)private SqlServerChangeTable[]processErrorFromChangeTableQuery(SQLException exception, SqlServerChangeTable[] currentChangeTables)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.debezium.pipeline.source.spi.StreamingChangeEventSource
commitOffset
-
-
-
-
Field Detail
-
MISSING_CDC_FUNCTION_CHANGES_ERROR
private static final Pattern MISSING_CDC_FUNCTION_CHANGES_ERROR
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
dataConnection
private final SqlServerConnection dataConnection
Connection used for reading CDC tables.
-
metadataConnection
private final SqlServerConnection metadataConnection
A separate connection for retrieving timestamps; without it, adaptive buffering will not work.
-
dispatcher
private final EventDispatcher<TableId> dispatcher
-
errorHandler
private final ErrorHandler errorHandler
-
clock
private final Clock clock
-
schema
private final SqlServerDatabaseSchema schema
-
offsetContext
private final SqlServerOffsetContext offsetContext
-
pollInterval
private final Duration pollInterval
-
connectorConfig
private final SqlServerConnectorConfig connectorConfig
-
-
Constructor Detail
-
SqlServerStreamingChangeEventSource
public SqlServerStreamingChangeEventSource(SqlServerConnectorConfig connectorConfig, SqlServerOffsetContext offsetContext, SqlServerConnection dataConnection, SqlServerConnection metadataConnection, EventDispatcher<TableId> dispatcher, ErrorHandler errorHandler, Clock clock, SqlServerDatabaseSchema schema)
-
-
Method Detail
-
execute
public void execute(ChangeEventSource.ChangeEventSourceContext context) throws InterruptedException
- Specified by:
executein interfaceStreamingChangeEventSource- Throws:
InterruptedException
-
migrateTable
private void migrateTable(Queue<SqlServerChangeTable> schemaChangeCheckpoints) throws InterruptedException, SQLException
- Throws:
InterruptedExceptionSQLException
-
processErrorFromChangeTableQuery
private SqlServerChangeTable[] processErrorFromChangeTableQuery(SQLException exception, SqlServerChangeTable[] currentChangeTables) throws Exception
- Throws:
Exception
-
getCdcTablesToQuery
private SqlServerChangeTable[] getCdcTablesToQuery() throws SQLException, InterruptedException
- Throws:
SQLExceptionInterruptedException
-
-