Class AbstractIncrementalSnapshotChangeEventSource<P extends Partition,T extends DataCollectionId>
java.lang.Object
io.debezium.pipeline.source.snapshot.incremental.AbstractIncrementalSnapshotChangeEventSource<P,T>
- All Implemented Interfaces:
IncrementalSnapshotChangeEventSource<P,T>
- Direct Known Subclasses:
SignalBasedIncrementalSnapshotChangeEventSource
@NotThreadSafe
public abstract class AbstractIncrementalSnapshotChangeEventSource<P extends Partition,T extends DataCollectionId>
extends Object
implements IncrementalSnapshotChangeEventSource<P,T>
An incremental snapshot change event source that emits events from a DB log interleaved with snapshot events.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Clockprotected Tables.ColumnNameFilterprotected final RelationalDatabaseConnectorConfigprotected IncrementalSnapshotContext<T>private Tableprivate final RelationalDatabaseSchemaprivate final DataChangeEventListener<P>protected EventDispatcher<P,T> protected JdbcConnectionprivate static final org.slf4j.Loggerprotected final NotificationService<P,? extends OffsetContext> private final SnapshotProgressListener<P>private long -
Constructor Summary
ConstructorsConstructorDescriptionAbstractIncrementalSnapshotChangeEventSource(RelationalDatabaseConnectorConfig config, JdbcConnection jdbcConnection, EventDispatcher<P, T> dispatcher, DatabaseSchema<?> databaseSchema, Clock clock, SnapshotProgressListener<P> progressListener, DataChangeEventListener<P> dataChangeEventListener, NotificationService<P, ? extends OffsetContext> notificationService) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDataCollectionNamesToSnapshot(SignalPayload<P> signalPayload, SnapshotConfiguration snapshotConfiguration) protected voidaddKeyColumnsToCondition(Table table, StringBuilder sql, String predicate) private voidaddLowerBound(Table table, StringBuilder sql) protected StringbuildChunkQuery(Table table, int limit, Optional<String> additionalCondition) protected StringbuildChunkQuery(Table table, Optional<String> additionalCondition) protected StringbuildMaxPrimaryKeyQuery(Table table, Optional<String> additionalCondition) protected StringbuildProjection(Table table) private booleanvoidcloseWindow(P partition, String id, OffsetContext offsetContext) private booleancreateDataEventsForTable(P partition) Dispatches the data change events for the records of a single table.protected voiddeduplicateWindow(DataCollectionId dataCollectionId, Object key) protected abstract voidemitWindowClose(P partition, OffsetContext offsetContext) Update high watermark for the incremental snapshot chunkprotected abstract voidUpdate low watermark for the incremental snapshot chunkexpandAndDedupeDataCollectionIds(List<String> dataCollectionIds) Expands the string-based list of data collection ids if supplied using regex to a list of all matching explicit data collection ids.protected ChangeRecordEmitter<P>getChangeRecordEmitter(P partition, T dataCollectionId, OffsetContext offsetContext, Object[] row) Returns aChangeRecordEmitterproducing the change records for the given table row.private Key.KeyMappergetQueryColumns(Table table) protected StringgetSignalTableName(String dataCollectionId) private Tableprivate Threads.Timerprivate voidincrementTableRowsScanned(P partition, long rows) voidinit(P partition, OffsetContext offsetContext) private booleanisTableInvalid(P partition, OffsetContext offsetContext) private Object[]keyFromRow(Object[] row) private voidnextDataCollection(P partition, OffsetContext offsetContext) voidpauseSnapshot(P partition, OffsetContext offsetContext) protected voidprotected voidpostReadChunk(IncrementalSnapshotContext<T> context) protected voidpreReadChunk(IncrementalSnapshotContext<T> context) voidprocessSchemaChange(P partition, OffsetContext offsetContext, DataCollectionId dataCollectionId) protected voidreadChunk(P partition, OffsetContext offsetContext) private Tableprotected PreparedStatementprotected TablerefreshTableSchema(Table table) voidrereadChunk(P partition, OffsetContext offsetContext) voidresumeSnapshot(P partition, OffsetContext offsetContext) private booleanVerifies that in-memory representation of the table’s schema is up to date with the table's schema in the database.protected voidsendEvent(P partition, EventDispatcher<P, T> dispatcher, OffsetContext offsetContext, Object[] row) protected voidsendWindowEvents(P partition, OffsetContext offsetContext) protected voidsetContext(IncrementalSnapshotContext<T> context) voidstopSnapshot(P partition, OffsetContext offsetContext, Map<String, Object> additionalData, List<String> dataCollectionIds) private voidtableScanCompleted(P partition) private voidVerifies that table's schema in the database has not changed since it was captured in the previous windowMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.debezium.pipeline.source.snapshot.incremental.IncrementalSnapshotChangeEventSource
processFilteredEvent, processHeartbeat, processMessage, processTransactionCommittedEvent, processTransactionStartedEvent
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
connectorConfig
-
clock
-
databaseSchema
-
progressListener
-
dataListener
-
totalRowsScanned
private long totalRowsScanned -
currentTable
-
dispatcher
-
context
-
jdbcConnection
-
columnFilter
-
window
-
notificationService
protected final NotificationService<P extends Partition,? extends OffsetContext> notificationService
-
-
Constructor Details
-
AbstractIncrementalSnapshotChangeEventSource
public AbstractIncrementalSnapshotChangeEventSource(RelationalDatabaseConnectorConfig config, JdbcConnection jdbcConnection, EventDispatcher<P, T> dispatcher, DatabaseSchema<?> databaseSchema, Clock clock, SnapshotProgressListener<P> progressListener, DataChangeEventListener<P> dataChangeEventListener, NotificationService<P, ? extends OffsetContext> notificationService)
-
-
Method Details
-
closeWindow
public void closeWindow(P partition, String id, OffsetContext offsetContext) throws InterruptedException - Specified by:
closeWindowin interfaceIncrementalSnapshotChangeEventSource<P extends Partition,T extends DataCollectionId> - Throws:
InterruptedException
-
pauseSnapshot
- Specified by:
pauseSnapshotin interfaceIncrementalSnapshotChangeEventSource<P extends Partition,T extends DataCollectionId>
-
resumeSnapshot
- Specified by:
resumeSnapshotin interfaceIncrementalSnapshotChangeEventSource<P extends Partition,T extends DataCollectionId> - Throws:
InterruptedException
-
processSchemaChange
public void processSchemaChange(P partition, OffsetContext offsetContext, DataCollectionId dataCollectionId) throws InterruptedException - Specified by:
processSchemaChangein interfaceIncrementalSnapshotChangeEventSource<P extends Partition,T extends DataCollectionId> - Throws:
InterruptedException
-
rereadChunk
- Throws:
InterruptedException
-
getSignalTableName
-
sendWindowEvents
protected void sendWindowEvents(P partition, OffsetContext offsetContext) throws InterruptedException - Throws:
InterruptedException
-
sendEvent
protected void sendEvent(P partition, EventDispatcher<P, T> dispatcher, OffsetContext offsetContext, Object[] row) throws InterruptedException- Throws:
InterruptedException
-
getChangeRecordEmitter
protected ChangeRecordEmitter<P> getChangeRecordEmitter(P partition, T dataCollectionId, OffsetContext offsetContext, Object[] row) Returns aChangeRecordEmitterproducing the change records for the given table row. -
deduplicateWindow
-
emitWindowOpen
Update low watermark for the incremental snapshot chunk- Throws:
SQLException
-
emitWindowClose
Update high watermark for the incremental snapshot chunk- Throws:
Exception
-
buildChunkQuery
-
buildChunkQuery
-
buildProjection
-
addLowerBound
-
buildMaxPrimaryKeyQuery
-
init
- Specified by:
initin interfaceIncrementalSnapshotChangeEventSource<P extends Partition,T extends DataCollectionId>
-
readChunk
- Throws:
InterruptedException
-
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
-
nextDataCollection
-
addDataCollectionNamesToSnapshot
public void addDataCollectionNamesToSnapshot(SignalPayload<P> signalPayload, SnapshotConfiguration snapshotConfiguration) throws InterruptedException - Specified by:
addDataCollectionNamesToSnapshotin interfaceIncrementalSnapshotChangeEventSource<P extends Partition,T extends DataCollectionId> - Throws:
InterruptedException
-
stopSnapshot
public void stopSnapshot(P partition, OffsetContext offsetContext, Map<String, Object> additionalData, List<String> dataCollectionIds) - Specified by:
stopSnapshotin interfaceIncrementalSnapshotChangeEventSource<P extends Partition,T extends DataCollectionId>
-
addKeyColumnsToCondition
-
expandAndDedupeDataCollectionIds
Expands the string-based list of data collection ids if supplied using regex to a list of all matching explicit data collection ids. -
createDataEventsForTable
Dispatches the data change events for the records of a single table. -
checkSchemaChanges
- Throws:
SQLException
-
getTable
- Throws:
SQLException
-
incrementTableRowsScanned
-
tableScanCompleted
-
readTableChunkStatement
- Throws:
SQLException
-
getTableScanLogTimer
-
keyFromRow
-
setContext
-
preReadChunk
-
postReadChunk
-
postIncrementalSnapshotCompleted
protected void postIncrementalSnapshotCompleted() -
refreshTableSchema
- Throws:
SQLException
-
getKeyMapper
-
getQueryColumns
-