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 Configuration
config
private MySqlJdbcContext
connectionContext
private MySqlConnectorConfig
connectorConfig
private MySqlSchema
dbSchema
private Predicate<String>
ddlFilter
private Predicate<String>
gtidSourceFilter
private static org.slf4j.Logger
LOGGER
private RecordMakers
recordProcessor
private SourceInfo
source
private boolean
tableIdCaseInsensitive
Whether 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 int
bufferSizeForBinlogReader()
Configuration
config()
String
connectorName()
MySqlSchema
dbSchema()
Predicate<String>
ddlFilter()
Get the predicate function that will returntrue
if a DDL has to be skipped over and left out of the schema history orfalse
when it should be processed.GtidSet
filterGtidSet(GtidSet availableServerGtidSet, GtidSet purgedServerGtid)
Apply the include/exclude GTID source filters to the currentGTID set
and merge them onto the currently available GTID set from a MySQL server.MySqlJdbcContext
getConnectionContext()
MySqlConnectorConfig
getConnectorConfig()
Predicate<String>
gtidSourceFilter()
Get the predicate function that will returntrue
if a GTID source is to be included, orfalse
if a GTID source is to be excluded.boolean
historyExists()
Return true if the database history entity existsboolean
includeSchemaChangeRecords()
boolean
includeSqlQuery()
void
initializeHistory()
Initialize the database history with any server-specific information.void
initializeHistoryStorage()
Initialize permanent storage for database historyboolean
isInitialSnapshotOnly()
boolean
isSchemaOnlyRecoverySnapshot()
boolean
isSchemaOnlySnapshot()
boolean
isSnapshotAllowedWhenNeeded()
boolean
isSnapshotNeverAllowed()
boolean
isTableIdCaseInsensitive()
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.RecordMakers
makeRecord()
long
rowCountForLargeTable()
long
serverId()
void
shutdown()
protected MySqlConnectorConfig.SnapshotMode
snapshotMode()
SourceInfo
source()
void
start()
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.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 returntrue
if a GTID source is to be included, orfalse
if 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()
andoffset
at 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 set
and 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 returntrue
if a DDL has to be skipped over and left out of the schema history orfalse
when it should be processed.- Returns:
- the DDL predicate function; never null
-
isTableIdCaseInsensitive
public boolean isTableIdCaseInsensitive()
-
-