Class MySqlTaskContext
- java.lang.Object
-
- io.debezium.connector.common.CdcSourceTaskContext
-
- io.debezium.connector.mysql.legacy.MySqlTaskContext
-
public final class MySqlTaskContext extends CdcSourceTaskContext
A Kafka Connect source task reads the MySQL binary log and generate the corresponding data change events.- Author:
- Randall Hauch
- See Also:
MySqlConnector
-
-
Field Summary
Fields Modifier and Type Field Description private Configurationconfigprivate MySqlJdbcContextconnectionContextprivate MySqlConnectorConfigconnectorConfigprivate MySqlSchemadbSchemaprivate Predicate<String>ddlFilterprivate Predicate<String>gtidSourceFilterprivate static org.slf4j.LoggerLOGGERprivate RecordMakersrecordProcessorprivate SourceInfosourceprivate booleantableIdCaseInsensitiveWhether table ids are compared ignoring letter casing.private TopicSelector<TableId>topicSelector
-
Constructor Summary
Constructors Constructor Description MySqlTaskContext(Configuration config, Filters filters)MySqlTaskContext(Configuration config, Filters filters, Boolean tableIdCaseInsensitive, Map<String,?> restartOffset)MySqlTaskContext(Configuration config, Filters filters, Map<String,?> restartOffset)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intbufferSizeForBinlogReader()Configurationconfig()StringconnectorName()MySqlSchemadbSchema()Predicate<String>ddlFilter()Get the predicate function that will returntrueif a DDL has to be skipped over and left out of the schema history orfalsewhen it should be processed.GtidSetfilterGtidSet(GtidSet availableServerGtidSet, GtidSet purgedServerGtid)Apply the include/exclude GTID source filters to the currentGTID setand merge them onto the currently available GTID set from a MySQL server.MySqlJdbcContextgetConnectionContext()MySqlConnectorConfiggetConnectorConfig()Predicate<String>gtidSourceFilter()Get the predicate function that will returntrueif a GTID source is to be included, orfalseif a GTID source is to be excluded.booleanhistoryExists()Return true if the database history entity existsbooleanincludeSchemaChangeRecords()booleanincludeSqlQuery()voidinitializeHistory()Initialize the database history with any server-specific information.voidinitializeHistoryStorage()Initialize permanent storage for database historybooleanisInitialSnapshotOnly()booleanisSchemaOnlyRecoverySnapshot()booleanisSchemaOnlySnapshot()booleanisSnapshotAllowedWhenNeeded()booleanisSnapshotNeverAllowed()booleanisTableIdCaseInsensitive()voidloadHistory(SourceInfo startingPoint)Load the database schema information using the previously-recorded history, and stop reading the history when the the history reaches the supplied starting point.RecordMakersmakeRecord()longrowCountForLargeTable()longserverId()voidshutdown()protected MySqlConnectorConfig.SnapshotModesnapshotMode()SourceInfosource()voidstart()voidtemporaryLoggingContext(String contextName, Runnable operation)Run the supplied function in the temporary connector MDC context, and when complete always return the MDC context to its state before this method was called.TopicSelector<TableId>topicSelector()-
Methods inherited from class io.debezium.connector.common.CdcSourceTaskContext
capturedDataCollections, configureLoggingContext, getClock, getConnectorName, getConnectorType, temporaryLoggingContext
-
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
connectionContext
private final MySqlJdbcContext connectionContext
-
config
private final Configuration config
-
connectorConfig
private final MySqlConnectorConfig connectorConfig
-
source
private final SourceInfo source
-
dbSchema
private final MySqlSchema dbSchema
-
topicSelector
private final TopicSelector<TableId> topicSelector
-
recordProcessor
private final RecordMakers recordProcessor
-
tableIdCaseInsensitive
private final boolean tableIdCaseInsensitive
Whether table ids are compared ignoring letter casing.
-
-
Constructor Detail
-
MySqlTaskContext
public MySqlTaskContext(Configuration config, Filters filters)
-
MySqlTaskContext
public MySqlTaskContext(Configuration config, Filters filters, Map<String,?> restartOffset)
-
MySqlTaskContext
public MySqlTaskContext(Configuration config, Filters filters, Boolean tableIdCaseInsensitive, Map<String,?> restartOffset)
-
-
Method Detail
-
config
public Configuration config()
-
getConnectorConfig
public MySqlConnectorConfig getConnectorConfig()
-
getConnectionContext
public MySqlJdbcContext getConnectionContext()
-
connectorName
public String connectorName()
-
topicSelector
public TopicSelector<TableId> topicSelector()
-
source
public SourceInfo source()
-
dbSchema
public MySqlSchema dbSchema()
-
makeRecord
public RecordMakers makeRecord()
-
gtidSourceFilter
public Predicate<String> gtidSourceFilter()
Get the predicate function that will returntrueif a GTID source is to be included, orfalseif a GTID source is to be excluded.- Returns:
- the GTID source predicate function; never null
-
initializeHistory
public void initializeHistory()
Initialize the database history with any server-specific information. This should be done only upon connector startup when the connector has no prior history.
-
loadHistory
public void loadHistory(SourceInfo startingPoint)
Load the database schema information using the previously-recorded history, and stop reading the history when the the history reaches the supplied starting point.- Parameters:
startingPoint- the source information with the currentSourceInfo.partition()andoffsetat which the database schemas are to reflect; may not be null
-
historyExists
public boolean historyExists()
Return true if the database history entity exists
-
initializeHistoryStorage
public void initializeHistoryStorage()
Initialize permanent storage for database history
-
serverId
public long serverId()
-
rowCountForLargeTable
public long rowCountForLargeTable()
-
bufferSizeForBinlogReader
public int bufferSizeForBinlogReader()
-
includeSchemaChangeRecords
public boolean includeSchemaChangeRecords()
-
includeSqlQuery
public boolean includeSqlQuery()
-
isSnapshotAllowedWhenNeeded
public boolean isSnapshotAllowedWhenNeeded()
-
isSnapshotNeverAllowed
public boolean isSnapshotNeverAllowed()
-
isInitialSnapshotOnly
public boolean isInitialSnapshotOnly()
-
isSchemaOnlySnapshot
public boolean isSchemaOnlySnapshot()
-
isSchemaOnlyRecoverySnapshot
public boolean isSchemaOnlyRecoverySnapshot()
-
snapshotMode
protected MySqlConnectorConfig.SnapshotMode snapshotMode()
-
start
public void start()
-
shutdown
public void shutdown()
-
temporaryLoggingContext
public void temporaryLoggingContext(String contextName, Runnable operation)
Run the supplied function in the temporary connector MDC context, and when complete always return the MDC context to its state before this method was called.- Parameters:
contextName- the name of the context; may not be nulloperation- the function to run in the new MDC context; may not be null- Throws:
IllegalArgumentException- if any of the parameters are null
-
filterGtidSet
public GtidSet filterGtidSet(GtidSet availableServerGtidSet, GtidSet purgedServerGtid)
Apply the include/exclude GTID source filters to the currentGTID setand merge them onto the currently available GTID set from a MySQL server. The merging behavior of this method might seem a bit strange at first. It's required in order for Debezium to consume a MySQL binlog that has multi-source replication enabled, if a failover has to occur. In such a case, the server that Debezium is failed over to might have a different set of sources, but still include the sources required for Debezium to continue to function. MySQL does not allow downstream replicas to connect if the GTID set does not contain GTIDs for all channels that the server is replicating from, even if the server does have the data needed by the client. To get around this, we can have Debezium merge its GTID set with whatever is on the server, so that MySQL will allow it to connect. See DBZ-143 for details. This method does not mutate any state in the context.- Parameters:
availableServerGtidSet- the GTID set currently available in the MySQL serverpurgedServerGtid- the GTID set already purged by the MySQL server- Returns:
- A GTID set meant for consuming from a MySQL binlog; may return null if the SourceInfo has no GTIDs and therefore none were filtered
-
ddlFilter
public Predicate<String> ddlFilter()
Get the predicate function that will returntrueif a DDL has to be skipped over and left out of the schema history orfalsewhen it should be processed.- Returns:
- the DDL predicate function; never null
-
isTableIdCaseInsensitive
public boolean isTableIdCaseInsensitive()
-
-