Package io.debezium.connector.mysql
Class MySqlSnapshotChangeEventSource
java.lang.Object
io.debezium.pipeline.source.AbstractSnapshotChangeEventSource<P,O>
io.debezium.relational.RelationalSnapshotChangeEventSource<MySqlPartition,MySqlOffsetContext>
io.debezium.connector.mysql.MySqlSnapshotChangeEventSource
- All Implemented Interfaces:
ChangeEventSource
,SnapshotChangeEventSource<MySqlPartition,
,MySqlOffsetContext> AutoCloseable
public class MySqlSnapshotChangeEventSource
extends RelationalSnapshotChangeEventSource<MySqlPartition,MySqlOffsetContext>
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate static class
Mutable context which is populated in the course of snapshotting.Nested classes/interfaces inherited from class io.debezium.relational.RelationalSnapshotChangeEventSource
RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P extends Partition,
O extends OffsetContext> Nested classes/interfaces inherited from class io.debezium.pipeline.source.AbstractSnapshotChangeEventSource
AbstractSnapshotChangeEventSource.SnapshotContext<P extends Partition,
O extends OffsetContext> Nested classes/interfaces inherited from interface io.debezium.pipeline.source.spi.ChangeEventSource
ChangeEventSource.ChangeEventSourceContext
-
Field Summary
Modifier and TypeFieldDescriptionprivate final AbstractConnectorConnection
private final MySqlConnectorConfig
private final MySqlDatabaseSchema
private final RelationalTableFilters
private long
private final BlockingConsumer<Function<org.apache.kafka.connect.source.SourceRecord,
org.apache.kafka.connect.source.SourceRecord>> private static final org.slf4j.Logger
private final MySqlSnapshotChangeEventSourceMetrics
private final Runnable
private final List<SchemaChangeEvent>
private long
Fields inherited from class io.debezium.relational.RelationalSnapshotChangeEventSource
clock, connectionPool, dispatcher, MATCH_ALL_PATTERN, SELECT_ALL_PATTERN
Fields inherited from class io.debezium.pipeline.source.AbstractSnapshotChangeEventSource
LOG_INTERVAL, notificationService
-
Constructor Summary
ConstructorDescriptionMySqlSnapshotChangeEventSource
(MySqlConnectorConfig connectorConfig, MainConnectionProvidingConnectionFactory<AbstractConnectorConnection> connectionFactory, MySqlDatabaseSchema schema, EventDispatcher<MySqlPartition, TableId> dispatcher, Clock clock, MySqlSnapshotChangeEventSourceMetrics metrics, BlockingConsumer<Function<org.apache.kafka.connect.source.SourceRecord, org.apache.kafka.connect.source.SourceRecord>> lastEventProcessor, Runnable preSnapshotAction, NotificationService<MySqlPartition, MySqlOffsetContext> notificationService) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addSchemaEvent
(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext, String database, String ddl) protected MySqlOffsetContext
copyOffset
(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext) createDdlForTableCallable
(TableId tableId, Queue<JdbcConnection> connectionPool) protected void
createSchemaChangeEventsForTables
(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext, SnapshottingTask snapshottingTask) private void
createSchemaEventsForTables
(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext, Collection<TableId> tablesToRead, boolean firstPhase) private void
createSchemaEventsForTables
(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext, Collection<TableId> tablesToRead, boolean firstPhase, ExecutorService executorService) private Statement
Create a JDBC statement that can be used for large result sets.protected void
determineSnapshotOffset
(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> ctx, MySqlOffsetContext previousOffset) getAllTableIds
(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> ctx) protected SchemaChangeEvent
getCreateTableEvent
(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext, Table table) getSnapshotConnectionFirstSelect
(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext, TableId tableId) getSnapshotSelect
(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext, TableId tableId, List<String> columns) Generate a valid MySQL query string for the specified table and columnsprivate String
getSnapshotSelect
(TableId tableId, List<String> columns) getSnapshottingTask
(MySqlPartition partition, MySqlOffsetContext previousOffset) private void
private void
private boolean
private boolean
protected void
lockTablesForSchemaSnapshot
(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext) protected void
prepare
(MySqlPartition partition) protected void
private String
private String
protected Statement
readTableStatement
(JdbcConnection jdbcConnection, OptionalLong rowCount) protected void
readTableStructure
(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext, MySqlOffsetContext offsetContext, SnapshottingTask snapshottingTask) protected void
releaseDataSnapshotLocks
(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext) protected void
releaseSchemaSnapshotLocks
(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext) protected OptionalLong
rowCountForTable
(TableId tableId) private void
tableLock
(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext) private void
private boolean
Methods inherited from class io.debezium.relational.RelationalSnapshotChangeEventSource
additionalColumnFilter, connectionCreated, connectionPoolConnectionCreated, createSnapshotConnection, doExecute, enhanceOverriddenSelect, getChangeRecordEmitter, getClock, getPreparedColumnNames, getSignalDataCollectionPattern, getSnapshotSelectOverridesByTable, getSnapshotSourceTimestamp, getTablesForSchemaChange, lastSnapshotRecord, resultSetForDataEvents, tryStartingSnapshot
Methods inherited from class io.debezium.pipeline.source.AbstractSnapshotChangeEventSource
aborted, close, completed, delaySnapshotIfNeeded, determineDataCollectionsToBeSnapshotted, execute, getDataCollectionPattern, getOffsets
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.SnapshotChangeEventSource
getBlockingSnapshottingTask
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
connectorConfig
-
connection
-
globalLockAcquiredAt
private long globalLockAcquiredAt -
tableLockAcquiredAt
private long tableLockAcquiredAt -
filters
-
metrics
-
databaseSchema
-
schemaEvents
-
delayedSchemaSnapshotTables
-
lastEventProcessor
private final BlockingConsumer<Function<org.apache.kafka.connect.source.SourceRecord,org.apache.kafka.connect.source.SourceRecord>> lastEventProcessor -
preSnapshotAction
-
-
Constructor Details
-
MySqlSnapshotChangeEventSource
public MySqlSnapshotChangeEventSource(MySqlConnectorConfig connectorConfig, MainConnectionProvidingConnectionFactory<AbstractConnectorConnection> connectionFactory, MySqlDatabaseSchema schema, EventDispatcher<MySqlPartition, TableId> dispatcher, Clock clock, MySqlSnapshotChangeEventSourceMetrics metrics, BlockingConsumer<Function<org.apache.kafka.connect.source.SourceRecord, org.apache.kafka.connect.source.SourceRecord>> lastEventProcessor, Runnable preSnapshotAction, NotificationService<MySqlPartition, MySqlOffsetContext> notificationService)
-
-
Method Details
-
getSnapshottingTask
public SnapshottingTask getSnapshottingTask(MySqlPartition partition, MySqlOffsetContext previousOffset) - Specified by:
getSnapshottingTask
in interfaceSnapshotChangeEventSource<MySqlPartition,
MySqlOffsetContext> - Specified by:
getSnapshottingTask
in classAbstractSnapshotChangeEventSource<MySqlPartition,
MySqlOffsetContext>
-
prepare
protected AbstractSnapshotChangeEventSource.SnapshotContext<MySqlPartition,MySqlOffsetContext> prepare(MySqlPartition partition) throws Exception - Specified by:
prepare
in classAbstractSnapshotChangeEventSource<MySqlPartition,
MySqlOffsetContext> - Throws:
Exception
-
getAllTableIds
protected Set<TableId> getAllTableIds(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> ctx) throws Exception- Specified by:
getAllTableIds
in classRelationalSnapshotChangeEventSource<MySqlPartition,
MySqlOffsetContext> - Throws:
Exception
-
lockTablesForSchemaSnapshot
protected void lockTablesForSchemaSnapshot(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext) throws SQLException- Specified by:
lockTablesForSchemaSnapshot
in classRelationalSnapshotChangeEventSource<MySqlPartition,
MySqlOffsetContext> - Throws:
SQLException
-
releaseSchemaSnapshotLocks
protected void releaseSchemaSnapshotLocks(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext) throws SQLException- Specified by:
releaseSchemaSnapshotLocks
in classRelationalSnapshotChangeEventSource<MySqlPartition,
MySqlOffsetContext> - Throws:
SQLException
-
releaseDataSnapshotLocks
protected void releaseDataSnapshotLocks(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext) throws Exception- Overrides:
releaseDataSnapshotLocks
in classRelationalSnapshotChangeEventSource<MySqlPartition,
MySqlOffsetContext> - Throws:
Exception
-
determineSnapshotOffset
protected void determineSnapshotOffset(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> ctx, MySqlOffsetContext previousOffset) throws Exception- Specified by:
determineSnapshotOffset
in classRelationalSnapshotChangeEventSource<MySqlPartition,
MySqlOffsetContext> - Throws:
Exception
-
addSchemaEvent
private void addSchemaEvent(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext, String database, String ddl) -
readTableStructure
protected void readTableStructure(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext, MySqlOffsetContext offsetContext, SnapshottingTask snapshottingTask) throws Exception- Specified by:
readTableStructure
in classRelationalSnapshotChangeEventSource<MySqlPartition,
MySqlOffsetContext> - Throws:
Exception
-
createSchemaEventsForTables
private void createSchemaEventsForTables(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext, Collection<TableId> tablesToRead, boolean firstPhase) throws Exception- Throws:
Exception
-
createSchemaEventsForTables
private void createSchemaEventsForTables(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext, Collection<TableId> tablesToRead, boolean firstPhase, ExecutorService executorService) throws Exception- Throws:
Exception
-
createDdlForTableCallable
-
twoPhaseSchemaSnapshot
private boolean twoPhaseSchemaSnapshot() -
getCreateTableEvent
protected SchemaChangeEvent getCreateTableEvent(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext, Table table) - Specified by:
getCreateTableEvent
in classRelationalSnapshotChangeEventSource<MySqlPartition,
MySqlOffsetContext>
-
getSnapshotSelect
protected Optional<String> getSnapshotSelect(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext, TableId tableId, List<String> columns) Generate a valid MySQL query string for the specified table and columns- Specified by:
getSnapshotSelect
in classRelationalSnapshotChangeEventSource<MySqlPartition,
MySqlOffsetContext> - Parameters:
tableId
- the table to generate a query for- Returns:
- a valid query string
-
getSnapshotSelect
-
getSnapshotConnectionFirstSelect
protected Optional<String> getSnapshotConnectionFirstSelect(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext, TableId tableId) -
isGloballyLocked
private boolean isGloballyLocked() -
isTablesLocked
private boolean isTablesLocked() -
globalLock
- Throws:
SQLException
-
globalUnlock
- Throws:
SQLException
-
tableLock
private void tableLock(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext) throws SQLException- Throws:
SQLException
-
tableUnlock
- Throws:
SQLException
-
quote
-
quote
-
rowCountForTable
- Overrides:
rowCountForTable
in classRelationalSnapshotChangeEventSource<MySqlPartition,
MySqlOffsetContext>
-
readTableStatement
protected Statement readTableStatement(JdbcConnection jdbcConnection, OptionalLong rowCount) throws SQLException - Overrides:
readTableStatement
in classRelationalSnapshotChangeEventSource<MySqlPartition,
MySqlOffsetContext> - Throws:
SQLException
-
createStatementWithLargeResultSet
private Statement createStatementWithLargeResultSet(AbstractConnectorConnection connection) throws SQLException Create a JDBC statement that can be used for large result sets.By default, the MySQL Connector/J driver retrieves all rows for ResultSets and stores them in memory. In most cases this is the most efficient way to operate and, due to the design of the MySQL network protocol, is easier to implement. However, when ResultSets that have a large number of rows or large values, the driver may not be able to allocate heap space in the JVM and may result in an
OutOfMemoryError
. See DBZ-94 for details.This method handles such cases using the recommended technique for MySQL by creating the JDBC
Statement
withforward-only
cursor andread-only concurrency
flags, and with aminimum value
fetch size hint
.- Returns:
- the statement; never null
- Throws:
SQLException
- if there is a problem creating the statement
-
createSchemaChangeEventsForTables
protected void createSchemaChangeEventsForTables(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext, SnapshottingTask snapshottingTask) throws Exception- Overrides:
createSchemaChangeEventsForTables
in classRelationalSnapshotChangeEventSource<MySqlPartition,
MySqlOffsetContext> - Throws:
Exception
-
postSnapshot
- Overrides:
postSnapshot
in classRelationalSnapshotChangeEventSource<MySqlPartition,
MySqlOffsetContext> - Throws:
InterruptedException
-
preSnapshot
- Overrides:
preSnapshot
in classRelationalSnapshotChangeEventSource<MySqlPartition,
MySqlOffsetContext> - Throws:
InterruptedException
-
copyOffset
protected MySqlOffsetContext copyOffset(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<MySqlPartition, MySqlOffsetContext> snapshotContext) - Specified by:
copyOffset
in classRelationalSnapshotChangeEventSource<MySqlPartition,
MySqlOffsetContext>
-