Class MySqlStreamingChangeEventSource
- All Implemented Interfaces:
ChangeEventSource
,StreamingChangeEventSource<MySqlPartition,
MySqlOffsetContext>
- Author:
- Jiri Pechanec
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate static interface
static class
private static interface
protected final class
private static interface
MySqlStreamingChangeEventSource.RowsProvider<E extends com.github.shyiko.mysql.binlog.event.EventData,
U> private static interface
MySqlStreamingChangeEventSource.TableIdProvider<E extends com.github.shyiko.mysql.binlog.event.EventData>
Nested classes/interfaces inherited from interface io.debezium.pipeline.source.spi.ChangeEventSource
ChangeEventSource.ChangeEventSourceContext
-
Field Summary
Modifier and TypeFieldDescriptionprivate final com.github.shyiko.mysql.binlog.BinaryLogClient
private final Clock
private final AbstractConnectorConnection
private final ConnectorAdapter
private final MySqlConnectorConfig
private MySqlOffsetContext
private final ErrorHandler
private final CommonConnectorConfig.EventProcessingFailureHandlingMode
private final EventDispatcher<MySqlPartition,
TableId> private final EnumMap<com.github.shyiko.mysql.binlog.event.EventType,
BlockingConsumer<com.github.shyiko.mysql.binlog.event.Event>> private Instant
private com.github.shyiko.mysql.binlog.GtidSet
private boolean
private final CommonConnectorConfig.EventProcessingFailureHandlingMode
private long
private final boolean
private static final String
private static final org.slf4j.Logger
private com.github.shyiko.mysql.binlog.MariadbGtidSet
private final MySqlStreamingChangeEventSourceMetrics
private boolean
private int
private final MySqlTaskContext
private final AtomicLong
-
Constructor Summary
ConstructorDescriptionMySqlStreamingChangeEventSource
(MySqlConnectorConfig connectorConfig, AbstractConnectorConnection connection, EventDispatcher<MySqlPartition, TableId> dispatcher, ErrorHandler errorHandler, Clock clock, MySqlTaskContext taskContext, MySqlStreamingChangeEventSourceMetrics metrics) -
Method Summary
Modifier and TypeMethodDescriptionvoid
execute
(ChangeEventSource.ChangeEventSourceContext context, MySqlPartition partition, MySqlOffsetContext offsetContext) (package private) MySqlStreamingChangeEventSource.BinlogPosition
private Instant
getEventTimestamp
(com.github.shyiko.mysql.binlog.event.Event event, long eventTs) (package private) MySqlStreamingChangeEventSourceMetrics
private <T extends com.github.shyiko.mysql.binlog.event.EventData,
U>
voidhandleChange
(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event, Envelope.Operation operation, Class<T> eventDataClass, MySqlStreamingChangeEventSource.TableIdProvider<T> tableIdProvider, MySqlStreamingChangeEventSource.RowsProvider<T, U> rowsProvider, MySqlStreamingChangeEventSource.BinlogChangeEmitter<U> changeEmitter, MySqlStreamingChangeEventSource.ChangeEventValidator<U> changeEventValidator) protected void
handleDelete
(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Generate source records for the supplied event with anDeleteRowsEventData
.protected void
handleEvent
(MySqlPartition partition, MySqlOffsetContext offsetContext, ChangeEventSource.ChangeEventSourceContext context, com.github.shyiko.mysql.binlog.event.Event event) protected void
handleGtidEvent
(MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle the supplied event with aGtidEventData
that signals the beginning of a GTID transaction.protected void
handleInsert
(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Generate source records for the supplied event with anWriteRowsEventData
.protected void
handleMariaDbGtidEvent
(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) protected void
handleQueryEvent
(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle the supplied event with anQueryEventData
by possibly recording the DDL statements as changes in the MySQL schemas.protected void
handleRecordingQuery
(MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle the supplied event with anRowsQueryEventData
orAnnotateRowsEventData
by recording the original SQL query that generated the event.protected void
handleRotateLogsEvent
(MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle the supplied event with aRotateEventData
that signals the logs are being rotated.protected void
handleServerHeartbeat
(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle the supplied event that is sent by a primary to a replica to let the replica know that the primary is still alive.protected void
handleServerIncident
(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle the supplied event that signals that an out of the ordinary event that occurred on the master.protected void
handleServerStop
(MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle the supplied event that signals that mysqld has stopped.private void
handleTransactionBegin
(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event, Long threadId) private void
handleTransactionCompletion
(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) protected void
handleTransactionPayload
(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle an event of type TRANSACTION_PAYLOAD_EVENTprotected void
handleUpdate
(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Generate source records for the supplied event with anUpdateRowsEventData
.protected void
handleUpdateTableMetadata
(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle a change in the table metadata.protected void
ignoreEvent
(MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) private void
informAboutUnknownTableIfRequired
(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event, TableId tableId) private void
informAboutUnknownTableIfRequired
(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event, TableId tableId, Envelope.Operation operation) If we receive an event for a table that is monitored but whose metadata we don't know, either ignore that event or raise a warning or error as per theMySqlConnectorConfig.INCONSISTENT_SCHEMA_HANDLING_MODE
configuration.void
init
(MySqlOffsetContext offsetContext) protected void
logEvent
(MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) private void
private void
logStreamingSourceState
(org.slf4j.event.Level severity) protected void
onEvent
(MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) protected void
prepareTransaction
(MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle aEventType.XA_PREPARE
event.(package private) void
rewindBinaryLogClient
(ChangeEventSource.ChangeEventSourceContext context, MySqlStreamingChangeEventSource.BinlogPosition position) protected <T extends com.github.shyiko.mysql.binlog.event.EventData>
TunwrapData
(com.github.shyiko.mysql.binlog.event.Event event) private void
validateChangeEventWithTable
(Table table, Object[] before, Object[] after) protected void
viewChange
(MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle aEventType.VIEW_CHANGE
event.private void
protected io.debezium.DebeziumException
Wraps the specified exception in aDebeziumException
, ensuring that all useful state is captured inside the new exception's message.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.debezium.pipeline.source.spi.StreamingChangeEventSource
commitOffset, executeIteration
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
KEEPALIVE_THREAD_NAME
- See Also:
-
eventHandlers
private final EnumMap<com.github.shyiko.mysql.binlog.event.EventType,BlockingConsumer<com.github.shyiko.mysql.binlog.event.Event>> eventHandlers -
client
private final com.github.shyiko.mysql.binlog.BinaryLogClient client -
metrics
-
clock
-
eventDeserializationFailureHandlingMode
private final CommonConnectorConfig.EventProcessingFailureHandlingMode eventDeserializationFailureHandlingMode -
inconsistentSchemaHandlingMode
private final CommonConnectorConfig.EventProcessingFailureHandlingMode inconsistentSchemaHandlingMode -
startingRowNumber
private int startingRowNumber -
initialEventsToSkip
private long initialEventsToSkip -
skipEvent
private boolean skipEvent -
ignoreDmlEventByGtidSource
private boolean ignoreDmlEventByGtidSource -
isGtidModeEnabled
private final boolean isGtidModeEnabled -
gtidDmlSourceFilter
-
totalRecordCounter
-
lastOffset
-
gtidSet
private com.github.shyiko.mysql.binlog.GtidSet gtidSet -
mariaGtidSet
private com.github.shyiko.mysql.binlog.MariadbGtidSet mariaGtidSet -
binaryLogClientThreads
-
taskContext
-
connectorConfig
-
connection
-
eventDispatcher
-
errorHandler
-
connectorAdapter
-
eventTimestamp
-
effectiveOffsetContext
-
-
Constructor Details
-
MySqlStreamingChangeEventSource
public MySqlStreamingChangeEventSource(MySqlConnectorConfig connectorConfig, AbstractConnectorConnection connection, EventDispatcher<MySqlPartition, TableId> dispatcher, ErrorHandler errorHandler, Clock clock, MySqlTaskContext taskContext, MySqlStreamingChangeEventSourceMetrics metrics)
-
-
Method Details
-
onEvent
protected void onEvent(MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) -
getEventTimestamp
-
ignoreEvent
protected void ignoreEvent(MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) -
handleEvent
protected void handleEvent(MySqlPartition partition, MySqlOffsetContext offsetContext, ChangeEventSource.ChangeEventSourceContext context, com.github.shyiko.mysql.binlog.event.Event event) -
unwrapData
protected <T extends com.github.shyiko.mysql.binlog.event.EventData> T unwrapData(com.github.shyiko.mysql.binlog.event.Event event) -
handleServerStop
protected void handleServerStop(MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle the supplied event that signals that mysqld has stopped.- Parameters:
event
- the server stopped event to be processed; may not be null
-
handleServerHeartbeat
protected void handleServerHeartbeat(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) throws InterruptedException Handle the supplied event that is sent by a primary to a replica to let the replica know that the primary is still alive. Not written to a binary log.- Parameters:
event
- the server stopped event to be processed; may not be null- Throws:
InterruptedException
-
handleServerIncident
protected void handleServerIncident(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle the supplied event that signals that an out of the ordinary event that occurred on the master. It notifies the replica that something happened on the primary that might cause data to be in an inconsistent state.- Parameters:
event
- the server stopped event to be processed; may not be null
-
handleRotateLogsEvent
protected void handleRotateLogsEvent(MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle the supplied event with aRotateEventData
that signals the logs are being rotated. This means that either the server was restarted, or the binlog has transitioned to a new file. In either case, subsequent table numbers will be different than those seen to this point.- Parameters:
event
- the database change data event to be processed; may not be null
-
handleGtidEvent
protected void handleGtidEvent(MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle the supplied event with aGtidEventData
that signals the beginning of a GTID transaction. We don't yet know whether this transaction contains any events we're interested in, but we have to record it so that we know the position of this event and know we've processed the binlog to this point.Note that this captures the current GTID and complete GTID set, regardless of whether the connector is
filtering
the GTID set upon connection. We do this because we actually want to capture all GTID set values found in the binlog, whether or not we process them. However, only when we connect do we actually want to pass to MySQL only those GTID ranges that are applicable per the configuration.- Parameters:
event
- the GTID event to be processed; may not be null
-
handleMariaDbGtidEvent
protected void handleMariaDbGtidEvent(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) throws InterruptedException - Throws:
InterruptedException
-
handleRecordingQuery
protected void handleRecordingQuery(MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle the supplied event with anRowsQueryEventData
orAnnotateRowsEventData
by recording the original SQL query that generated the event.- Parameters:
event
- the database change data event to be processed; may not be null
-
handleQueryEvent
protected void handleQueryEvent(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) throws InterruptedException Handle the supplied event with anQueryEventData
by possibly recording the DDL statements as changes in the MySQL schemas.- Parameters:
partition
- the partition in which the even occurredevent
- the database change data event to be processed; may not be null- Throws:
InterruptedException
- if this thread is interrupted while recording the DDL statements
-
handleTransactionBegin
private void handleTransactionBegin(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event, Long threadId) throws InterruptedException - Throws:
InterruptedException
-
handleTransactionCompletion
private void handleTransactionCompletion(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) throws InterruptedException - Throws:
InterruptedException
-
handleUpdateTableMetadata
protected void handleUpdateTableMetadata(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) throws InterruptedException Handle a change in the table metadata.This method should be called whenever we consume a TABLE_MAP event, and every transaction in the log should include one of these for each table affected by the transaction. Each table map event includes a monotonically-increasing numeric identifier, and this identifier is used within subsequent events within the same transaction. This table identifier can change when:
- the table structure is modified (e.g., via an
ALTER TABLE ...
command); or - MySQL rotates to a new binary log file, even if the table structure does not change.
- Parameters:
event
- the update event; never null- Throws:
InterruptedException
- the table structure is modified (e.g., via an
-
handleTransactionPayload
protected void handleTransactionPayload(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) throws InterruptedException Handle an event of type TRANSACTION_PAYLOAD_EVENTThis method should be called whenever a transaction payload event is encountered by the mysql binlog connector. A Transaction payload event is propagated from the binlog connector when compression is turned on over binlog. This method loops over the individual events in the compressed binlog and calls the respective atomic event handlers.
- Throws:
InterruptedException
-
informAboutUnknownTableIfRequired
private void informAboutUnknownTableIfRequired(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event, TableId tableId, Envelope.Operation operation) throws InterruptedException If we receive an event for a table that is monitored but whose metadata we don't know, either ignore that event or raise a warning or error as per theMySqlConnectorConfig.INCONSISTENT_SCHEMA_HANDLING_MODE
configuration.- Throws:
InterruptedException
-
informAboutUnknownTableIfRequired
private void informAboutUnknownTableIfRequired(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event, TableId tableId) throws InterruptedException - Throws:
InterruptedException
-
validateChangeEventWithTable
-
handleInsert
protected void handleInsert(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) throws InterruptedException Generate source records for the supplied event with anWriteRowsEventData
.- Parameters:
partition
- the partition in which the even occurredevent
- the database change data event to be processed; may not be null- Throws:
InterruptedException
- if this thread is interrupted while blocking
-
handleUpdate
protected void handleUpdate(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) throws InterruptedException Generate source records for the supplied event with anUpdateRowsEventData
.- Parameters:
partition
- the partition in which the even occurredevent
- the database change data event to be processed; may not be null- Throws:
InterruptedException
- if this thread is interrupted while blocking
-
handleDelete
protected void handleDelete(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) throws InterruptedException Generate source records for the supplied event with anDeleteRowsEventData
.- Parameters:
partition
- the partition in which the even occurredevent
- the database change data event to be processed; may not be null- Throws:
InterruptedException
- if this thread is interrupted while blocking
-
handleChange
private <T extends com.github.shyiko.mysql.binlog.event.EventData,U> void handleChange(MySqlPartition partition, MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event, Envelope.Operation operation, Class<T> eventDataClass, MySqlStreamingChangeEventSource.TableIdProvider<T> tableIdProvider, MySqlStreamingChangeEventSource.RowsProvider<T, U> rowsProvider, MySqlStreamingChangeEventSource.BinlogChangeEmitter<U> changeEmitter, MySqlStreamingChangeEventSource.ChangeEventValidator<U> changeEventValidator) throws InterruptedException- Throws:
InterruptedException
-
viewChange
protected void viewChange(MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) throws InterruptedException Handle aEventType.VIEW_CHANGE
event.- Parameters:
event
- the database change data event to be processed; may not be null- Throws:
InterruptedException
- if this thread is interrupted while blocking
-
prepareTransaction
protected void prepareTransaction(MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) throws InterruptedException Handle aEventType.XA_PREPARE
event.- Parameters:
event
- the database change data event to be processed; may not be null- Throws:
InterruptedException
- if this thread is interrupted while blocking
-
init
- Specified by:
init
in interfaceStreamingChangeEventSource<MySqlPartition,
MySqlOffsetContext>
-
execute
public void execute(ChangeEventSource.ChangeEventSourceContext context, MySqlPartition partition, MySqlOffsetContext offsetContext) throws InterruptedException - Specified by:
execute
in interfaceStreamingChangeEventSource<MySqlPartition,
MySqlOffsetContext> - Throws:
InterruptedException
-
waitWhenStreamingPaused
private void waitWhenStreamingPaused(ChangeEventSource.ChangeEventSourceContext context) throws InterruptedException - Throws:
InterruptedException
-
getOffsetContext
- Specified by:
getOffsetContext
in interfaceStreamingChangeEventSource<MySqlPartition,
MySqlOffsetContext>
-
logStreamingSourceState
private void logStreamingSourceState() -
logEvent
protected void logEvent(MySqlOffsetContext offsetContext, com.github.shyiko.mysql.binlog.event.Event event) -
logStreamingSourceState
private void logStreamingSourceState(org.slf4j.event.Level severity) -
getMetrics
MySqlStreamingChangeEventSourceMetrics getMetrics() -
rewindBinaryLogClient
void rewindBinaryLogClient(ChangeEventSource.ChangeEventSourceContext context, MySqlStreamingChangeEventSource.BinlogPosition position) -
getCurrentBinlogPosition
MySqlStreamingChangeEventSource.BinlogPosition getCurrentBinlogPosition() -
wrap
Wraps the specified exception in aDebeziumException
, ensuring that all useful state is captured inside the new exception's message.- Parameters:
error
- the exception; may not be null- Returns:
- the wrapped Kafka Connect exception
-