Class AbstractIncrementalSnapshotChangeEventSource<P extends Partition,T extends io.debezium.spi.schema.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 io.debezium.spi.schema.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 TypeFieldDescriptionprotected ChunkQueryBuilder<T> private final io.debezium.util.Clockprotected 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, io.debezium.util.Clock clock, SnapshotProgressListener<P> progressListener, DataChangeEventListener<P> dataChangeEventListener, NotificationService<P, ? extends OffsetContext> notificationService) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDataCollectionNamesToSnapshot(SignalPayload<P> signalPayload, SnapshotConfiguration snapshotConfiguration) private voidcheckAndProcessStopFlag(P partition, OffsetContext offsetContext) private booleanvoidcloseWindow(P partition, String id, OffsetContext offsetContext) protected voidcreateAndDispatchSchemaChangeEvent(Table newTable, P partition, OffsetContext offsetContext, TableId tableId) Creates and dispatches a schema change event for the given table.private booleancreateDataEventsForTable(P partition) Dispatches the data change events for the records of a single table.protected voiddeduplicateWindow(io.debezium.spi.schema.DataCollectionId dataCollectionId, Object key) protected abstract voidemitWindowClose(P partition, OffsetContext offsetContext) Update high watermark for the incremental snapshot chunkprotected abstract voidemitWindowOpen(P partition, OffsetContext offsetContext) Update 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.getDatabaseName(Object dataCollectionId) Extract the database name from a data collection ID.protected StringgetSignalTableName(String dataCollectionId) private Tableprotected StringgetTableDDL(TableId tableId) private io.debezium.util.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 voidprotected voidpreReadChunk(IncrementalSnapshotContext<T> context) voidprocessSchemaChange(P partition, OffsetContext offsetContext, io.debezium.spi.schema.DataCollectionId dataCollectionId) protected voidreadChunk(P partition, OffsetContext offsetContext) private Tableprotected TablereadSchemaForTable(TableId tableId) Reads the schema for the specified table ID.protected TablerefreshTableSchema(Table table) voidrequestStopSnapshot(P partition, OffsetContext offsetContext, Map<String, Object> additionalData, List<String> dataCollectionIds) voidrereadChunk(P partition, OffsetContext offsetContext) voidresumeSnapshot(P partition, OffsetContext offsetContext) private voidretrieveAndRefreshSchema(TableId tableId, 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) private voidtableScanCompleted(P partition) protected voidvalidateSignalTableConfiguration(List<DataCollection<T>> dataCollections) Validates that signal table configuration is appropriate for the tables being snapshotted.private voidVerifies that table's schema in the database has not changed since it was captured in the previous windowprivate voidwarnAndSkip(P partition, OffsetContext offsetContext, IncrementalSnapshotNotificationService.TableScanCompletionStatus status, String formattedReason, Throwable t) Methods 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
private final io.debezium.util.Clock clock -
databaseSchema
-
progressListener
-
dataListener
-
totalRowsScanned
private long totalRowsScanned -
currentTable
-
dispatcher
protected EventDispatcher<P extends Partition,T extends io.debezium.spi.schema.DataCollectionId> dispatcher -
context
-
jdbcConnection
-
chunkQueryBuilder
-
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, io.debezium.util.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 io.debezium.spi.schema.DataCollectionId> - Throws:
InterruptedException
-
pauseSnapshot
- Specified by:
pauseSnapshotin interfaceIncrementalSnapshotChangeEventSource<P extends Partition,T extends io.debezium.spi.schema.DataCollectionId>
-
resumeSnapshot
- Specified by:
resumeSnapshotin interfaceIncrementalSnapshotChangeEventSource<P extends Partition,T extends io.debezium.spi.schema.DataCollectionId> - Throws:
InterruptedException
-
processSchemaChange
public void processSchemaChange(P partition, OffsetContext offsetContext, io.debezium.spi.schema.DataCollectionId dataCollectionId) throws InterruptedException - Specified by:
processSchemaChangein interfaceIncrementalSnapshotChangeEventSource<P extends Partition,T extends io.debezium.spi.schema.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
protected void deduplicateWindow(io.debezium.spi.schema.DataCollectionId dataCollectionId, Object key) -
emitWindowOpen
protected abstract void emitWindowOpen(P partition, OffsetContext offsetContext) throws SQLException Update low watermark for the incremental snapshot chunk- Throws:
SQLException
-
emitWindowClose
Update high watermark for the incremental snapshot chunk- Throws:
Exception
-
init
- Specified by:
initin interfaceIncrementalSnapshotChangeEventSource<P extends Partition,T extends io.debezium.spi.schema.DataCollectionId>
-
readChunk
- Throws:
InterruptedException
-
isTableInvalid
-
warnAndSkip
private void warnAndSkip(P partition, OffsetContext offsetContext, IncrementalSnapshotNotificationService.TableScanCompletionStatus status, String formattedReason, Throwable t) -
retrieveAndRefreshSchema
private void retrieveAndRefreshSchema(TableId tableId, P partition, OffsetContext offsetContext) throws SQLException, InterruptedException - Throws:
SQLExceptionInterruptedException
-
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 io.debezium.spi.schema.DataCollectionId> - Throws:
InterruptedException
-
validateSignalTableConfiguration
Validates that signal table configuration is appropriate for the tables being snapshotted. For multi-database connectors with a single signal table, warns if tables from different databases are being snapshotted. -
getDatabaseName
Extract the database name from a data collection ID. Default implementation handles TableId, subclasses may override. -
requestStopSnapshot
public void requestStopSnapshot(P partition, OffsetContext offsetContext, Map<String, Object> additionalData, List<String> dataCollectionIds) - Specified by:
requestStopSnapshotin interfaceIncrementalSnapshotChangeEventSource<P extends Partition,T extends io.debezium.spi.schema.DataCollectionId>
-
checkAndProcessStopFlag
-
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.- Throws:
SQLException
-
checkSchemaChanges
- Throws:
SQLException
-
getTable
- Throws:
SQLException
-
incrementTableRowsScanned
-
tableScanCompleted
-
getTableScanLogTimer
private io.debezium.util.Threads.Timer getTableScanLogTimer() -
keyFromRow
-
setContext
-
preIncrementalSnapshotStart
protected void preIncrementalSnapshotStart() -
preReadChunk
-
postReadChunk
-
postIncrementalSnapshotCompleted
protected void postIncrementalSnapshotCompleted() -
refreshTableSchema
- Throws:
SQLException
-
readSchemaForTable
Reads the schema for the specified table ID. This method can be overridden if custom schema retrieval logic is required.- Throws:
SQLException
-
createAndDispatchSchemaChangeEvent
protected void createAndDispatchSchemaChangeEvent(Table newTable, P partition, OffsetContext offsetContext, TableId tableId) throws SQLException Creates and dispatches a schema change event for the given table. This method can be overridden if custom event creation or dispatching is required.- Throws:
SQLException
-
getTableDDL
- Throws:
SQLException
-