public class BinlogReader extends AbstractReader
MySqlSchema
.Modifier and Type | Class and Description |
---|---|
static class |
BinlogReader.BinlogPosition |
protected class |
BinlogReader.ReaderThreadLifecycleListener |
AbstractReader.AcceptAllPredicate
Reader.State
changeEventQueueMetrics, context, logger
Constructor and Description |
---|
BinlogReader(String name,
MySqlTaskContext context,
HaltingPredicate acceptAndContinue)
Create a binlog reader.
|
BinlogReader(String name,
MySqlTaskContext context,
HaltingPredicate acceptAndContinue,
long serverId)
Create a binlog reader.
|
Modifier and Type | Method and Description |
---|---|
protected void |
doCleanup()
The reader has completed all processing and all
enqueued records have been
consumed , so this reader should clean up any resources that might remain. |
void |
doDestroy()
The reader has been requested to de-initialize resources after stopping.
|
protected void |
doInitialize()
The reader has been requested to initialize resources prior to starting.
|
protected void |
doStart()
The reader has been requested to start, so initialize any un-initialized resources required
by the reader.
|
protected void |
doStop()
The reader has been requested to stop, so perform any work required to stop the reader's resources that were previously
started . |
protected com.github.shyiko.mysql.binlog.BinaryLogClient |
getBinlogClient() |
private com.github.shyiko.mysql.binlog.network.SSLSocketFactory |
getBinlogSslSocketFactory(MySqlJdbcContext connectionContext) |
BinlogReader.BinlogPosition |
getCurrentBinlogPosition() |
Map<String,?> |
getLastOffset() |
protected BinlogReaderMetrics |
getMetrics() |
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 master to a slave to let the slave know that the master 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 |
logReaderState() |
private void |
logReaderState(org.slf4j.event.Level severity) |
protected void |
onEvent(com.github.shyiko.mysql.binlog.event.Event event) |
protected void |
pollComplete(List<org.apache.kafka.connect.source.SourceRecord> batch)
Method called when
AbstractReader.poll() completes sending a non-zero-sized batch of records. |
protected void |
prepareTransaction(com.github.shyiko.mysql.binlog.event.Event event)
Handle a
EventType.XA_PREPARE event. |
protected void |
rewindBinaryLogClient(BinlogReader.BinlogPosition position) |
protected static 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. |
cleanupResources, completeSuccessfully, destroy, enqueueRecord, failed, failed, initialize, isRunning, name, poll, start, state, stop, toString, uponCompletion, wrap
private static final long INITIAL_POLL_PERIOD_IN_MILLIS
private static final long MAX_POLL_PERIOD_IN_MILLIS
private static final String KEEPALIVE_THREAD_NAME
private final boolean recordSchemaChangesInSourceRecords
private final RecordMakers recordMakers
private final SourceInfo source
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 BinlogReaderMetrics metrics
private final Clock clock
private final ElapsedTimeStrategy pollOutputDelay
private final CommonConnectorConfig.EventProcessingFailureHandlingMode eventDeserializationFailureHandlingMode
private final CommonConnectorConfig.EventProcessingFailureHandlingMode inconsistentSchemaHandlingMode
private int startingRowNumber
private long recordCounter
private long previousOutputMillis
private long initialEventsToSkip
private boolean skipEvent
private boolean ignoreDmlEventByGtidSource
private final AtomicLong totalRecordCounter
private com.github.shyiko.mysql.binlog.GtidSet gtidSet
private Heartbeat heartbeat
private MySqlJdbcContext connectionContext
private final float heartbeatIntervalFactor
public BinlogReader(String name, MySqlTaskContext context, HaltingPredicate acceptAndContinue)
name
- the name of this reader; may not be nullcontext
- the task context in which this reader is running; may not be nullacceptAndContinue
- see AbstractReader#AbstractReader(String, MySqlTaskContext, Predicate)
public BinlogReader(String name, MySqlTaskContext context, HaltingPredicate acceptAndContinue, long serverId)
name
- the name of this reader; may not be nullcontext
- the task context in which this reader is running; may not be nullacceptAndContinue
- see AbstractReader#AbstractReader(String, MySqlTaskContext, Predicate)
serverId
- the server id to use for the BinaryLogClient
protected void doInitialize()
AbstractReader
AbstractReader.doStart()
.doInitialize
in class AbstractReader
public void doDestroy()
AbstractReader
AbstractReader.doStop()
.doDestroy
in class AbstractReader
protected void doStart()
AbstractReader
doStart
in class AbstractReader
protected void rewindBinaryLogClient(BinlogReader.BinlogPosition position)
public Map<String,?> getLastOffset()
protected void doStop()
AbstractReader
started
.
This method is always called when AbstractReader.stop()
is called, and the first time AbstractReader.isRunning()
will return
true
the first time and false
for any subsequent calls.
doStop
in class AbstractReader
protected void doCleanup()
AbstractReader
enqueued records
have been
consumed
, so this reader should clean up any resources that might remain.doCleanup
in class AbstractReader
protected void pollComplete(List<org.apache.kafka.connect.source.SourceRecord> batch)
AbstractReader
AbstractReader.poll()
completes sending a non-zero-sized batch of records.pollComplete
in class AbstractReader
batch
- the batch of records being recordedprotected void logEvent(com.github.shyiko.mysql.binlog.event.Event event)
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, so we need to discard the cache of record makers
.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)
protected 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 blockingprotected 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 blockingprotected static com.github.shyiko.mysql.binlog.network.SSLMode sslModeFor(MySqlConnectorConfig.SecureConnectionMode mode)
private void logReaderState()
private void logReaderState(org.slf4j.event.Level severity)
protected BinlogReaderMetrics getMetrics()
protected com.github.shyiko.mysql.binlog.BinaryLogClient getBinlogClient()
public BinlogReader.BinlogPosition getCurrentBinlogPosition()
private com.github.shyiko.mysql.binlog.network.SSLSocketFactory getBinlogSslSocketFactory(MySqlJdbcContext connectionContext)
Copyright © 2020 JBoss by Red Hat. All rights reserved.