Class DebeziumSourceFunction<T>
- java.lang.Object
-
- org.apache.flink.api.common.functions.AbstractRichFunction
-
- org.apache.flink.streaming.api.functions.source.RichSourceFunction<T>
-
- org.apache.flink.cdc.debezium.DebeziumSourceFunction<T>
-
- All Implemented Interfaces:
Serializable,org.apache.flink.api.common.functions.Function,org.apache.flink.api.common.functions.RichFunction,org.apache.flink.api.common.state.CheckpointListener,org.apache.flink.api.java.typeutils.ResultTypeQueryable<T>,org.apache.flink.streaming.api.checkpoint.CheckpointedFunction,org.apache.flink.streaming.api.functions.source.SourceFunction<T>
@PublicEvolving public class DebeziumSourceFunction<T> extends org.apache.flink.streaming.api.functions.source.RichSourceFunction<T> implements org.apache.flink.streaming.api.checkpoint.CheckpointedFunction, org.apache.flink.api.common.state.CheckpointListener, org.apache.flink.api.java.typeutils.ResultTypeQueryable<T>
TheDebeziumSourceFunctionis a streaming data source that pulls captured change data from databases into Flink.There are two workers during the runtime. One worker periodically pulls records from the database and pushes the records into the
Handover. The other worker consumes the records from theHandoverand convert the records to the data in Flink style. The reason why don't use one workers is because debezium has different behaviours in snapshot phase and streaming phase.Here we use the
Handoveras the buffer to submit data from the producer to the consumer. Because the two threads don't communicate to each other directly, the error reporting also relies onHandover. When the engine gets errors, the engine uses theDebeziumEngine.CompletionCallbackto report errors to theHandoverand wakes up the consumer to check the error. However, the source function just closes the engine and wakes up the producer if the error is from the Flink side.If the execution is canceled or finish(only snapshot phase), the exit logic is as same as the logic in the error reporting.
The source function participates in checkpointing and guarantees that no data is lost during a failure, and that the computation processes elements "exactly once".
Note: currently, the source function can't run in multiple parallel instances.
Please refer to Debezium's documentation for the available configuration properties: https://debezium.io/documentation/reference/1.9/development/engine.html#engine-properties
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.flink.streaming.api.functions.source.SourceFunction
org.apache.flink.streaming.api.functions.source.SourceFunction.SourceContext<T extends Object>
-
-
Field Summary
Fields Modifier and Type Field Description static StringHISTORY_RECORDS_STATE_NAMEState name of the consumer's history records state.static StringLEGACY_IMPLEMENTATION_KEYThe configuration represents the Debezium MySQL Connector uses the legacy implementation or not.static StringLEGACY_IMPLEMENTATION_VALUEThe configuration value represents legacy implementation.protected static org.slf4j.LoggerLOGstatic intMAX_NUM_PENDING_CHECKPOINTSThe maximum number of pending non-committed checkpoints to track, to avoid memory leaks.static StringOFFSETS_STATE_NAMEState name of the consumer's partition offset states.
-
Constructor Summary
Constructors Constructor Description DebeziumSourceFunction(DebeziumDeserializationSchema<T> deserializer, Properties properties, DebeziumOffset specificOffset, Validator validator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel()voidclose()booleangetDebeziumStarted()StringgetEngineInstanceName()HandovergetHandover()org.apache.commons.collections.map.LinkedMapgetPendingOffsetsToCommit()org.apache.flink.api.common.typeinfo.TypeInformation<T>getProducedType()voidinitializeState(org.apache.flink.runtime.state.FunctionInitializationContext context)voidnotifyCheckpointComplete(long checkpointId)voidopen(org.apache.flink.configuration.Configuration parameters)voidrun(org.apache.flink.streaming.api.functions.source.SourceFunction.SourceContext<T> sourceContext)voidsnapshotState(org.apache.flink.runtime.state.FunctionSnapshotContext functionSnapshotContext)-
Methods inherited from class org.apache.flink.api.common.functions.AbstractRichFunction
getIterationRuntimeContext, getRuntimeContext, setRuntimeContext
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Field Detail
-
LOG
protected static final org.slf4j.Logger LOG
-
OFFSETS_STATE_NAME
public static final String OFFSETS_STATE_NAME
State name of the consumer's partition offset states.- See Also:
- Constant Field Values
-
HISTORY_RECORDS_STATE_NAME
public static final String HISTORY_RECORDS_STATE_NAME
State name of the consumer's history records state.- See Also:
- Constant Field Values
-
MAX_NUM_PENDING_CHECKPOINTS
public static final int MAX_NUM_PENDING_CHECKPOINTS
The maximum number of pending non-committed checkpoints to track, to avoid memory leaks.- See Also:
- Constant Field Values
-
LEGACY_IMPLEMENTATION_KEY
public static final String LEGACY_IMPLEMENTATION_KEY
The configuration represents the Debezium MySQL Connector uses the legacy implementation or not.- See Also:
- Constant Field Values
-
LEGACY_IMPLEMENTATION_VALUE
public static final String LEGACY_IMPLEMENTATION_VALUE
The configuration value represents legacy implementation.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DebeziumSourceFunction
public DebeziumSourceFunction(DebeziumDeserializationSchema<T> deserializer, Properties properties, @Nullable DebeziumOffset specificOffset, Validator validator)
-
-
Method Detail
-
open
public void open(org.apache.flink.configuration.Configuration parameters) throws Exception- Specified by:
openin interfaceorg.apache.flink.api.common.functions.RichFunction- Overrides:
openin classorg.apache.flink.api.common.functions.AbstractRichFunction- Throws:
Exception
-
initializeState
public void initializeState(org.apache.flink.runtime.state.FunctionInitializationContext context) throws Exception- Specified by:
initializeStatein interfaceorg.apache.flink.streaming.api.checkpoint.CheckpointedFunction- Throws:
Exception
-
snapshotState
public void snapshotState(org.apache.flink.runtime.state.FunctionSnapshotContext functionSnapshotContext) throws Exception- Specified by:
snapshotStatein interfaceorg.apache.flink.streaming.api.checkpoint.CheckpointedFunction- Throws:
Exception
-
run
public void run(org.apache.flink.streaming.api.functions.source.SourceFunction.SourceContext<T> sourceContext) throws Exception
-
notifyCheckpointComplete
public void notifyCheckpointComplete(long checkpointId)
- Specified by:
notifyCheckpointCompletein interfaceorg.apache.flink.api.common.state.CheckpointListener
-
cancel
public void cancel()
- Specified by:
cancelin interfaceorg.apache.flink.streaming.api.functions.source.SourceFunction<T>
-
close
public void close() throws Exception- Specified by:
closein interfaceorg.apache.flink.api.common.functions.RichFunction- Overrides:
closein classorg.apache.flink.api.common.functions.AbstractRichFunction- Throws:
Exception
-
getProducedType
public org.apache.flink.api.common.typeinfo.TypeInformation<T> getProducedType()
- Specified by:
getProducedTypein interfaceorg.apache.flink.api.java.typeutils.ResultTypeQueryable<T>
-
getPendingOffsetsToCommit
@VisibleForTesting public org.apache.commons.collections.map.LinkedMap getPendingOffsetsToCommit()
-
getDebeziumStarted
@VisibleForTesting public boolean getDebeziumStarted()
-
getEngineInstanceName
@VisibleForTesting public String getEngineInstanceName()
-
getHandover
@VisibleForTesting public Handover getHandover()
-
-