Package io.debezium.connector.common
Class BaseSourceTask<P extends Partition,O extends OffsetContext>
java.lang.Object
org.apache.kafka.connect.source.SourceTask
io.debezium.connector.common.BaseSourceTask<P,O>
- All Implemented Interfaces:
org.apache.kafka.connect.connector.Task
public abstract class BaseSourceTask<P extends Partition,O extends OffsetContext>
extends org.apache.kafka.connect.source.SourceTask
Base class for Debezium's CDC
SourceTask implementations. Provides functionality common to all connectors,
such as validation of the configuration.- Author:
- Gunnar Morling
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.kafka.connect.source.SourceTask
org.apache.kafka.connect.source.SourceTask.TransactionBoundary -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ServiceLoader<SignalChannelReader> private CdcSourceTaskContext<? extends CommonConnectorConfig> private final io.debezium.util.Clockprivate io.debezium.config.Configurationprotected ChangeEventSourceCoordinator<P, O> The change event source coordinator for those connectors adhering to the new framework structure,nullfor legacy-style connectors.private static final DurationThe latest offsets that have been acknowledged by the Kafka producer.private static final org.slf4j.Loggerprivate static final Durationprivate final List<NotificationChannel> private booleanA flag to record whether the offsets stored in the offset store are loaded for the first time.private final io.debezium.util.ElapsedTimeStrategyprivate intprivate Instantprivate io.debezium.util.ElapsedTimeStrategyprivate Durationprotected final AtomicBooleanprivate List<SignalChannelReader> private final AtomicReference<io.debezium.connector.common.DebeziumTaskState> private final ReentrantLockUsed to ensure that start(), stop() and commitRecord() calls are serialized.Fields inherited from class org.apache.kafka.connect.source.SourceTask
context, TRANSACTION_BOUNDARY_CONFIG -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcommit()voidcommitRecord(org.apache.kafka.connect.source.SourceRecord record, org.apache.kafka.clients.producer.RecordMetadata metadata) protected abstract Stringprotected booleancontainsChangeDataMessages(List<org.apache.kafka.connect.source.SourceRecord> records) protected abstract List<org.apache.kafka.connect.source.SourceRecord> doPoll()Returns the next batch of source records, if any are available.protected abstract voiddoStop()protected abstract Iterable<io.debezium.config.Field> Returns all configurationFieldsupported by this source task.Returns the available signal channels.Optional<? extends SignalChannelWriter> Returns the first available signal channel writerprotected abstract Optional<ErrorHandler> getMaskedConfigurationMap(Map<String, String> props) getPreviousOffsets(Partition.Provider<P> provider, OffsetContext.Loader<O> loader) Loads the connector's persistent offsets (if present) via the given loader.io.debezium.connector.common.DebeziumTaskStatebooleanisLogPositionAvailable(LogPositionValidator logPositionValidator, Partition partition, OffsetContext offsetContext, CommonConnectorConfig config) protected voidlogStatistics(List<org.apache.kafka.connect.source.SourceRecord> records) voidfinal List<org.apache.kafka.connect.source.SourceRecord> poll()abstract CdcSourceTaskContext<? extends CommonConnectorConfig> preStart(io.debezium.config.Configuration config) protected voidregisterServiceProviders(ServiceRegistry serviceRegistry) protected voidresetErrorHandlerRetriesIfNeeded(List<org.apache.kafka.connect.source.SourceRecord> records) Should be called to reset the error handler's retry counter upon a successful poll or when known that the connector task has recovered from a previous failure state.private voidsetTaskState(io.debezium.connector.common.DebeziumTaskState newState) Sets the new state for the task.protected abstract ChangeEventSourceCoordinator<P, O> start(io.debezium.config.Configuration config) Called when starting this source task.final voidprivate booleanStarts this connector in case it has been stopped after a retriable error, and the backoff period has passed.final voidstop()private voidstop(boolean restart) private voidupdateLastOffset(Map<String, ?> partition, Map<String, ?> lastOffset) protected voidvalidateSchemaHistory(CommonConnectorConfig config, LogPositionValidator logPositionValidator, Offsets<P, O> previousOffsets, DatabaseSchema schema, io.debezium.spi.snapshot.Snapshotter snapshotter) protected io.debezium.config.ConfigurationwithMaskedSensitiveOptions(io.debezium.config.Configuration config) Methods inherited from class org.apache.kafka.connect.source.SourceTask
initializeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.kafka.connect.connector.Task
version
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
INITIAL_POLL_PERIOD_IN_MILLIS
-
MAX_POLL_PERIOD_IN_MILLIS
-
config
private io.debezium.config.Configuration config -
signalChannels
-
cdcSourceTaskContext
-
state
-
stateLock
Used to ensure that start(), stop() and commitRecord() calls are serialized. -
restartDelay
private volatile io.debezium.util.ElapsedTimeStrategy restartDelay -
coordinator
The change event source coordinator for those connectors adhering to the new framework structure,nullfor legacy-style connectors. -
lastOffsets
The latest offsets that have been acknowledged by the Kafka producer. Will be acknowledged with the source database incommit()(which may be a no-op depending on the connector). -
retriableRestartWait
-
pollOutputDelay
private final io.debezium.util.ElapsedTimeStrategy pollOutputDelay -
clock
private final io.debezium.util.Clock clock -
previousOutputInstant
-
previousOutputBatchSize
private int previousOutputBatchSize -
shouldPerformCommit
-
availableSignalChannels
-
notificationChannels
-
offsetLoadedInPast
private boolean offsetLoadedInPastA flag to record whether the offsets stored in the offset store are loaded for the first time. This is typically used to reduce logging in case a connector like PostgreSQL reads offsets not only on connector startup but repeatedly during execution time too.
-
-
Constructor Details
-
BaseSourceTask
protected BaseSourceTask()
-
-
Method Details
-
validateSchemaHistory
protected void validateSchemaHistory(CommonConnectorConfig config, LogPositionValidator logPositionValidator, Offsets<P, O> previousOffsets, DatabaseSchema schema, io.debezium.spi.snapshot.Snapshotter snapshotter) -
isLogPositionAvailable
public boolean isLogPositionAvailable(LogPositionValidator logPositionValidator, Partition partition, OffsetContext offsetContext, CommonConnectorConfig config) -
preStart
public abstract CdcSourceTaskContext<? extends CommonConnectorConfig> preStart(io.debezium.config.Configuration config) -
start
- Specified by:
startin interfaceorg.apache.kafka.connect.connector.Task- Specified by:
startin classorg.apache.kafka.connect.source.SourceTask
-
getAvailableSignalChannels
Returns the available signal channels.The signal channels are loaded using the
ServiceLoadermechanism and cached for the lifetime of the task.- Returns:
- list of loaded signal channels
-
getAvailableSignalChannelWriter
Returns the first available signal channel writer- Returns:
- the first available signal channel writer empty optional if not available
-
withMaskedSensitiveOptions
protected io.debezium.config.Configuration withMaskedSensitiveOptions(io.debezium.config.Configuration config) -
getMaskedConfigurationMap
-
start
Called when starting this source task. This method can throw aRetriableExceptionto indicate that the task should attempt to retry the start later.- Parameters:
config- the task configuration; implementations should wrap it in a dedicated implementation ofCommonConnectorConfigand work with typed access to configuration properties that way
-
connectorName
-
poll
- Specified by:
pollin classorg.apache.kafka.connect.source.SourceTask- Throws:
InterruptedException
-
logStatistics
-
updateLastOffset
-
resetErrorHandlerRetriesIfNeeded
protected void resetErrorHandlerRetriesIfNeeded(List<org.apache.kafka.connect.source.SourceRecord> records) Should be called to reset the error handler's retry counter upon a successful poll or when known that the connector task has recovered from a previous failure state. -
containsChangeDataMessages
protected boolean containsChangeDataMessages(List<org.apache.kafka.connect.source.SourceRecord> records) -
doPoll
protected abstract List<org.apache.kafka.connect.source.SourceRecord> doPoll() throws InterruptedExceptionReturns the next batch of source records, if any are available.- Throws:
InterruptedException
-
getErrorHandler
-
startIfNeededAndPossible
Starts this connector in case it has been stopped after a retriable error, and the backoff period has passed.- Throws:
InterruptedException
-
stop
public final void stop()- Specified by:
stopin interfaceorg.apache.kafka.connect.connector.Task- Specified by:
stopin classorg.apache.kafka.connect.source.SourceTask
-
stop
private void stop(boolean restart) -
doStop
protected abstract void doStop() -
commitRecord
public void commitRecord(org.apache.kafka.connect.source.SourceRecord record, org.apache.kafka.clients.producer.RecordMetadata metadata) throws InterruptedException - Overrides:
commitRecordin classorg.apache.kafka.connect.source.SourceTask- Throws:
InterruptedException
-
commit
- Overrides:
commitin classorg.apache.kafka.connect.source.SourceTask- Throws:
InterruptedException
-
performCommit
public void performCommit() -
getAllConfigurationFields
Returns all configurationFieldsupported by this source task. -
getPreviousOffsets
protected Offsets<P,O> getPreviousOffsets(Partition.Provider<P> provider, OffsetContext.Loader<O> loader) Loads the connector's persistent offsets (if present) via the given loader. -
setTaskState
private void setTaskState(io.debezium.connector.common.DebeziumTaskState newState) Sets the new state for the task. The caller must be holdingstateLocklock.- Parameters:
newState-
-
getTaskState
@VisibleForTesting public io.debezium.connector.common.DebeziumTaskState getTaskState() -
getNotificationChannels
-
registerServiceProviders
-