Package io.debezium.connector.binlog
Class BinlogStreamingChangeEventSource<P extends BinlogPartition,O extends BinlogOffsetContext>
java.lang.Object
io.debezium.connector.binlog.BinlogStreamingChangeEventSource<P,O>
- All Implemented Interfaces:
ChangeEventSource,StreamingChangeEventSource<P,O>
public abstract class BinlogStreamingChangeEventSource<P extends BinlogPartition,O extends BinlogOffsetContext>
extends Object
implements StreamingChangeEventSource<P,O>
An abstract common implementation of
StreamingChangeEventSource for binlog-based connectors.- Author:
- Jiri Pechanec, Chris Cranford
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static interfacestatic classClass that represents a binlog file and positionprivate static interfaceprotected final classprivate static interfaceBinlogStreamingChangeEventSource.RowsProvider<E extends com.github.shyiko.mysql.binlog.event.EventData,U> private static interfaceBinlogStreamingChangeEventSource.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
FieldsModifier and TypeFieldDescriptionprivate final com.github.shyiko.mysql.binlog.BinaryLogClientprivate final Clockprivate final BinlogConnectorConnectionprivate final BinlogConnectorConfigprivate Oprivate final ErrorHandlerprivate final CommonConnectorConfig.EventProcessingFailureHandlingModeprivate final EventDispatcher<P,TableId> private final EnumMap<com.github.shyiko.mysql.binlog.event.EventType,BlockingConsumer<com.github.shyiko.mysql.binlog.event.Event>> protected Instantprivate final floatprivate booleanprivate final CommonConnectorConfig.EventProcessingFailureHandlingModeprivate longprivate final booleanprivate static final Stringprivate static final org.slf4j.Loggerprivate final BinlogStreamingChangeEventSourceMetrics<?,P> private final BinlogDatabaseSchemaprivate static final Stringprivate booleanprivate final SnapshotterServiceprivate intprivate final BinlogTaskContext<?>private final AtomicLong -
Constructor Summary
ConstructorsConstructorDescriptionBinlogStreamingChangeEventSource(BinlogConnectorConfig connectorConfig, BinlogConnectorConnection connection, EventDispatcher<P, TableId> dispatcher, ErrorHandler errorHandler, Clock clock, BinlogTaskContext<?> taskContext, BinlogDatabaseSchema schema, BinlogStreamingChangeEventSourceMetrics<?, P> metrics, SnapshotterService snapshotterService) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidconfigureReplicaCompatibility(com.github.shyiko.mysql.binlog.BinaryLogClient client) protected com.github.shyiko.mysql.binlog.BinaryLogClientcreateBinaryLogClient(BinlogTaskContext<?> taskContext, BinlogConnectorConfig connectorConfig, Map<String, Thread> clientThreads, BinlogConnectorConnection connection) protected com.github.shyiko.mysql.binlog.event.deserialization.EventDeserializervoidexecute(ChangeEventSource.ChangeEventSourceContext context, P partition, O offsetContext) private com.github.shyiko.mysql.binlog.network.SSLSocketFactorygetBinlogSslSocketFactory(BinlogConnectorConfig connectorConfig, BinlogConnectorConnection connection) protected abstract Class<? extends org.apache.kafka.connect.source.SourceConnector>(package private) BinlogStreamingChangeEventSource.BinlogPositionprotected abstract com.github.shyiko.mysql.binlog.event.EventTypeprotected abstract com.github.shyiko.mysql.binlog.event.EventType(package private) BinlogStreamingChangeEventSourceMetrics<?,P> private <T extends com.github.shyiko.mysql.binlog.event.EventData,U>
voidhandleChange(P partition, O offsetContext, com.github.shyiko.mysql.binlog.event.Event event, Envelope.Operation operation, Class<T> eventDataClass, BinlogStreamingChangeEventSource.TableIdProvider<T> tableIdProvider, BinlogStreamingChangeEventSource.RowsProvider<T, U> rowsProvider, BinlogStreamingChangeEventSource.BinlogChangeEmitter<U> changeEmitter, BinlogStreamingChangeEventSource.ChangeEventValidator<U> changeEventValidator) protected voidhandleDelete(P partition, O offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Generate source records for the supplied event with anDeleteRowsEventData.protected voidhandleEvent(P partition, O offsetContext, ChangeEventSource.ChangeEventSourceContext context, com.github.shyiko.mysql.binlog.event.Event event) protected abstract voidhandleGtidEvent(P partition, O offsetContext, com.github.shyiko.mysql.binlog.event.Event event, Predicate<String> gtidSourceFilter) Handle the GTID event.protected voidhandleInsert(P partition, O offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Generate source records for the supplied event with anWriteRowsEventData.protected voidhandleQueryEvent(P partition, O offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle the supplied event with anQueryEventDataby possibly recording the DDL statements as changes in the database schemas.protected abstract voidhandleRecordingQuery(O offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle the supplied event with aRowsQueryEventDataorAnnotateRowsEventDataby recording the original SQL query that generated the event.protected voidhandleRotateLogsEvent(O offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle the supplied event with aRotateEventDatathat signals the logs are being rotated.protected voidhandleServerHeartbeat(P partition, O 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 voidhandleServerIncident(P partition, O 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 voidhandleServerStop(O offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle the supplied event that signals that the database has stopped.protected voidhandleTransactionBegin(P partition, O offsetContext, com.github.shyiko.mysql.binlog.event.Event event, Long threadId) private voidhandleTransactionCompletion(P partition, O offsetContext, com.github.shyiko.mysql.binlog.event.Event event) protected voidhandleTransactionPayload(P partition, O offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle an event of type TRANSACTION_PAYLOAD_EVENTprotected voidhandleUpdate(P partition, O offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Generate source records for the supplied event with anUpdateRowsEventData.protected voidhandleUpdateTableMetadata(P partition, O offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle a change in the table metadata.protected voidignoreEvent(O offsetContext, com.github.shyiko.mysql.binlog.event.Event event) private voidinformAboutUnknownTableIfRequired(P partition, O offsetContext, com.github.shyiko.mysql.binlog.event.Event event, TableId tableId) 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 per theBinlogConnectorConfig.INCONSISTENT_SCHEMA_HANDLING_MODEconfiguration.private voidinformAboutUnknownTableIfRequired(P partition, O 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 per theBinlogConnectorConfig.INCONSISTENT_SCHEMA_HANDLING_MODEconfiguration.protected abstract voidinitializeGtidSet(String value) Initialize the connector's global transaction identifier set.protected booleanprotected voidprivate voidprivate voidlogStreamingSourceState(org.slf4j.event.Level severity) protected voidprotected voidprepareTransaction(O offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle aEventType.XA_PREPAREevent.private StringremoveSetStatement(String sql) (package private) voidrewindBinaryLogClient(ChangeEventSource.ChangeEventSourceContext context, BinlogStreamingChangeEventSource.BinlogPosition position) protected voidsetEffectiveOffsetContext(O offsetContext) protected abstract voidsetEventTimestamp(com.github.shyiko.mysql.binlog.event.Event event, long eventTs) protected voidsetGtidChanged(String gtid) protected voidsetIgnoreDmlEventByGtidSource(boolean ignoreDmlEventByGtidSource) private com.github.shyiko.mysql.binlog.network.SSLModeprotected <T extends com.github.shyiko.mysql.binlog.event.EventData>
TunwrapData(com.github.shyiko.mysql.binlog.event.Event event) private voidvalidateChangeEventWithTable(Table table, Object[] before, Object[] after) protected voidviewChange(O offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle aEventType.VIEW_CHANGEevent.private voidprotected DebeziumExceptionWraps 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, waitMethods inherited from interface io.debezium.pipeline.source.spi.StreamingChangeEventSource
commitOffset, executeIteration, init
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
KEEPALIVE_THREAD_NAME
- See Also:
-
SET_STATEMENT_REGEX
- See Also:
-
client
private final com.github.shyiko.mysql.binlog.BinaryLogClient client -
metrics
-
taskContext
-
schema
-
connectorConfig
-
connection
-
eventDispatcher
-
clock
-
errorHandler
-
eventDeserializationFailureHandlingMode
private final CommonConnectorConfig.EventProcessingFailureHandlingMode eventDeserializationFailureHandlingMode -
inconsistentSchemaHandlingMode
private final CommonConnectorConfig.EventProcessingFailureHandlingMode inconsistentSchemaHandlingMode -
snapshotterService
-
gtidDmlSourceFilter
-
isGtidModeEnabled
private final boolean isGtidModeEnabled -
totalRecordCounter
-
binaryLogClientThreads
-
eventHandlers
private final EnumMap<com.github.shyiko.mysql.binlog.event.EventType,BlockingConsumer<com.github.shyiko.mysql.binlog.event.Event>> eventHandlers -
heartbeatIntervalFactor
private final float heartbeatIntervalFactor- See Also:
-
startingRowNumber
private int startingRowNumber -
initialEventsToSkip
private long initialEventsToSkip -
skipEvent
private boolean skipEvent -
ignoreDmlEventByGtidSource
private boolean ignoreDmlEventByGtidSource -
lastOffset
-
effectiveOffsetContext
-
eventTimestamp
-
-
Constructor Details
-
BinlogStreamingChangeEventSource
public BinlogStreamingChangeEventSource(BinlogConnectorConfig connectorConfig, BinlogConnectorConnection connection, EventDispatcher<P, TableId> dispatcher, ErrorHandler errorHandler, Clock clock, BinlogTaskContext<?> taskContext, BinlogDatabaseSchema schema, BinlogStreamingChangeEventSourceMetrics<?, P> metrics, SnapshotterService snapshotterService)
-
-
Method Details
-
execute
public void execute(ChangeEventSource.ChangeEventSourceContext context, P partition, O offsetContext) throws InterruptedException - Specified by:
executein interfaceStreamingChangeEventSource<P extends BinlogPartition,O extends BinlogOffsetContext> - Throws:
InterruptedException
-
getOffsetContext
- Specified by:
getOffsetContextin interfaceStreamingChangeEventSource<P extends BinlogPartition,O extends BinlogOffsetContext>
-
setEffectiveOffsetContext
-
setIgnoreDmlEventByGtidSource
protected void setIgnoreDmlEventByGtidSource(boolean ignoreDmlEventByGtidSource) -
setGtidChanged
-
isGtidModeEnabled
protected boolean isGtidModeEnabled() -
createBinaryLogClient
protected com.github.shyiko.mysql.binlog.BinaryLogClient createBinaryLogClient(BinlogTaskContext<?> taskContext, BinlogConnectorConfig connectorConfig, Map<String, Thread> clientThreads, BinlogConnectorConnection connection) -
configureReplicaCompatibility
protected void configureReplicaCompatibility(com.github.shyiko.mysql.binlog.BinaryLogClient client) -
createEventDeserializer
protected com.github.shyiko.mysql.binlog.event.deserialization.EventDeserializer createEventDeserializer() -
onEvent
-
setEventTimestamp
protected abstract void setEventTimestamp(com.github.shyiko.mysql.binlog.event.Event event, long eventTs) -
ignoreEvent
-
handleEvent
protected void handleEvent(P partition, O 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
Handle the supplied event that signals that the database has stopped.- Parameters:
event- the server stopped event to be processed; may not be null
-
handleServerHeartbeat
protected void handleServerHeartbeat(P partition, O 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(P partition, O 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(O offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle the supplied event with aRotateEventDatathat 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 from those seen to this point.- Parameters:
event- the database change data event to be processed; may not be null
-
handleQueryEvent
protected void handleQueryEvent(P partition, O offsetContext, com.github.shyiko.mysql.binlog.event.Event event) throws InterruptedException Handle the supplied event with anQueryEventDataby possibly recording the DDL statements as changes in the database 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
-
removeSetStatement
-
handleUpdateTableMetadata
protected void handleUpdateTableMetadata(P partition, O 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:
partition- the partition; never nulloffsetContext- the offset context; never nullevent- the update event; never null- Throws:
InterruptedException
- the table structure is modified (e.g., via an
-
handleTransactionPayload
protected void handleTransactionPayload(P partition, O offsetContext, com.github.shyiko.mysql.binlog.event.Event event) throws InterruptedException Handle an event of type TRANSACTION_PAYLOAD_EVENT This 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.- Parameters:
partition- the partition; never nulloffsetContext- the offset context; never nullevent- the transaction payload event; never null- Throws:
InterruptedException
-
handleInsert
protected void handleInsert(P partition, O 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(P partition, O 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(P partition, O 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
-
viewChange
protected void viewChange(O offsetContext, com.github.shyiko.mysql.binlog.event.Event event) throws InterruptedException Handle aEventType.VIEW_CHANGEevent.- 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(O offsetContext, com.github.shyiko.mysql.binlog.event.Event event) throws InterruptedException Handle aEventType.XA_PREPAREevent.- Parameters:
event- the database change data event to be processed; may not be null- Throws:
InterruptedException- if this thread is interrupted while blocking
-
handleTransactionBegin
protected void handleTransactionBegin(P partition, O offsetContext, com.github.shyiko.mysql.binlog.event.Event event, Long threadId) throws InterruptedException - Throws:
InterruptedException
-
getConnectorClass
protected abstract Class<? extends org.apache.kafka.connect.source.SourceConnector> getConnectorClass()- Returns:
- the connector class type
-
handleGtidEvent
protected abstract void handleGtidEvent(P partition, O offsetContext, com.github.shyiko.mysql.binlog.event.Event event, Predicate<String> gtidSourceFilter) throws InterruptedException Handle the GTID event.- Parameters:
partition- the partition; never nulloffsetContext- the offset context; never nullevent- the eventgtidSourceFilter- the GTID source filter- Throws:
InterruptedException- if the thread is interrupted
-
handleRecordingQuery
protected abstract void handleRecordingQuery(O offsetContext, com.github.shyiko.mysql.binlog.event.Event event) Handle the supplied event with aRowsQueryEventDataorAnnotateRowsEventDataby recording the original SQL query that generated the event.- Parameters:
offsetContext- the offset context; never nullevent- the database change data event to be processed; may not be null
-
getIncludeQueryEventType
protected abstract com.github.shyiko.mysql.binlog.event.EventType getIncludeQueryEventType()- Returns:
- the event type for reading query events from
-
getGtidEventType
protected abstract com.github.shyiko.mysql.binlog.event.EventType getGtidEventType()- Returns:
- the event type for the global transaction identifier events
-
initializeGtidSet
Initialize the connector's global transaction identifier set.- Parameters:
value- the value to initialize the set based upon
-
getGtidDmlSourceFilter
-
handleTransactionCompletion
private void handleTransactionCompletion(P partition, O offsetContext, com.github.shyiko.mysql.binlog.event.Event event) throws InterruptedException - Throws:
InterruptedException
-
informAboutUnknownTableIfRequired
private void informAboutUnknownTableIfRequired(P partition, O 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 per theBinlogConnectorConfig.INCONSISTENT_SCHEMA_HANDLING_MODEconfiguration.- Parameters:
partition- the partition; never nulloffsetContext- the offset context; never nullevent- the binlog eventtableId- the table identifieroperation- the operation being performed- Throws:
InterruptedException
-
informAboutUnknownTableIfRequired
private void informAboutUnknownTableIfRequired(P partition, O offsetContext, com.github.shyiko.mysql.binlog.event.Event event, TableId tableId) 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 per theBinlogConnectorConfig.INCONSISTENT_SCHEMA_HANDLING_MODEconfiguration.- Parameters:
partition- the partition; never nulloffsetContext- the offset context; never nullevent- the binlog eventtableId- the table identifier- Throws:
InterruptedException- if the thread is interrupted
-
validateChangeEventWithTable
-
handleChange
private <T extends com.github.shyiko.mysql.binlog.event.EventData,U> void handleChange(P partition, O offsetContext, com.github.shyiko.mysql.binlog.event.Event event, Envelope.Operation operation, Class<T> eventDataClass, BinlogStreamingChangeEventSource.TableIdProvider<T> tableIdProvider, BinlogStreamingChangeEventSource.RowsProvider<T, U> rowsProvider, BinlogStreamingChangeEventSource.BinlogChangeEmitter<U> changeEmitter, BinlogStreamingChangeEventSource.ChangeEventValidator<U> changeEventValidator) throws InterruptedException- Throws:
InterruptedException
-
waitWhenStreamingPaused
private void waitWhenStreamingPaused(ChangeEventSource.ChangeEventSourceContext context) throws InterruptedException - Throws:
InterruptedException
-
logStreamingSourceState
private void logStreamingSourceState() -
logEvent
-
logStreamingSourceState
private void logStreamingSourceState(org.slf4j.event.Level severity) -
getMetrics
BinlogStreamingChangeEventSourceMetrics<?,P> getMetrics() -
rewindBinaryLogClient
void rewindBinaryLogClient(ChangeEventSource.ChangeEventSourceContext context, BinlogStreamingChangeEventSource.BinlogPosition position) -
getCurrentBinlogPosition
BinlogStreamingChangeEventSource.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
-
sslModeFor
private com.github.shyiko.mysql.binlog.network.SSLMode sslModeFor(BinlogConnectorConfig.SecureConnectionMode mode) -
getBinlogSslSocketFactory
private com.github.shyiko.mysql.binlog.network.SSLSocketFactory getBinlogSslSocketFactory(BinlogConnectorConfig connectorConfig, BinlogConnectorConnection connection)
-