Class AbstractIncrementalSnapshotChangeEventSource<T extends DataCollectionId>
- java.lang.Object
-
- io.debezium.pipeline.source.snapshot.incremental.AbstractIncrementalSnapshotChangeEventSource<T>
-
- All Implemented Interfaces:
IncrementalSnapshotChangeEventSource<T>
- Direct Known Subclasses:
SignalBasedIncrementalSnapshotChangeEventSource
@NotThreadSafe public abstract class AbstractIncrementalSnapshotChangeEventSource<T extends DataCollectionId> extends Object implements IncrementalSnapshotChangeEventSource<T>
An incremental snapshot change event source that emits events from a DB log interleaved with snapshot events.
-
-
Field Summary
Fields Modifier and Type Field Description private Clockclockprivate RelationalDatabaseConnectorConfigconnectorConfigprotected IncrementalSnapshotContext<T>contextprivate TablecurrentTableprivate RelationalDatabaseSchemadatabaseSchemaprivate DataChangeEventListenerdataListenerprotected EventDispatcher<T>dispatcherprotected JdbcConnectionjdbcConnectionprivate static org.slf4j.LoggerLOGGERprivate SnapshotProgressListenerprogressListenerprivate longtotalRowsScannedprotected Map<org.apache.kafka.connect.data.Struct,Object[]>window
-
Constructor Summary
Constructors Constructor Description AbstractIncrementalSnapshotChangeEventSource(RelationalDatabaseConnectorConfig config, JdbcConnection jdbcConnection, EventDispatcher<T> dispatcher, DatabaseSchema<?> databaseSchema, Clock clock, SnapshotProgressListener progressListener, DataChangeEventListener dataChangeEventListener)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddDataCollectionNamesToSnapshot(List<String> dataCollectionIds, OffsetContext offsetContext)protected voidaddKeyColumnsToCondition(Table table, StringBuilder sql, String predicate)private voidaddLowerBound(Table table, StringBuilder sql)protected StringbuildChunkQuery(Table table)protected StringbuildChunkQuery(Table table, int limit)protected StringbuildMaxPrimaryKeyQuery(Table table)private booleancheckSchemaChanges(ResultSet rs)voidcloseWindow(Partition partition, String id, OffsetContext offsetContext)private booleancreateDataEventsForTable()Dispatches the data change events for the records of a single table.protected voiddeduplicateWindow(DataCollectionId dataCollectionId, Object key)protected abstract voidemitWindowClose()Update high watermark for the incremental snapshot chunkprotected abstract voidemitWindowOpen()Update low watermark for the incremental snapshot chunkprotected ChangeRecordEmittergetChangeRecordEmitter(Partition partition, T dataCollectionId, OffsetContext offsetContext, Object[] row)Returns aChangeRecordEmitterproducing the change records for the given table row.private Key.KeyMappergetKeyMapper()protected StringgetSignalTableName(String dataCollectionId)private TablegetTable(ResultSet rs)private Threads.TimergetTableScanLogTimer()private voidincrementTableRowsScanned(long rows)voidinit(OffsetContext offsetContext)private booleanisTableInvalid()private Object[]keyFromRow(Object[] row)private voidnextDataCollection()protected voidpostIncrementalSnapshotCompleted()protected voidpostReadChunk(IncrementalSnapshotContext<T> context)protected voidpreReadChunk(IncrementalSnapshotContext<T> context)protected voidreadChunk()private TablereadSchema()protected PreparedStatementreadTableChunkStatement(String sql)protected TablerefreshTableSchema(Table table)private booleanschemaHistoryIsUpToDate()Verifies that in-memory representation of the table’s schema is up to date with the table's schema in the database.protected voidsendEvent(Partition partition, EventDispatcher<T> dispatcher, OffsetContext offsetContext, Object[] row)protected voidsendWindowEvents(Partition partition, OffsetContext offsetContext)protected voidsetContext(IncrementalSnapshotContext<T> context)private voidtableScanCompleted()private voidverifySchemaUnchanged()Verifies that table's schema in the database has not changed since it was captured in the previous window-
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.snapshot.incremental.IncrementalSnapshotChangeEventSource
processFilteredEvent, processHeartbeat, processMessage, processTransactionCommittedEvent, processTransactionStartedEvent
-
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
connectorConfig
private final RelationalDatabaseConnectorConfig connectorConfig
-
clock
private final Clock clock
-
databaseSchema
private final RelationalDatabaseSchema databaseSchema
-
progressListener
private final SnapshotProgressListener progressListener
-
dataListener
private final DataChangeEventListener dataListener
-
totalRowsScanned
private long totalRowsScanned
-
currentTable
private Table currentTable
-
dispatcher
protected EventDispatcher<T extends DataCollectionId> dispatcher
-
context
protected IncrementalSnapshotContext<T extends DataCollectionId> context
-
jdbcConnection
protected JdbcConnection jdbcConnection
-
-
Constructor Detail
-
AbstractIncrementalSnapshotChangeEventSource
public AbstractIncrementalSnapshotChangeEventSource(RelationalDatabaseConnectorConfig config, JdbcConnection jdbcConnection, EventDispatcher<T> dispatcher, DatabaseSchema<?> databaseSchema, Clock clock, SnapshotProgressListener progressListener, DataChangeEventListener dataChangeEventListener)
-
-
Method Detail
-
closeWindow
public void closeWindow(Partition partition, String id, OffsetContext offsetContext) throws InterruptedException
- Specified by:
closeWindowin interfaceIncrementalSnapshotChangeEventSource<T extends DataCollectionId>- Throws:
InterruptedException
-
sendWindowEvents
protected void sendWindowEvents(Partition partition, OffsetContext offsetContext) throws InterruptedException
- Throws:
InterruptedException
-
sendEvent
protected void sendEvent(Partition partition, EventDispatcher<T> dispatcher, OffsetContext offsetContext, Object[] row) throws InterruptedException
- Throws:
InterruptedException
-
getChangeRecordEmitter
protected ChangeRecordEmitter getChangeRecordEmitter(Partition partition, T dataCollectionId, OffsetContext offsetContext, Object[] row)
Returns aChangeRecordEmitterproducing the change records for the given table row.
-
deduplicateWindow
protected void deduplicateWindow(DataCollectionId dataCollectionId, Object key)
-
emitWindowOpen
protected abstract void emitWindowOpen() throws SQLExceptionUpdate low watermark for the incremental snapshot chunk- Throws:
SQLException
-
emitWindowClose
protected abstract void emitWindowClose() throws SQLException, InterruptedExceptionUpdate high watermark for the incremental snapshot chunk- Throws:
SQLExceptionInterruptedException
-
addLowerBound
private void addLowerBound(Table table, StringBuilder sql)
-
init
public void init(OffsetContext offsetContext)
- Specified by:
initin interfaceIncrementalSnapshotChangeEventSource<T extends DataCollectionId>
-
readChunk
protected void readChunk() throws InterruptedException- Throws:
InterruptedException
-
isTableInvalid
private boolean isTableInvalid()
-
schemaHistoryIsUpToDate
private boolean schemaHistoryIsUpToDate()
Verifies that in-memory representation of the table’s schema is up to date with the table's schema in the database.Verification is a two step process:
- Save table's schema from the database to the context
- Verify schema hasn't changed in the following window. If schema has changed repeat the process
Verification is done at the beginning of the incremental snapshot and on every schema change during the snapshotting.
-
verifySchemaUnchanged
private void verifySchemaUnchanged()
Verifies that table's schema in the database has not changed since it was captured in the previous window
-
readSchema
private Table readSchema()
-
nextDataCollection
private void nextDataCollection()
-
addDataCollectionNamesToSnapshot
public void addDataCollectionNamesToSnapshot(List<String> dataCollectionIds, OffsetContext offsetContext) throws InterruptedException
- Specified by:
addDataCollectionNamesToSnapshotin interfaceIncrementalSnapshotChangeEventSource<T extends DataCollectionId>- Throws:
InterruptedException
-
addKeyColumnsToCondition
protected void addKeyColumnsToCondition(Table table, StringBuilder sql, String predicate)
-
createDataEventsForTable
private boolean createDataEventsForTable()
Dispatches the data change events for the records of a single table.
-
checkSchemaChanges
private boolean checkSchemaChanges(ResultSet rs) throws SQLException
- Throws:
SQLException
-
getTable
private Table getTable(ResultSet rs) throws SQLException
- Throws:
SQLException
-
incrementTableRowsScanned
private void incrementTableRowsScanned(long rows)
-
tableScanCompleted
private void tableScanCompleted()
-
readTableChunkStatement
protected PreparedStatement readTableChunkStatement(String sql) throws SQLException
- Throws:
SQLException
-
getTableScanLogTimer
private Threads.Timer getTableScanLogTimer()
-
setContext
protected void setContext(IncrementalSnapshotContext<T> context)
-
preReadChunk
protected void preReadChunk(IncrementalSnapshotContext<T> context)
-
postReadChunk
protected void postReadChunk(IncrementalSnapshotContext<T> context)
-
postIncrementalSnapshotCompleted
protected void postIncrementalSnapshotCompleted()
-
refreshTableSchema
protected Table refreshTableSchema(Table table) throws SQLException
- Throws:
SQLException
-
getKeyMapper
private Key.KeyMapper getKeyMapper()
-
-