Package io.debezium.pipeline.source
Class AbstractSnapshotChangeEventSource<O extends OffsetContext>
- java.lang.Object
-
- io.debezium.pipeline.source.AbstractSnapshotChangeEventSource<O>
-
- All Implemented Interfaces:
ChangeEventSource
,SnapshotChangeEventSource<O>
- Direct Known Subclasses:
RelationalSnapshotChangeEventSource
public abstract class AbstractSnapshotChangeEventSource<O extends OffsetContext> extends Object implements SnapshotChangeEventSource<O>
An abstract implementation ofSnapshotChangeEventSource
that all implementations should extend to inherit common functionality.- Author:
- Chris Cranford
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractSnapshotChangeEventSource.SnapshotContext<O extends OffsetContext>
Mutable context which is populated in the course of snapshottingstatic class
AbstractSnapshotChangeEventSource.SnapshottingTask
A configuration describing the task to be performed during snapshotting.-
Nested classes/interfaces inherited from interface io.debezium.pipeline.source.spi.ChangeEventSource
ChangeEventSource.ChangeEventSourceContext
-
-
Field Summary
Fields Modifier and Type Field Description private CommonConnectorConfig
connectorConfig
private static org.slf4j.Logger
LOGGER
private SnapshotProgressListener
snapshotProgressListener
-
Constructor Summary
Constructors Constructor Description AbstractSnapshotChangeEventSource(CommonConnectorConfig connectorConfig, SnapshotProgressListener snapshotProgressListener)
-
Method Summary
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
connectorConfig
private final CommonConnectorConfig connectorConfig
-
snapshotProgressListener
private final SnapshotProgressListener snapshotProgressListener
-
-
Constructor Detail
-
AbstractSnapshotChangeEventSource
public AbstractSnapshotChangeEventSource(CommonConnectorConfig connectorConfig, SnapshotProgressListener snapshotProgressListener)
-
-
Method Detail
-
execute
public SnapshotResult<O> execute(ChangeEventSource.ChangeEventSourceContext context, O previousOffset) throws InterruptedException
Description copied from interface:SnapshotChangeEventSource
Executes 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:
execute
in interfaceSnapshotChangeEventSource<O extends OffsetContext>
- Parameters:
context
- contextual information for this source's executionpreviousOffset
- previous offset restored from Kafka- Returns:
- an indicator to the position at which the snapshot was taken
- Throws:
InterruptedException
- in case the snapshot was aborted before completion
-
determineDataCollectionsToBeSnapshotted
protected <T extends DataCollectionId> Stream<T> determineDataCollectionsToBeSnapshotted(Collection<T> allDataCollections)
-
delaySnapshotIfNeeded
protected void delaySnapshotIfNeeded(ChangeEventSource.ChangeEventSourceContext context) throws InterruptedException
Delays snapshot execution as per theCommonConnectorConfig.SNAPSHOT_DELAY_MS
parameter.- Throws:
InterruptedException
-
doExecute
protected abstract SnapshotResult<O> doExecute(ChangeEventSource.ChangeEventSourceContext context, O previousOffset, AbstractSnapshotChangeEventSource.SnapshotContext<O> snapshotContext, AbstractSnapshotChangeEventSource.SnapshottingTask snapshottingTask) throws Exception
Executes 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.- 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
-
getSnapshottingTask
protected abstract AbstractSnapshotChangeEventSource.SnapshottingTask getSnapshottingTask(O previousOffset)
Returns the snapshotting task based on the previous offset (if available) and the connector's snapshotting mode.
-
prepare
protected abstract AbstractSnapshotChangeEventSource.SnapshotContext<O> prepare(ChangeEventSource.ChangeEventSourceContext changeEventSourceContext) throws Exception
Prepares the taking of a snapshot and returns an initialAbstractSnapshotChangeEventSource.SnapshotContext
.- Throws:
Exception
-
complete
protected void complete(AbstractSnapshotChangeEventSource.SnapshotContext<O> snapshotContext)
Completes the snapshot, doing any required clean-up (resource disposal etc.). The snapshot may have run successfully or have been aborted at this point.- Parameters:
snapshotContext
- snapshot context
-
-