Package io.debezium.connector.binlog
Class BinlogSnapshotChangeEventSource<P extends BinlogPartition,O extends BinlogOffsetContext<?>>
java.lang.Object
io.debezium.pipeline.source.AbstractSnapshotChangeEventSource<P,O>
io.debezium.relational.RelationalSnapshotChangeEventSource<P,O>
io.debezium.connector.binlog.BinlogSnapshotChangeEventSource<P,O>
- All Implemented Interfaces:
ChangeEventSource,SnapshotChangeEventSource<P,,O> AutoCloseable
public abstract class BinlogSnapshotChangeEventSource<P extends BinlogPartition,O extends BinlogOffsetContext<?>>
extends RelationalSnapshotChangeEventSource<P,O>
An abstract implementation of
SnapshotChangeEventSource for binlog-based connectors.- Author:
- Chris Cranford
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classBinlogSnapshotChangeEventSource.BinlogSnapshotContext<P extends BinlogPartition,O extends BinlogOffsetContext> 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
FieldsModifier and TypeFieldDescriptionprivate final BinlogConnectorConnectionprivate final BinlogConnectorConfigprivate final BinlogDatabaseSchema<P,O, ?, ?> private final RelationalTableFiltersprivate longprivate final BlockingConsumer<Function<org.apache.kafka.connect.source.SourceRecord,org.apache.kafka.connect.source.SourceRecord>> private static final org.slf4j.Loggerprivate final BinlogSnapshotChangeEventSourceMetrics<P>private final Runnableprivate static final org.slf4j.Loggerprivate final Set<SchemaChangeEvent>private longFields inherited from class io.debezium.relational.RelationalSnapshotChangeEventSource
clock, connectionPool, dispatcher, MATCH_ALL_PATTERN, SELECT_ALL_PATTERN, snapshotterServiceFields inherited from class io.debezium.pipeline.source.AbstractSnapshotChangeEventSource
LOG_INTERVAL, notificationService -
Constructor Summary
ConstructorsConstructorDescriptionBinlogSnapshotChangeEventSource(BinlogConnectorConfig connectorConfig, MainConnectionProvidingConnectionFactory<BinlogConnectorConnection> connectionFactory, BinlogDatabaseSchema<P, O, ?, ?> schema, EventDispatcher<P, TableId> dispatcher, Clock clock, BinlogSnapshotChangeEventSourceMetrics<P> metrics, BlockingConsumer<Function<org.apache.kafka.connect.source.SourceRecord, org.apache.kafka.connect.source.SourceRecord>> lastEventProcessor, Runnable preSnapshotAction, NotificationService<P, O> notificationService, SnapshotterService snapshotterService) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddSchemaEvent(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, String database, String ddl) createDdlForTableCallable(TableId tableId, Queue<JdbcConnection> connectionPool) protected voidcreateSchemaChangeEventsForTables(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, SnapshottingTask snapshottingTask) private voidcreateSchemaEventsForTables(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, Collection<TableId> tablesToRead, boolean firstPhase) private voidcreateSchemaEventsForTables(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, Collection<TableId> tablesToRead, boolean firstPhase, ExecutorService executorService) private StatementCreate a JDBC statement that can be used for large result sets.protected voiddetermineSnapshotOffset(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> ctx, O previousOffset) protected SchemaChangeEventgetCreateTableEvent(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, Table table) protected abstract OgetInitialOffsetContext(BinlogConnectorConfig connectorConfig) getSnapshotConnectionFirstSelect(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, TableId tableId) getSnapshotSelect(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, TableId tableId, List<String> columns) Generate a valid MySQL query string for the specified table and columnsgetSnapshotSelect(TableId tableId, List<String> columns) private voidprivate voidprivate booleanprivate booleanprotected voidlockTablesForSchemaSnapshot(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) protected voidprotected AbstractSnapshotChangeEventSource.SnapshotContext<P,O> protected voidprivate Stringprivate Stringprotected StatementreadTableStatement(JdbcConnection jdbcConnection, OptionalLong rowCount) protected voidreadTableStructure(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, O offsetContext, SnapshottingTask snapshottingTask) protected voidreleaseDataSnapshotLocks(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) protected voidreleaseSchemaSnapshotLocks(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) protected OptionalLongrowCountForTable(TableId tableId) protected abstract voidsetOffsetContextBinlogPositionAndGtidDetailsForSnapshot(O offsetContext, BinlogConnectorConnection connection, SnapshotterService snapshotterService) private voidtableLock(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) private voidprivate booleanMethods inherited from class io.debezium.relational.RelationalSnapshotChangeEventSource
additionalColumnFilter, connectionCreated, connectionPoolConnectionCreated, copyOffset, createDataEventsForTableCallable, createSnapshotConnection, doCreateDataEventsForTable, doExecute, enhanceOverriddenSelect, getBlockingSnapshottingTask, getChangeRecordEmitter, getClock, getPreparedColumnNames, getSignalDataCollectionPattern, getSnapshotSelectOverridesByTable, getSnapshotSourceTimestamp, getSnapshottingTask, getTablesForSchemaChange, lastSnapshotRecord, resultSetForDataEvents, tryStartingSnapshotMethods inherited from class io.debezium.pipeline.source.AbstractSnapshotChangeEventSource
aborted, close, completed, delaySnapshotIfNeeded, determineDataCollectionsToBeSnapshotted, execute, getDataCollectionPattern, getOffsets
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
ROW_ESTIMATE_LOGGER
private static final org.slf4j.Logger ROW_ESTIMATE_LOGGER -
connectorConfig
-
connection
-
filters
-
metrics
-
databaseSchema
private final BinlogDatabaseSchema<P extends BinlogPartition,O extends BinlogOffsetContext<?>, databaseSchema?, ?> -
schemaEvents
-
lastEventProcessor
private final BlockingConsumer<Function<org.apache.kafka.connect.source.SourceRecord,org.apache.kafka.connect.source.SourceRecord>> lastEventProcessor -
preSnapshotAction
-
delayedSchemaSnapshotTables
-
globalLockAcquiredAt
private long globalLockAcquiredAt -
tableLockAcquiredAt
private long tableLockAcquiredAt
-
-
Constructor Details
-
BinlogSnapshotChangeEventSource
public BinlogSnapshotChangeEventSource(BinlogConnectorConfig connectorConfig, MainConnectionProvidingConnectionFactory<BinlogConnectorConnection> connectionFactory, BinlogDatabaseSchema<P, O, ?, ?> schema, EventDispatcher<P, TableId> dispatcher, Clock clock, BinlogSnapshotChangeEventSourceMetrics<P> metrics, BlockingConsumer<Function<org.apache.kafka.connect.source.SourceRecord, org.apache.kafka.connect.source.SourceRecord>> lastEventProcessor, Runnable preSnapshotAction, NotificationService<P, O> notificationService, SnapshotterService snapshotterService)
-
-
Method Details
-
prepare
protected AbstractSnapshotChangeEventSource.SnapshotContext<P,O> prepare(P partition, boolean onDemand) - Specified by:
preparein classAbstractSnapshotChangeEventSource<P extends BinlogPartition,O extends BinlogOffsetContext<?>>
-
getAllTableIds
protected Set<TableId> getAllTableIds(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> ctx) throws Exception- Specified by:
getAllTableIdsin classRelationalSnapshotChangeEventSource<P extends BinlogPartition,O extends BinlogOffsetContext<?>> - Throws:
Exception
-
lockTablesForSchemaSnapshot
protected void lockTablesForSchemaSnapshot(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) throws SQLException- Specified by:
lockTablesForSchemaSnapshotin classRelationalSnapshotChangeEventSource<P extends BinlogPartition,O extends BinlogOffsetContext<?>> - Throws:
SQLException
-
releaseSchemaSnapshotLocks
protected void releaseSchemaSnapshotLocks(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) throws SQLException- Specified by:
releaseSchemaSnapshotLocksin classRelationalSnapshotChangeEventSource<P extends BinlogPartition,O extends BinlogOffsetContext<?>> - Throws:
SQLException
-
releaseDataSnapshotLocks
protected void releaseDataSnapshotLocks(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) throws Exception- Overrides:
releaseDataSnapshotLocksin classRelationalSnapshotChangeEventSource<P extends BinlogPartition,O extends BinlogOffsetContext<?>> - Throws:
Exception
-
determineSnapshotOffset
protected void determineSnapshotOffset(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> ctx, O previousOffset) throws Exception- Specified by:
determineSnapshotOffsetin classRelationalSnapshotChangeEventSource<P extends BinlogPartition,O extends BinlogOffsetContext<?>> - Throws:
Exception
-
getInitialOffsetContext
-
setOffsetContextBinlogPositionAndGtidDetailsForSnapshot
protected abstract void setOffsetContextBinlogPositionAndGtidDetailsForSnapshot(O offsetContext, BinlogConnectorConnection connection, SnapshotterService snapshotterService) throws Exception - Throws:
Exception
-
addSchemaEvent
private void addSchemaEvent(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, String database, String ddl) -
readTableStructure
protected void readTableStructure(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, O offsetContext, SnapshottingTask snapshottingTask) throws Exception- Specified by:
readTableStructurein classRelationalSnapshotChangeEventSource<P extends BinlogPartition,O extends BinlogOffsetContext<?>> - Throws:
Exception
-
createSchemaEventsForTables
private void createSchemaEventsForTables(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, Collection<TableId> tablesToRead, boolean firstPhase) throws Exception- Throws:
Exception
-
createSchemaEventsForTables
private void createSchemaEventsForTables(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, Collection<TableId> tablesToRead, boolean firstPhase, ExecutorService executorService) throws Exception- Throws:
Exception
-
createDdlForTableCallable
-
twoPhaseSchemaSnapshot
private boolean twoPhaseSchemaSnapshot() -
getCreateTableEvent
protected SchemaChangeEvent getCreateTableEvent(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, Table table) - Specified by:
getCreateTableEventin classRelationalSnapshotChangeEventSource<P extends BinlogPartition,O extends BinlogOffsetContext<?>>
-
getSnapshotSelect
protected Optional<String> getSnapshotSelect(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, TableId tableId, List<String> columns) Generate a valid MySQL query string for the specified table and columns- Specified by:
getSnapshotSelectin classRelationalSnapshotChangeEventSource<P extends BinlogPartition,O extends BinlogOffsetContext<?>> - Parameters:
tableId- the table to generate a query for- Returns:
- a valid query string
-
getSnapshotSelect
-
getSnapshotConnectionFirstSelect
protected Optional<String> getSnapshotConnectionFirstSelect(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, TableId tableId) - Overrides:
getSnapshotConnectionFirstSelectin classRelationalSnapshotChangeEventSource<P extends BinlogPartition,O extends BinlogOffsetContext<?>>
-
isGloballyLocked
private boolean isGloballyLocked() -
isTablesLocked
private boolean isTablesLocked() -
globalLock
- Throws:
SQLException
-
globalUnlock
- Throws:
SQLException
-
tableLock
private void tableLock(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) throws SQLException- Throws:
SQLException
-
tableUnlock
- Throws:
SQLException
-
quote
-
quote
-
rowCountForTable
- Overrides:
rowCountForTablein classRelationalSnapshotChangeEventSource<P extends BinlogPartition,O extends BinlogOffsetContext<?>>
-
readTableStatement
protected Statement readTableStatement(JdbcConnection jdbcConnection, OptionalLong rowCount) throws SQLException - Overrides:
readTableStatementin classRelationalSnapshotChangeEventSource<P extends BinlogPartition,O extends BinlogOffsetContext<?>> - Throws:
SQLException
-
createStatementWithLargeResultSet
private Statement createStatementWithLargeResultSet(BinlogConnectorConnection 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
Statementwithforward-onlycursor andread-only concurrencyflags, and with aminimum valuefetch 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<P, O> snapshotContext, SnapshottingTask snapshottingTask) throws Exception- Overrides:
createSchemaChangeEventsForTablesin classRelationalSnapshotChangeEventSource<P extends BinlogPartition,O extends BinlogOffsetContext<?>> - Throws:
Exception
-
postSnapshot
- Overrides:
postSnapshotin classRelationalSnapshotChangeEventSource<P extends BinlogPartition,O extends BinlogOffsetContext<?>> - Throws:
InterruptedException
-
preSnapshot
- Overrides:
preSnapshotin classRelationalSnapshotChangeEventSource<P extends BinlogPartition,O extends BinlogOffsetContext<?>> - Throws:
InterruptedException
-