Class SqlServerStreamingChangeEventSource
- java.lang.Object
-
- io.debezium.connector.sqlserver.SqlServerStreamingChangeEventSource
-
- All Implemented Interfaces:
io.debezium.pipeline.source.spi.ChangeEventSource,io.debezium.pipeline.source.spi.StreamingChangeEventSource<io.debezium.connector.sqlserver.SqlServerPartition,SqlServerOffsetContext>
- Direct Known Subclasses:
SqlServerStreamFetchTask.StreamSplitReadTask
public class SqlServerStreamingChangeEventSource extends Object implements io.debezium.pipeline.source.spi.StreamingChangeEventSource<io.debezium.connector.sqlserver.SqlServerPartition,SqlServerOffsetContext>
Copied from Debezium project(1.9.8.final) to add methodafterHandleLsn(SqlServerPartition, Lsn). Also implementedexecute(ChangeEventSourceContext, SqlServerPartition, SqlServerOffsetContext). AStreamingChangeEventSourcebased 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.
-
-
Constructor Summary
Constructors Constructor Description SqlServerStreamingChangeEventSource(io.debezium.connector.sqlserver.SqlServerConnectorConfig connectorConfig, io.debezium.connector.sqlserver.SqlServerConnection dataConnection, io.debezium.connector.sqlserver.SqlServerConnection metadataConnection, io.debezium.pipeline.EventDispatcher<io.debezium.connector.sqlserver.SqlServerPartition,io.debezium.relational.TableId> dispatcher, io.debezium.pipeline.ErrorHandler errorHandler, io.debezium.util.Clock clock, io.debezium.connector.sqlserver.SqlServerDatabaseSchema schema)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidafterHandleLsn(io.debezium.connector.sqlserver.SqlServerPartition partition, io.debezium.connector.sqlserver.Lsn toLsn)expose control to the user to stop the connector.voidexecute(io.debezium.pipeline.source.spi.ChangeEventSource.ChangeEventSourceContext context, io.debezium.connector.sqlserver.SqlServerPartition partition, SqlServerOffsetContext offsetContext)booleanexecuteIteration(io.debezium.pipeline.source.spi.ChangeEventSource.ChangeEventSourceContext context, io.debezium.connector.sqlserver.SqlServerPartition partition, SqlServerOffsetContext offsetContext)
-
-
-
Constructor Detail
-
SqlServerStreamingChangeEventSource
public SqlServerStreamingChangeEventSource(io.debezium.connector.sqlserver.SqlServerConnectorConfig connectorConfig, io.debezium.connector.sqlserver.SqlServerConnection dataConnection, io.debezium.connector.sqlserver.SqlServerConnection metadataConnection, io.debezium.pipeline.EventDispatcher<io.debezium.connector.sqlserver.SqlServerPartition,io.debezium.relational.TableId> dispatcher, io.debezium.pipeline.ErrorHandler errorHandler, io.debezium.util.Clock clock, io.debezium.connector.sqlserver.SqlServerDatabaseSchema schema)
-
-
Method Detail
-
execute
public void execute(io.debezium.pipeline.source.spi.ChangeEventSource.ChangeEventSourceContext context, io.debezium.connector.sqlserver.SqlServerPartition partition, SqlServerOffsetContext offsetContext) throws InterruptedException- Specified by:
executein interfaceio.debezium.pipeline.source.spi.StreamingChangeEventSource<io.debezium.connector.sqlserver.SqlServerPartition,SqlServerOffsetContext>- Throws:
InterruptedException
-
executeIteration
public boolean executeIteration(io.debezium.pipeline.source.spi.ChangeEventSource.ChangeEventSourceContext context, io.debezium.connector.sqlserver.SqlServerPartition partition, SqlServerOffsetContext offsetContext) throws InterruptedException- Specified by:
executeIterationin interfaceio.debezium.pipeline.source.spi.StreamingChangeEventSource<io.debezium.connector.sqlserver.SqlServerPartition,SqlServerOffsetContext>- Throws:
InterruptedException
-
afterHandleLsn
protected void afterHandleLsn(io.debezium.connector.sqlserver.SqlServerPartition partition, io.debezium.connector.sqlserver.Lsn toLsn)expose control to the user to stop the connector.
-
-