Class MySqlConnectorTask
java.lang.Object
org.apache.kafka.connect.source.SourceTask
io.debezium.connector.common.BaseSourceTask<MySqlPartition,MySqlOffsetContext>
io.debezium.connector.mysql.legacy.MySqlConnectorTask
- All Implemented Interfaces:
org.apache.kafka.connect.connector.Task
@NotThreadSafe
public final class MySqlConnectorTask
extends BaseSourceTask<MySqlPartition,MySqlOffsetContext>
A Kafka Connect source task reads the MySQL binary log and generate the corresponding data change events.
- Author:
- Randall Hauch
- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class io.debezium.connector.common.BaseSourceTask
BaseSourceTask.State -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate MySqlJdbcContextprivate final org.slf4j.Loggerprivate ChainedReaderprivate MySqlTaskContextFields inherited from class org.apache.kafka.connect.source.SourceTask
context -
Constructor Summary
ConstructorsConstructorDescriptionCreate an instance of the log reader that uses Kafka to store database schema history and theTopicSelector.defaultSelector(String, String, String, TopicSelector.DataCollectionTopicNamer)of "<serverName>.<databaseName>.<tableName>" for data and "<serverName>" for metadata. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcompleteReaders(MySqlPartition partition) When the task isstopped, the readers may have additional work to perform before they actually stop and before all their records have been consumed via theBaseSourceTask.poll()method.private static MySqlTaskContextcreateAndStartTaskContext(Configuration config, Filters filters) List<org.apache.kafka.connect.source.SourceRecord>doPoll()protected voiddoStop()protected StringDetermine the earliest binlog filename that is still available in the server.private static FiltersgetAllFilters(Configuration config) Get the filters representing all tables represented by the config.private static FiltersgetNewFilters(Map<String, ?> offsets, Configuration config) Get the filters representing the tables that have been newly added to the config, but not those that previously existed in the config.private static FiltersgetOldFilters(Map<String, ?> offsets, Configuration config) Get the filters representing those tables that previously existed in the config, but not those newly added to the config.getRestartOffset(Map<String, ?> storedOffset) Get the offset to restart the connector from.protected booleanDetermine whether the binlog position as set on theSourceInfois available in the server.protected booleanDetermine whether the MySQL server has the row-level binlog enabled.protected booleanDetermine whether the MySQL server has the binlog_row_image set to 'FULL'.private booleanstart(Configuration config) version()Methods inherited from class io.debezium.connector.common.BaseSourceTask
commit, commitRecord, getPreviousOffsets, poll, start, stopMethods inherited from class org.apache.kafka.connect.source.SourceTask
commitRecord, initialize
-
Field Details
-
logger
private final org.slf4j.Logger logger -
taskContext
-
connectionContext
-
readers
-
-
Constructor Details
-
MySqlConnectorTask
public MySqlConnectorTask()Create an instance of the log reader that uses Kafka to store database schema history and theTopicSelector.defaultSelector(String, String, String, TopicSelector.DataCollectionTopicNamer)of "<serverName>.<databaseName>.<tableName>" for data and "<serverName>" for metadata.
-
-
Method Details
-
version
-
start
- Specified by:
startin classBaseSourceTask<MySqlPartition,MySqlOffsetContext>
-
getRestartOffset
Get the offset to restart the connector from. Normally, this is just the stored offset. However, if we were doing a parallel load with new tables, it's possible that the last committed offset is from reading the new tables, which could be beyond where we want to restart from (and restarting there could cause skipped events). To fix this, the new tables binlog reader records extra information in its offset to tell the connector where to restart from. If this extra information is present in the stored offset, that is the offset that is returned.- Parameters:
storedOffset- the stored offset.- Returns:
- the offset to restart from.
- See Also:
-
createAndStartTaskContext
-
newTablesInConfig
private boolean newTablesInConfig()- Returns:
- true if new tables appear to have been added to the config, and false otherwise.
-
getNewFilters
Get the filters representing the tables that have been newly added to the config, but not those that previously existed in the config.- Returns:
Filters
-
getOldFilters
Get the filters representing those tables that previously existed in the config, but not those newly added to the config.- Returns:
Filters
-
getAllFilters
Get the filters representing all tables represented by the config.- Returns:
Filters
-
doPoll
- Specified by:
doPollin classBaseSourceTask<MySqlPartition,MySqlOffsetContext> - Throws:
InterruptedException
-
doStop
protected void doStop()- Specified by:
doStopin classBaseSourceTask<MySqlPartition,MySqlOffsetContext>
-
getAllConfigurationFields
- Specified by:
getAllConfigurationFieldsin classBaseSourceTask<MySqlPartition,MySqlOffsetContext>
-
completeReaders
When the task isstopped, the readers may have additional work to perform before they actually stop and before all their records have been consumed via theBaseSourceTask.poll()method. This method signals that all of this has completed. -
isBinlogAvailable
protected boolean isBinlogAvailable()Determine whether the binlog position as set on theSourceInfois available in the server.- Returns:
trueif the server has the binlog coordinates, orfalseotherwise
-
earliestBinlogFilename
Determine the earliest binlog filename that is still available in the server.- Returns:
- the name of the earliest binlog filename, or null if there are none.
-
isBinlogRowImageFull
protected boolean isBinlogRowImageFull()Determine whether the MySQL server has the binlog_row_image set to 'FULL'.- Returns:
trueif the server'sbinlog_row_imageis set toFULL, orfalseotherwise
-
isBinlogFormatRow
protected boolean isBinlogFormatRow()Determine whether the MySQL server has the row-level binlog enabled.- Returns:
trueif the server'sbinlog_formatis set toROW, orfalseotherwise
-