Package io.debezium.connector.mongodb
Class MongoDbIncrementalSnapshotChangeEventSource<T extends DataCollectionId>
- java.lang.Object
-
- io.debezium.connector.mongodb.MongoDbIncrementalSnapshotChangeEventSource<T>
-
- All Implemented Interfaces:
IncrementalSnapshotChangeEventSource<CollectionId>
@NotThreadSafe public class MongoDbIncrementalSnapshotChangeEventSource<T extends DataCollectionId> extends Object implements IncrementalSnapshotChangeEventSource<CollectionId>
An incremental snapshot change event source that emits events from a MongoDB change stream interleaved with snapshot events.
-
-
Field Summary
Fields Modifier and Type Field Description private static StringAUTHORIZATION_FAILURE_MESSAGEprivate Clockclockprivate MongoDbSchemacollectionSchemaprivate ConnectionContextconnectionContextprivate MongoDbConnectorConfigconnectorConfigprotected IncrementalSnapshotContext<T>contextprivate MongoDbCollectionSchemacurrentCollectionprivate DataChangeEventListenerdataListenerprotected EventDispatcher<CollectionId>dispatcherprivate static StringDOCUMENT_IDprivate static org.slf4j.LoggerLOGGERprivate ConnectionContext.MongoPrimaryprimaryprivate SnapshotProgressListenerprogressListenerprivate ReplicaSetsreplicaSetsprivate CollectionIdsignallingCollectionIdprivate MongoDbTaskContexttaskContextprivate longtotalRowsScannedprotected Map<org.apache.kafka.connect.data.Struct,Object[]>window
-
Constructor Summary
Constructors Constructor Description MongoDbIncrementalSnapshotChangeEventSource(MongoDbConnectorConfig config, MongoDbTaskContext taskContext, ReplicaSets replicaSets, EventDispatcher<CollectionId> dispatcher, MongoDbSchema collectionSchema, Clock clock, SnapshotProgressListener progressListener, DataChangeEventListener dataChangeEventListener)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDataCollectionNamesToSnapshot(List<String> dataCollectionIds, OffsetContext offsetContext)voidcloseWindow(Partition partition, String id, OffsetContext offsetContext)private voidcollectionScanCompleted()private voidcreateDataEventsForDataCollection()Dispatches the data change events for the records of a single table.protected voiddeduplicateWindow(DataCollectionId dataCollectionId, Object key)protected voidemitWindowClose()Update high watermark for the incremental snapshot chunkprotected voidemitWindowOpen()Update low watermark for the incremental snapshot chunkprivate ConnectionContext.MongoPrimaryestablishConnectionToPrimary(ReplicaSet replicaSet)protected ChangeRecordEmittergetChangeRecordEmitter(Partition partition, T dataCollectionId, OffsetContext offsetContext, Object[] row)Returns aChangeRecordEmitterproducing the change records for the given table row.protected StringgetSignalCollectionName(String dataCollectionId)private Threads.TimergetTableScanLogTimer()private voidincrementTableRowsScanned(long rows)voidinit(OffsetContext offsetContext)private Object[]keyFromRow(Object[] row)private voidnextDataCollection()protected voidpostIncrementalSnapshotCompleted()protected voidpostReadChunk(IncrementalSnapshotContext<T> context)protected voidpreReadChunk(IncrementalSnapshotContext<T> context)voidprocessMessage(Partition partition, DataCollectionId dataCollectionId, Object key, OffsetContext offsetContext)protected voidreadChunk()private Object[]readMaximumKey()protected voidsendEvent(Partition partition, EventDispatcher dispatcher, OffsetContext offsetContext, Object[] row)protected voidsendWindowEvents(Partition partition, OffsetContext offsetContext)protected voidsetContext(IncrementalSnapshotContext<T> context)-
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, processTransactionCommittedEvent, processTransactionStartedEvent
-
-
-
-
Field Detail
-
DOCUMENT_ID
private static final String DOCUMENT_ID
- See Also:
- Constant Field Values
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
AUTHORIZATION_FAILURE_MESSAGE
private static final String AUTHORIZATION_FAILURE_MESSAGE
- See Also:
- Constant Field Values
-
connectorConfig
private final MongoDbConnectorConfig connectorConfig
-
clock
private final Clock clock
-
collectionSchema
private final MongoDbSchema collectionSchema
-
progressListener
private final SnapshotProgressListener progressListener
-
dataListener
private final DataChangeEventListener dataListener
-
totalRowsScanned
private long totalRowsScanned
-
replicaSets
private final ReplicaSets replicaSets
-
connectionContext
private final ConnectionContext connectionContext
-
taskContext
private final MongoDbTaskContext taskContext
-
currentCollection
private MongoDbCollectionSchema currentCollection
-
dispatcher
protected EventDispatcher<CollectionId> dispatcher
-
context
protected IncrementalSnapshotContext<T extends DataCollectionId> context
-
primary
private ConnectionContext.MongoPrimary primary
-
signallingCollectionId
private CollectionId signallingCollectionId
-
-
Constructor Detail
-
MongoDbIncrementalSnapshotChangeEventSource
public MongoDbIncrementalSnapshotChangeEventSource(MongoDbConnectorConfig config, MongoDbTaskContext taskContext, ReplicaSets replicaSets, EventDispatcher<CollectionId> dispatcher, MongoDbSchema collectionSchema, 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 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 void emitWindowOpen() throws InterruptedExceptionUpdate low watermark for the incremental snapshot chunk- Throws:
InterruptedException
-
emitWindowClose
protected void emitWindowClose() throws InterruptedExceptionUpdate high watermark for the incremental snapshot chunk- Throws:
InterruptedException
-
init
public void init(OffsetContext offsetContext)
- Specified by:
initin interfaceIncrementalSnapshotChangeEventSource<T extends DataCollectionId>
-
readChunk
protected void readChunk() throws InterruptedException- Throws:
InterruptedException
-
nextDataCollection
private void nextDataCollection()
-
readMaximumKey
private Object[] readMaximumKey() throws InterruptedException
- Throws:
InterruptedException
-
addDataCollectionNamesToSnapshot
public void addDataCollectionNamesToSnapshot(List<String> dataCollectionIds, OffsetContext offsetContext) throws InterruptedException
- Specified by:
addDataCollectionNamesToSnapshotin interfaceIncrementalSnapshotChangeEventSource<T extends DataCollectionId>- Throws:
InterruptedException
-
createDataEventsForDataCollection
private void createDataEventsForDataCollection() throws InterruptedExceptionDispatches the data change events for the records of a single table.- Throws:
InterruptedException
-
incrementTableRowsScanned
private void incrementTableRowsScanned(long rows)
-
collectionScanCompleted
private void collectionScanCompleted()
-
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()
-
processMessage
public void processMessage(Partition partition, DataCollectionId dataCollectionId, Object key, OffsetContext offsetContext) throws InterruptedException
- Specified by:
processMessagein interfaceIncrementalSnapshotChangeEventSource<T extends DataCollectionId>- Throws:
InterruptedException
-
establishConnectionToPrimary
private ConnectionContext.MongoPrimary establishConnectionToPrimary(ReplicaSet replicaSet)
-
-