public class MySqlStreamingChangeEventSource extends Object implements StreamingChangeEventSource
| Modifier and Type | Class and Description |
|---|---|
private static interface |
MySqlStreamingChangeEventSource.BinlogChangeEmitter<T> |
static class |
MySqlStreamingChangeEventSource.BinlogPosition |
protected class |
MySqlStreamingChangeEventSource.ReaderThreadLifecycleListener |
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> |
ChangeEventSource.ChangeEventSourceContext| Constructor and Description |
|---|
MySqlStreamingChangeEventSource(MySqlConnectorConfig connectorConfig,
MySqlOffsetContext offsetContext,
MySqlConnection connection,
EventDispatcher<TableId> dispatcher,
ErrorHandler errorHandler,
Clock clock,
MySqlTaskContext taskContext,
MySqlStreamingChangeEventSourceMetrics metrics) |
| Modifier and Type | Method and Description |
|---|---|
void |
execute(ChangeEventSource.ChangeEventSourceContext context) |
GtidSet |
filterGtidSet(GtidSet availableServerGtidSet,
GtidSet purgedServerGtid)
Apply the include/exclude GTID source filters to the current
GTID set and merge them onto the
currently available GTID set from a MySQL server. |
private com.github.shyiko.mysql.binlog.network.SSLSocketFactory |
getBinlogSslSocketFactory(MySqlConnectorConfig connectorConfig,
MySqlConnection connection) |
(package private) MySqlStreamingChangeEventSource.BinlogPosition |
getCurrentBinlogPosition() |
(package private) MySqlStreamingChangeEventSourceMetrics |
getMetrics() |
private <T extends com.github.shyiko.mysql.binlog.event.EventData,U> |
handleChange(com.github.shyiko.mysql.binlog.event.Event event,
String changeType,
Class<T> eventDataClass,
MySqlStreamingChangeEventSource.TableIdProvider<T> tableIdProvider,
MySqlStreamingChangeEventSource.RowsProvider<T,U> rowsProvider,
MySqlStreamingChangeEventSource.BinlogChangeEmitter<U> changeEmitter) |
protected void |
handleDelete(com.github.shyiko.mysql.binlog.event.Event event)
Generate source records for the supplied event with an
DeleteRowsEventData. |
protected void |
handleEvent(com.github.shyiko.mysql.binlog.event.Event event) |
protected void |
handleGtidEvent(com.github.shyiko.mysql.binlog.event.Event event)
Handle the supplied event with a
GtidEventData that signals the beginning of a GTID transaction. |
protected void |
handleInsert(com.github.shyiko.mysql.binlog.event.Event event)
Generate source records for the supplied event with an
WriteRowsEventData. |
protected void |
handleQueryEvent(com.github.shyiko.mysql.binlog.event.Event event)
Handle the supplied event with an
QueryEventData by possibly recording the DDL statements as changes in the
MySQL schemas. |
protected void |
handleRotateLogsEvent(com.github.shyiko.mysql.binlog.event.Event event)
Handle the supplied event with a
RotateEventData that signals the logs are being rotated. |
protected void |
handleRowsQuery(com.github.shyiko.mysql.binlog.event.Event event)
Handle the supplied event with an
RowsQueryEventData by recording the original SQL query
that generated the event. |
protected void |
handleServerHeartbeat(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(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(com.github.shyiko.mysql.binlog.event.Event event)
Handle the supplied event that signals that mysqld has stopped.
|
private void |
handleTransactionCompletion(com.github.shyiko.mysql.binlog.event.Event event) |
protected void |
handleUpdate(com.github.shyiko.mysql.binlog.event.Event event)
Generate source records for the supplied event with an
UpdateRowsEventData. |
protected void |
handleUpdateTableMetadata(com.github.shyiko.mysql.binlog.event.Event event)
Handle a change in the table metadata.
|
protected void |
ignoreEvent(com.github.shyiko.mysql.binlog.event.Event event) |
private void |
informAboutUnknownTableIfRequired(com.github.shyiko.mysql.binlog.event.Event event,
TableId tableId,
String typeToLog)
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 the
MySqlConnectorConfig.INCONSISTENT_SCHEMA_HANDLING_MODE configuration. |
protected void |
logEvent(com.github.shyiko.mysql.binlog.event.Event event) |
private void |
logStreamingSourceState() |
private void |
logStreamingSourceState(org.slf4j.event.Level severity) |
protected void |
onEvent(com.github.shyiko.mysql.binlog.event.Event event) |
protected void |
prepareTransaction(com.github.shyiko.mysql.binlog.event.Event event)
Handle a
EventType.XA_PREPARE event. |
(package private) void |
rewindBinaryLogClient(ChangeEventSource.ChangeEventSourceContext context,
MySqlStreamingChangeEventSource.BinlogPosition position) |
private com.github.shyiko.mysql.binlog.network.SSLMode |
sslModeFor(MySqlConnectorConfig.SecureConnectionMode mode) |
protected <T extends com.github.shyiko.mysql.binlog.event.EventData> |
unwrapData(com.github.shyiko.mysql.binlog.event.Event event) |
protected void |
viewChange(com.github.shyiko.mysql.binlog.event.Event event)
Handle a
EventType.VIEW_CHANGE event. |
protected io.debezium.DebeziumException |
wrap(Throwable error)
Wraps the specified exception in a
DebeziumException, ensuring that all useful state is captured inside
the new exception's message. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcommitOffsetprivate static final org.slf4j.Logger LOGGER
private static final String KEEPALIVE_THREAD_NAME
private final EnumMap<com.github.shyiko.mysql.binlog.event.EventType,BlockingConsumer<com.github.shyiko.mysql.binlog.event.Event>> eventHandlers
private final com.github.shyiko.mysql.binlog.BinaryLogClient client
private final MySqlStreamingChangeEventSourceMetrics metrics
private final Clock clock
private final CommonConnectorConfig.EventProcessingFailureHandlingMode eventDeserializationFailureHandlingMode
private final CommonConnectorConfig.EventProcessingFailureHandlingMode inconsistentSchemaHandlingMode
private int startingRowNumber
private long initialEventsToSkip
private boolean skipEvent
private boolean ignoreDmlEventByGtidSource
private final AtomicLong totalRecordCounter
private com.github.shyiko.mysql.binlog.GtidSet gtidSet
private final float heartbeatIntervalFactor
private final MySqlTaskContext taskContext
private final MySqlConnectorConfig connectorConfig
private final MySqlConnection connection
private final EventDispatcher<TableId> eventDispatcher
private final MySqlOffsetContext offsetContext
private final ErrorHandler errorHandler
private Instant eventTimestamp
public MySqlStreamingChangeEventSource(MySqlConnectorConfig connectorConfig, MySqlOffsetContext offsetContext, MySqlConnection connection, EventDispatcher<TableId> dispatcher, ErrorHandler errorHandler, Clock clock, MySqlTaskContext taskContext, MySqlStreamingChangeEventSourceMetrics metrics)
protected void onEvent(com.github.shyiko.mysql.binlog.event.Event event)
protected void ignoreEvent(com.github.shyiko.mysql.binlog.event.Event event)
protected void handleEvent(com.github.shyiko.mysql.binlog.event.Event event)
protected <T extends com.github.shyiko.mysql.binlog.event.EventData> T unwrapData(com.github.shyiko.mysql.binlog.event.Event event)
protected void handleServerStop(com.github.shyiko.mysql.binlog.event.Event event)
event - the server stopped event to be processed; may not be nullprotected void handleServerHeartbeat(com.github.shyiko.mysql.binlog.event.Event event)
event - the server stopped event to be processed; may not be nullprotected void handleServerIncident(com.github.shyiko.mysql.binlog.event.Event event)
event - the server stopped event to be processed; may not be nullprotected void handleRotateLogsEvent(com.github.shyiko.mysql.binlog.event.Event event)
RotateEventData 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.event - the database change data event to be processed; may not be nullprotected void handleGtidEvent(com.github.shyiko.mysql.binlog.event.Event event)
GtidEventData 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.
event - the GTID event to be processed; may not be nullprotected void handleRowsQuery(com.github.shyiko.mysql.binlog.event.Event event)
RowsQueryEventData by recording the original SQL query
that generated the event.event - the database change data event to be processed; may not be nullprotected void handleQueryEvent(com.github.shyiko.mysql.binlog.event.Event event)
throws InterruptedException
QueryEventData by possibly recording the DDL statements as changes in the
MySQL schemas.event - the database change data event to be processed; may not be nullInterruptedException - if this thread is interrupted while recording the DDL statementsprivate void handleTransactionCompletion(com.github.shyiko.mysql.binlog.event.Event event)
throws InterruptedException
InterruptedExceptionprotected void handleUpdateTableMetadata(com.github.shyiko.mysql.binlog.event.Event event)
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:
ALTER TABLE ... command); orevent - the update event; never nullprivate void informAboutUnknownTableIfRequired(com.github.shyiko.mysql.binlog.event.Event event,
TableId tableId,
String typeToLog)
MySqlConnectorConfig.INCONSISTENT_SCHEMA_HANDLING_MODE configuration.protected void handleInsert(com.github.shyiko.mysql.binlog.event.Event event)
throws InterruptedException
WriteRowsEventData.event - the database change data event to be processed; may not be nullInterruptedException - if this thread is interrupted while blockingprotected void handleUpdate(com.github.shyiko.mysql.binlog.event.Event event)
throws InterruptedException
UpdateRowsEventData.event - the database change data event to be processed; may not be nullInterruptedException - if this thread is interrupted while blockingprotected void handleDelete(com.github.shyiko.mysql.binlog.event.Event event)
throws InterruptedException
DeleteRowsEventData.event - the database change data event to be processed; may not be nullInterruptedException - if this thread is interrupted while blockingprivate <T extends com.github.shyiko.mysql.binlog.event.EventData,U> void handleChange(com.github.shyiko.mysql.binlog.event.Event event,
String changeType,
Class<T> eventDataClass,
MySqlStreamingChangeEventSource.TableIdProvider<T> tableIdProvider,
MySqlStreamingChangeEventSource.RowsProvider<T,U> rowsProvider,
MySqlStreamingChangeEventSource.BinlogChangeEmitter<U> changeEmitter)
throws InterruptedException
InterruptedExceptionprotected void viewChange(com.github.shyiko.mysql.binlog.event.Event event)
throws InterruptedException
EventType.VIEW_CHANGE event.event - the database change data event to be processed; may not be nullInterruptedException - if this thread is interrupted while blockingprotected void prepareTransaction(com.github.shyiko.mysql.binlog.event.Event event)
throws InterruptedException
EventType.XA_PREPARE event.event - the database change data event to be processed; may not be nullInterruptedException - if this thread is interrupted while blockingprivate com.github.shyiko.mysql.binlog.network.SSLMode sslModeFor(MySqlConnectorConfig.SecureConnectionMode mode)
public void execute(ChangeEventSource.ChangeEventSourceContext context) throws InterruptedException
execute in interface StreamingChangeEventSourceInterruptedExceptionprivate com.github.shyiko.mysql.binlog.network.SSLSocketFactory getBinlogSslSocketFactory(MySqlConnectorConfig connectorConfig, MySqlConnection connection)
private void logStreamingSourceState()
protected void logEvent(com.github.shyiko.mysql.binlog.event.Event event)
private void logStreamingSourceState(org.slf4j.event.Level severity)
public GtidSet filterGtidSet(GtidSet availableServerGtidSet, GtidSet purgedServerGtid)
GTID 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.availableServerGtidSet - the GTID set currently available in the MySQL serverpurgedServerGtid - the GTID set already purged by the MySQL serverMySqlStreamingChangeEventSourceMetrics getMetrics()
void rewindBinaryLogClient(ChangeEventSource.ChangeEventSourceContext context, MySqlStreamingChangeEventSource.BinlogPosition position)
MySqlStreamingChangeEventSource.BinlogPosition getCurrentBinlogPosition()
protected io.debezium.DebeziumException wrap(Throwable error)
DebeziumException, ensuring that all useful state is captured inside
the new exception's message.error - the exception; may not be nullCopyright © 2021 JBoss by Red Hat. All rights reserved.