Class MySqlConnectorTask

  • All Implemented Interfaces:
    org.apache.kafka.connect.connector.Task

    @NotThreadSafe
    public final class MySqlConnectorTask
    extends BaseSourceTask<MySqlOffsetContext>
    A Kafka Connect source task reads the MySQL binary log and generate the corresponding data change events.
    Author:
    Randall Hauch
    See Also:
    MySqlConnector
    • Constructor Detail

      • MySqlConnectorTask

        public MySqlConnectorTask()
        Create an instance of the log reader that uses Kafka to store database schema history and the default topic selector of "<serverName>.<databaseName>.<tableName>" for data and "<serverName>" for metadata.
    • Method Detail

      • version

        public String version()
      • getRestartOffset

        private Map<String,​?> getRestartOffset​(Map<String,​?> storedOffset)
        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:
        RecordMakers(MySqlSchema, SourceInfo, TopicSelector, boolean, Map)
      • newTablesInConfig

        private boolean newTablesInConfig()
        Returns:
        true if new tables appear to have been added to the config, and false otherwise.
      • getNewFilters

        private static Filters getNewFilters​(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.
        Returns:
        Filters
      • getOldFilters

        private static Filters getOldFilters​(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.
        Returns:
        Filters
      • getAllFilters

        private static Filters getAllFilters​(Configuration config)
        Get the filters representing all tables represented by the config.
        Returns:
        Filters
      • completeReaders

        protected void completeReaders()
        When the task is stopped, the readers may have additional work to perform before they actually stop and before all their records have been consumed via the BaseSourceTask.poll() method. This method signals that all of this has completed.
      • isBinlogAvailable

        protected boolean isBinlogAvailable()
        Determine whether the binlog position as set on the SourceInfo is available in the server.
        Returns:
        true if the server has the binlog coordinates, or false otherwise
      • earliestBinlogFilename

        protected String 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:
        true if the server's binlog_row_image is set to FULL, or false otherwise
      • isBinlogFormatRow

        protected boolean isBinlogFormatRow()
        Determine whether the MySQL server has the row-level binlog enabled.
        Returns:
        true if the server's binlog_format is set to ROW, or false otherwise