Package io.debezium.relational
Class RelationalSnapshotChangeEventSource<P extends Partition,O extends OffsetContext>
java.lang.Object
io.debezium.pipeline.source.AbstractSnapshotChangeEventSource<P,O>
io.debezium.relational.RelationalSnapshotChangeEventSource<P,O>
- All Implemented Interfaces:
ChangeEventSource,SnapshotChangeEventSource<P,,O> AutoCloseable
public abstract class RelationalSnapshotChangeEventSource<P extends Partition,O extends OffsetContext>
extends AbstractSnapshotChangeEventSource<P,O>
Base class for
SnapshotChangeEventSource for relational databases with or without a schema history.
A transaction is managed by this base class, sub-classes shouldn't rollback or commit this transaction. They are free to use nested transactions or savepoints, though.
- Author:
- Gunnar Morling
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static interfaceFunctional interface for operations that may throw SQLException.(package private) static interfaceFunctional interface for snapshot work that uses pooled resources.private static final recordHolds the prepared table information for snapshot processing.static classRelationalSnapshotChangeEventSource.RelationalSnapshotContext<P extends Partition,O extends OffsetContext> Mutable context which is populated in the course of snapshotting.private static classDetermines the appropriate SnapshotRecord marker based on record position.private static final recordprivate static classManages threaded execution of snapshot work using a thread pool.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 TypeFieldDescriptionprotected final io.debezium.util.Clockprotected Queue<JdbcConnection> private final RelationalDatabaseConnectorConfigprotected final EventDispatcher<P, TableId> private final JdbcConnectionprivate final MainConnectionProvidingConnectionFactory<? extends JdbcConnection> private static final org.slf4j.Loggerstatic final Patternprivate final RelationalDatabaseSchemastatic final Patternprivate final TableIdprivate final SnapshotProgressListener<P> protected final SnapshotterServiceFields inherited from class io.debezium.pipeline.source.AbstractSnapshotChangeEventSource
LOG_INTERVAL, notificationService -
Constructor Summary
ConstructorsConstructorDescriptionRelationalSnapshotChangeEventSource(RelationalDatabaseConnectorConfig connectorConfig, MainConnectionProvidingConnectionFactory<? extends JdbcConnection> jdbcConnectionFactory, RelationalDatabaseSchema schema, EventDispatcher<P, TableId> dispatcher, io.debezium.util.Clock clock, SnapshotProgressListener<P> snapshotProgressListener, NotificationService<P, O> notificationService, SnapshotterService snapshotterService) -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanadditionalColumnFilter(P partition, TableId tableId, String columnName) Additional filter handling for preparing column names for snapshot selectaddSignalingCollectionAndSort(Set<TableId> capturedTables) protected intcalculateChunkCount(OptionalLong rowCount, int maxThreads, int multiplier) protected voidconnectionCreated(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) Executes steps which have to be taken just after the database connection is created.protected voidconnectionPoolConnectionCreated(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, JdbcConnection connection) Executes steps which have to be taken just after a connection pool connection is created.protected abstract OcopyOffset(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) private voidcreateChunkedDataEvents(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, Queue<JdbcConnection> connectionPool, Map<io.debezium.spi.schema.DataCollectionId, String> snapshotSelectOverridesByTable, Queue<O> offsets, EventDispatcher.SnapshotReceiver<P> snapshotReceiver) private Queue<JdbcConnection> private voidcreateDataEvents(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, Queue<JdbcConnection> connectionPool, Map<io.debezium.spi.schema.DataCollectionId, String> snapshotSelectOverridesByTable) createDataEventsForChunkedTableCallable(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, EventDispatcher.SnapshotReceiver<P> snapshotReceiver, SnapshotChunk chunk, Map<TableId, TableChunkProgress> progressMap, SnapshotProgress snapshotProgress, Queue<JdbcConnection> connectionPool, Queue<O> offsets) createDataEventsForTableCallable(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, EventDispatcher.SnapshotReceiver<P> snapshotReceiver, Table table, boolean firstTable, boolean lastTable, int tableOrder, int tableCount, String selectStatement, OptionalLong rowCount, Set<TableId> rowCountTablesKeySet, Queue<JdbcConnection> connectionPool, Queue<O> offsets) private voidcreateLegacyDataEvents(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, Queue<JdbcConnection> connectionPool, Map<io.debezium.spi.schema.DataCollectionId, String> snapshotSelectOverridesByTable, Queue<O> offsets, EventDispatcher.SnapshotReceiver<P> snapshotReceiver) createOffsetPool(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, int poolSize) createPooledResourceCallable(Queue<JdbcConnection> connectionPool, Queue<O> offsetPool, RelationalSnapshotChangeEventSource.PooledWork<O> work, Runnable errorHandler) Creates a Callable that borrows resources from pools, executes work, and returns resources.protected voidcreateSchemaChangeEventsForTables(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, SnapshottingTask snapshottingTask) private voiddetermineCapturedTables(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> ctx, Set<Pattern> dataCollectionsToBeSnapshotted, SnapshottingTask snapshottingTask) protected abstract voiddetermineSnapshotOffset(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, O previousOffset) Determines the current offset (MySQL binlog position, Oracle SCN etc.), storing it into the passed context object.determineSnapshotSelect(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, TableId tableId, Map<io.debezium.spi.schema.DataCollectionId, String> snapshotSelectOverridesByTable) Returns a valid query string for the specified table, either given by the user via snapshot select overrides or defaulting to a statement provided by the DB-specific change event source.protected voiddoCreateDataEventsForChunk(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, O offset, EventDispatcher.SnapshotReceiver<P> snapshotReceiver, SnapshotChunk chunk, Map<TableId, TableChunkProgress> progressMap, SnapshotProgress snapshotProgress, JdbcConnection jdbcConnection) protected voiddoCreateDataEventsForTable(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, O offset, EventDispatcher.SnapshotReceiver<P> snapshotReceiver, Table table, boolean firstTable, boolean lastTable, int tableOrder, int tableCount, String selectStatement, OptionalLong rowCount, Set<TableId> rowCountTablesKeySet, JdbcConnection jdbcConnection) doExecute(ChangeEventSource.ChangeEventSourceContext context, O previousOffset, AbstractSnapshotChangeEventSource.SnapshotContext<P, O> snapshotContext, SnapshottingTask snapshottingTask) Executes this source.private voidemitRecordWithCoordination(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, O offset, EventDispatcher.SnapshotReceiver<P> snapshotReceiver, SnapshotChunk chunk, TableChunkProgress progress, SnapshotProgress snapshotProgress, TableId tableId, Object[] row, Instant sourceTableSnapshotTimestamp, boolean isFirstRecord, boolean isLastRecord) Emits a record with proper coordination to ensure correct snapshot marker ordering.protected StringenhanceOverriddenSelect(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, String overriddenSelect, TableId tableId) This method is overridden for Oracle to implement "as of SCN" predicategetAllTableIds(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) Returns all candidate tables; the current filter configuration will be applied to the result set, resulting in the effective set of captured tables.getBlockingSnapshottingTask(P partition, O previousOffset, SnapshotConfiguration snapshotConfiguration) Returns the blocking snapshotting task based on the snapshot configuration from the signal.protected ChangeRecordEmitter<P> Returns aChangeRecordEmitterproducing the change records for the given table row.protected io.debezium.util.ClockgetClock()protected abstract SchemaChangeEventgetCreateTableEvent(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, Table table) Creates aSchemaChangeEventrepresenting the creation of the given table.getKeyColumnsForChunking(Table table) getPreparedColumnNames(P partition, Table table) Prepares a list of columns to be used in the snapshot select.getSignalDataCollectionPattern(String signalingDataCollection) getSnapshotConnectionFirstSelect(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, TableId tableId) getSnapshotSelect(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, TableId tableId, List<String> columns) Returns the SELECT statement to be used for scanning the given table or empty value if the table will be streamed from but not snapshottedprotected StringgetSnapshotSelectOverridesByTable(TableId tableId, Map<io.debezium.spi.schema.DataCollectionId, String> snapshotSelectOverrides) protected InstantgetSnapshotSourceTimestamp(JdbcConnection jdbcConnection, O offset, TableId tableId) For the given table gets source.ts_ms value from the database for snapshot data!getSnapshottingTask(P partition, O previousOffset) Returns the snapshotting task based on the previous offset (if available) and the connector's snapshotting mode.private io.debezium.util.Threads.Timerprotected Collection<TableId> getTablesForSchemaChange(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) private voidhandleEmptyChunkCoordination(SnapshotChunk chunk, TableChunkProgress progress, SnapshotProgress snapshotProgress) Handles coordination for empty chunks to ensure latches are properly signaled.private voidinitializePooledConnection(JdbcConnection connection) private booleanisUseNonChunkedSnapshots(int snapshotMaxThreads) protected voidlastSnapshotRecord(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) protected abstract voidlockTablesForSchemaSnapshot(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) Locks all tables to be captured, so that no concurrent schema changes can be applied to them.protected voidprepareTables(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, Function<TableId, RelationalSnapshotChangeEventSource.SnapshotSelect> selectGenerator, RelationalSnapshotChangeEventSource.CheckedFunction<TableId, OptionalLong> rowCountProvider) Prepares tables for snapshot by generating select statements and row counts.protected voidprotected StatementreadTableStatement(JdbcConnection jdbcConnection, OptionalLong tableSize) Allow per-connector query creation to override for best database performance depending on the table size.protected abstract voidreadTableStructure(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, O offsetContext, SnapshottingTask snapshottingTask) Reads the structure of all the captured tables, writing it toRelationalSnapshotChangeEventSource.RelationalSnapshotContext.tables.protected voidreleaseDataSnapshotLocks(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) Releases all locks established in order to create a consistent data snapshot.protected abstract voidreleaseSchemaSnapshotLocks(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) Releases all locks established in order to create a consistent schema snapshot.protected ResultSetresultSetForDataEvents(String selectStatement, Statement statement) private voidrollbackTransaction(Connection connection) protected OptionalLongrowCountForTable(TableId tableId) If connector is able to provide statistics-based number of records per table.protected LongrowCountForTableChunked(TableId tableId) private voidsetChunkSnapshotMarker(OffsetContext offset, SnapshotChunk chunk, boolean firstRecordInChunk, boolean lastRecordInChunk) private voidsetSnapshotMarker(OffsetContext offset, boolean firstTable, boolean lastTable, boolean firstRecordInTable, boolean lastRecordInTable) private Map<TableId, OptionalLong> sortByRowCount(Map<TableId, OptionalLong> rowCountTables, RelationalDatabaseConnectorConfig.SnapshotTablesRowCountOrder order) toTableIds(Set<TableId> tableIds, Pattern pattern) protected voidtryStartingSnapshot(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) Methods inherited from class io.debezium.pipeline.source.AbstractSnapshotChangeEventSource
aborted, close, completed, delaySnapshotIfNeeded, determineDataCollectionsToBeSnapshotted, execute, getDataCollectionPattern, getOffsets, prepare
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
SELECT_ALL_PATTERN
-
MATCH_ALL_PATTERN
-
connectorConfig
-
jdbcConnection
-
jdbcConnectionFactory
private final MainConnectionProvidingConnectionFactory<? extends JdbcConnection> jdbcConnectionFactory -
schema
-
dispatcher
-
clock
protected final io.debezium.util.Clock clock -
snapshotProgressListener
-
snapshotterService
-
connectionPool
-
signalDataCollectionTableId
-
-
Constructor Details
-
RelationalSnapshotChangeEventSource
public RelationalSnapshotChangeEventSource(RelationalDatabaseConnectorConfig connectorConfig, MainConnectionProvidingConnectionFactory<? extends JdbcConnection> jdbcConnectionFactory, RelationalDatabaseSchema schema, EventDispatcher<P, TableId> dispatcher, io.debezium.util.Clock clock, SnapshotProgressListener<P> snapshotProgressListener, NotificationService<P, O> notificationService, SnapshotterService snapshotterService)
-
-
Method Details
-
doExecute
public SnapshotResult<O> doExecute(ChangeEventSource.ChangeEventSourceContext context, O previousOffset, AbstractSnapshotChangeEventSource.SnapshotContext<P, O> snapshotContext, SnapshottingTask snapshottingTask) throws ExceptionDescription copied from class:AbstractSnapshotChangeEventSourceExecutes this source. Implementations should regularly check via the given context if they should stop. If that's the case, they should abort their processing and perform any clean-up needed, such as rolling back pending transactions, releasing locks, etc.- Specified by:
doExecutein classAbstractSnapshotChangeEventSource<P extends Partition,O extends OffsetContext> - Parameters:
context- contextual information for this source's executionpreviousOffset- previous offset restored from KafkasnapshotContext- mutable context information populated throughout the snapshot processsnapshottingTask- immutable information about what tasks should be performed during snapshot- Returns:
- an indicator to the position at which the snapshot was taken
- Throws:
Exception
-
createConnectionPool
private Queue<JdbcConnection> createConnectionPool(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> ctx) throws SQLException- Throws:
SQLException
-
initializePooledConnection
- Throws:
SQLException
-
createSnapshotConnection
- Throws:
SQLException
-
getBlockingSnapshottingTask
public SnapshottingTask getBlockingSnapshottingTask(P partition, O previousOffset, SnapshotConfiguration snapshotConfiguration) Description copied from interface:SnapshotChangeEventSourceReturns the blocking snapshotting task based on the snapshot configuration from the signal. -
getSnapshottingTask
Description copied from interface:SnapshotChangeEventSourceReturns the snapshotting task based on the previous offset (if available) and the connector's snapshotting mode. -
connectionCreated
protected void connectionCreated(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) throws ExceptionExecutes steps which have to be taken just after the database connection is created.- Throws:
Exception
-
connectionPoolConnectionCreated
protected void connectionPoolConnectionCreated(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, JdbcConnection connection) throws SQLExceptionExecutes steps which have to be taken just after a connection pool connection is created.- Throws:
SQLException
-
getSignalDataCollectionPattern
-
toTableIds
-
addSignalingCollectionAndSort
-
determineCapturedTables
private void determineCapturedTables(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> ctx, Set<Pattern> dataCollectionsToBeSnapshotted, SnapshottingTask snapshottingTask) throws Exception- Throws:
Exception
-
getAllTableIds
protected abstract Set<TableId> getAllTableIds(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) throws ExceptionReturns all candidate tables; the current filter configuration will be applied to the result set, resulting in the effective set of captured tables.- Throws:
Exception
-
lockTablesForSchemaSnapshot
protected abstract void lockTablesForSchemaSnapshot(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) throws ExceptionLocks all tables to be captured, so that no concurrent schema changes can be applied to them.- Throws:
Exception
-
determineSnapshotOffset
protected abstract void determineSnapshotOffset(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, O previousOffset) throws ExceptionDetermines the current offset (MySQL binlog position, Oracle SCN etc.), storing it into the passed context object. Subsequently, the DB's schema (and data) will be be read at this position. Once the snapshot is completed, aStreamingChangeEventSourcewill be set up with this initial position to continue with stream reading from there.- Throws:
Exception
-
readTableStructure
protected abstract void readTableStructure(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, O offsetContext, SnapshottingTask snapshottingTask) throws ExceptionReads the structure of all the captured tables, writing it toRelationalSnapshotChangeEventSource.RelationalSnapshotContext.tables.- Throws:
Exception
-
releaseSchemaSnapshotLocks
protected abstract void releaseSchemaSnapshotLocks(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) throws ExceptionReleases all locks established in order to create a consistent schema snapshot.- Throws:
Exception
-
releaseDataSnapshotLocks
protected void releaseDataSnapshotLocks(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) throws ExceptionReleases all locks established in order to create a consistent data snapshot.- Throws:
Exception
-
createSchemaChangeEventsForTables
protected void createSchemaChangeEventsForTables(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, SnapshottingTask snapshottingTask) throws Exception- Throws:
Exception
-
getTablesForSchemaChange
protected Collection<TableId> getTablesForSchemaChange(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) -
getCreateTableEvent
protected abstract SchemaChangeEvent getCreateTableEvent(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, Table table) throws ExceptionCreates aSchemaChangeEventrepresenting the creation of the given table.- Throws:
Exception
-
createDataEvents
private void createDataEvents(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, Queue<JdbcConnection> connectionPool, Map<io.debezium.spi.schema.DataCollectionId, throws ExceptionString> snapshotSelectOverridesByTable) - Throws:
Exception
-
isUseNonChunkedSnapshots
private boolean isUseNonChunkedSnapshots(int snapshotMaxThreads) -
createLegacyDataEvents
private void createLegacyDataEvents(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, Queue<JdbcConnection> connectionPool, Map<io.debezium.spi.schema.DataCollectionId, throws ExceptionString> snapshotSelectOverridesByTable, Queue<O> offsets, EventDispatcher.SnapshotReceiver<P> snapshotReceiver) - Throws:
Exception
-
createChunkedDataEvents
private void createChunkedDataEvents(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, Queue<JdbcConnection> connectionPool, Map<io.debezium.spi.schema.DataCollectionId, throws ExceptionString> snapshotSelectOverridesByTable, Queue<O> offsets, EventDispatcher.SnapshotReceiver<P> snapshotReceiver) - Throws:
Exception
-
emitRecordWithCoordination
private void emitRecordWithCoordination(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, O offset, EventDispatcher.SnapshotReceiver<P> snapshotReceiver, SnapshotChunk chunk, TableChunkProgress progress, SnapshotProgress snapshotProgress, TableId tableId, Object[] row, Instant sourceTableSnapshotTimestamp, boolean isFirstRecord, boolean isLastRecord) throws InterruptedExceptionEmits a record with proper coordination to ensure correct snapshot marker ordering.- Throws:
InterruptedException
-
handleEmptyChunkCoordination
private void handleEmptyChunkCoordination(SnapshotChunk chunk, TableChunkProgress progress, SnapshotProgress snapshotProgress) throws InterruptedException Handles coordination for empty chunks to ensure latches are properly signaled.- Throws:
InterruptedException
-
getKeyColumnsForChunking
-
calculateChunkCount
-
createOffsetPool
private Queue<O> createOffsetPool(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, int poolSize) -
sortByRowCount
private Map<TableId,OptionalLong> sortByRowCount(Map<TableId, OptionalLong> rowCountTables, RelationalDatabaseConnectorConfig.SnapshotTablesRowCountOrder order) -
copyOffset
protected abstract O copyOffset(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) -
tryStartingSnapshot
protected void tryStartingSnapshot(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) -
getSnapshotSourceTimestamp
protected Instant getSnapshotSourceTimestamp(JdbcConnection jdbcConnection, O offset, TableId tableId) For the given table gets source.ts_ms value from the database for snapshot data! For Postgresql its globally static for all tables since postgresql snapshot process setting auto commit off. For Mysql its static per table and might be ~second behind of the select statements start ts. -
createDataEventsForTableCallable
protected Callable<Void> createDataEventsForTableCallable(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, EventDispatcher.SnapshotReceiver<P> snapshotReceiver, Table table, boolean firstTable, boolean lastTable, int tableOrder, int tableCount, String selectStatement, OptionalLong rowCount, Set<TableId> rowCountTablesKeySet, Queue<JdbcConnection> connectionPool, Queue<O> offsets) -
createDataEventsForChunkedTableCallable
protected Callable<Void> createDataEventsForChunkedTableCallable(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, EventDispatcher.SnapshotReceiver<P> snapshotReceiver, SnapshotChunk chunk, Map<TableId, TableChunkProgress> progressMap, SnapshotProgress snapshotProgress, Queue<JdbcConnection> connectionPool, Queue<O> offsets) -
doCreateDataEventsForTable
protected void doCreateDataEventsForTable(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, O offset, EventDispatcher.SnapshotReceiver<P> snapshotReceiver, Table table, boolean firstTable, boolean lastTable, int tableOrder, int tableCount, String selectStatement, OptionalLong rowCount, Set<TableId> rowCountTablesKeySet, JdbcConnection jdbcConnection) throws InterruptedException, SQLException- Throws:
InterruptedExceptionSQLException
-
doCreateDataEventsForChunk
protected void doCreateDataEventsForChunk(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, O offset, EventDispatcher.SnapshotReceiver<P> snapshotReceiver, SnapshotChunk chunk, Map<TableId, throws InterruptedException, SQLExceptionTableChunkProgress> progressMap, SnapshotProgress snapshotProgress, JdbcConnection jdbcConnection) - Throws:
InterruptedExceptionSQLException
-
resultSetForDataEvents
protected ResultSet resultSetForDataEvents(String selectStatement, Statement statement) throws SQLException - Throws:
SQLException
-
setSnapshotMarker
private void setSnapshotMarker(OffsetContext offset, boolean firstTable, boolean lastTable, boolean firstRecordInTable, boolean lastRecordInTable) -
setChunkSnapshotMarker
private void setChunkSnapshotMarker(OffsetContext offset, SnapshotChunk chunk, boolean firstRecordInChunk, boolean lastRecordInChunk) -
lastSnapshotRecord
protected void lastSnapshotRecord(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext) -
rowCountForTable
If connector is able to provide statistics-based number of records per table. -
rowCountForTableChunked
- Throws:
SQLException
-
getTableScanLogTimer
private io.debezium.util.Threads.Timer getTableScanLogTimer() -
getChangeRecordEmitter
protected ChangeRecordEmitter<P> getChangeRecordEmitter(P partition, O offset, TableId tableId, Object[] row, Instant timestamp) Returns aChangeRecordEmitterproducing the change records for the given table row. -
determineSnapshotSelect
private RelationalSnapshotChangeEventSource.SnapshotSelect determineSnapshotSelect(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, TableId tableId, Map<io.debezium.spi.schema.DataCollectionId, String> snapshotSelectOverridesByTable) Returns a valid query string for the specified table, either given by the user via snapshot select overrides or defaulting to a statement provided by the DB-specific change event source.- Parameters:
tableId- the table to generate a query forsnapshotSelectOverridesByTable- the select overrides by table- Returns:
- a snapshot select record, never
nullvalid query string or empty if table will not be snapshotted
-
getSnapshotSelectOverridesByTable
-
getPreparedColumnNames
Prepares a list of columns to be used in the snapshot select. The selected columns are based on the column include/exclude filters and if all columns are excluded, the list will contain all the primary key columns.- Returns:
- list of snapshot select columns
-
additionalColumnFilter
Additional filter handling for preparing column names for snapshot select -
enhanceOverriddenSelect
protected String enhanceOverriddenSelect(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, String overriddenSelect, TableId tableId) This method is overridden for Oracle to implement "as of SCN" predicate- Parameters:
snapshotContext- snapshot context, used for getting offset SCNoverriddenSelect- conditional snapshot select- Returns:
- enhanced select statement. By default it just returns original select statements.
-
getSnapshotSelect
protected abstract Optional<String> getSnapshotSelect(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, TableId tableId, List<String> columns) Returns the SELECT statement to be used for scanning the given table or empty value if the table will be streamed from but not snapshotted -
getSnapshotConnectionFirstSelect
-
readTableStatement
protected Statement readTableStatement(JdbcConnection jdbcConnection, OptionalLong tableSize) throws SQLException Allow per-connector query creation to override for best database performance depending on the table size.- Throws:
SQLException
-
rollbackTransaction
-
prepareTables
private RelationalSnapshotChangeEventSource.PreparedTables prepareTables(RelationalSnapshotChangeEventSource.RelationalSnapshotContext<P, O> snapshotContext, Function<TableId, throws SQLExceptionRelationalSnapshotChangeEventSource.SnapshotSelect> selectGenerator, RelationalSnapshotChangeEventSource.CheckedFunction<TableId, OptionalLong> rowCountProvider) Prepares tables for snapshot by generating select statements and row counts.- Parameters:
snapshotContext- the snapshot contextselectGenerator- function to generate select statement for a tablerowCountProvider- function to get row count for a table- Returns:
- the prepared tables with query and row count maps
- Throws:
SQLException- if row count retrieval fails
-
createPooledResourceCallable
private Callable<Void> createPooledResourceCallable(Queue<JdbcConnection> connectionPool, Queue<O> offsetPool, RelationalSnapshotChangeEventSource.PooledWork<O> work, Runnable errorHandler) Creates a Callable that borrows resources from pools, executes work, and returns resources.- Parameters:
connectionPool- the pool of JDBC connectionsoffsetPool- the pool of offset contextswork- the work to execute with borrowed resourceserrorHandler- called if work throws an exception, can benull- Returns:
- a Callable wrapping the resource management
-
getClock
protected io.debezium.util.Clock getClock() -
postSnapshot
- Throws:
InterruptedException
-
preSnapshot
- Throws:
InterruptedException
-