Class TwoPhaseCommitSinkFunction<IN,TXN,CONTEXT>
java.lang.Object
org.apache.flink.api.common.functions.AbstractRichFunction
org.apache.flink.streaming.api.functions.sink.legacy.RichSinkFunction<IN>
org.apache.flink.streaming.api.functions.sink.legacy.TwoPhaseCommitSinkFunction<IN,TXN,CONTEXT>
- Type Parameters:
IN- Input type forSinkFunction.TXN- Transaction to store all of the information required to handle a transaction.CONTEXT- Context that will be shared across all invocations for the givenTwoPhaseCommitSinkFunctioninstance. Context is created once
- 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.streaming.api.checkpoint.CheckpointedFunction,org.apache.flink.streaming.api.functions.sink.legacy.SinkFunction<IN>
@Internal
public abstract class TwoPhaseCommitSinkFunction<IN,TXN,CONTEXT>
extends org.apache.flink.streaming.api.functions.sink.legacy.RichSinkFunction<IN>
implements org.apache.flink.streaming.api.checkpoint.CheckpointedFunction, org.apache.flink.api.common.state.CheckpointListener
Deprecated.
This is a recommended base class for all of the
SinkFunction that intend to implement
exactly-once semantic. It does that by implementing two phase commit algorithm on top of the
CheckpointedFunction and CheckpointListener. User should provide custom
TXN (transaction handle) and implement abstract methods handling this transaction handle.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classDeprecated.State POJO class coupling pendingTransaction, context and pendingCommitTransactions.static final classDeprecated.CustomTypeSerializerfor the sink state.static final classDeprecated.Snapshot for theTwoPhaseCommitSinkFunction.StateSerializer.static final classDeprecated.Adds metadata (currently only the start time of the transaction) to the transaction object.Nested classes/interfaces inherited from interface org.apache.flink.streaming.api.functions.sink.legacy.SinkFunction
org.apache.flink.streaming.api.functions.sink.legacy.SinkFunction.Context -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final LinkedHashMap<Long,TwoPhaseCommitSinkFunction.TransactionHolder<TXN>> Deprecated.protected org.apache.flink.api.common.state.ListState<TwoPhaseCommitSinkFunction.State<TXN,CONTEXT>> Deprecated.Deprecated. -
Constructor Summary
ConstructorsConstructorDescriptionTwoPhaseCommitSinkFunction(org.apache.flink.api.common.typeutils.TypeSerializer<TXN> transactionSerializer, org.apache.flink.api.common.typeutils.TypeSerializer<CONTEXT> contextSerializer) Deprecated.Use defaultListStateDescriptorfor internal state serialization. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidDeprecated.Abort a transaction.protected abstract TXNDeprecated.Method that starts a new transaction.voidclose()Deprecated.protected abstract voidDeprecated.Commit a pre-committed transaction.protected TXNDeprecated.protected TwoPhaseCommitSinkFunction<IN,TXN, CONTEXT> enableTransactionTimeoutWarnings(double warningRatio) Deprecated.Enables logging of warnings if a transaction's elapsed time reaches a specified ratio of thetransactionTimeout.final voidfinish()Deprecated.protected voidfinishProcessing(TXN transaction) Deprecated.This method is called at the end of data processing.protected voidfinishRecoveringContext(Collection<TXN> handledTransactions) Deprecated.Callback for subclasses which is called after restoring (each) user context.Deprecated.protected TwoPhaseCommitSinkFunction<IN,TXN, CONTEXT> Deprecated.If called, the sink will only log but not propagate exceptions thrown inrecoverAndCommit(Object)if the transaction is older than a specified transaction timeout.voidinitializeState(org.apache.flink.runtime.state.FunctionInitializationContext context) Deprecated.Deprecated.final voidDeprecated.This should not be implemented by subclasses.final voidDeprecated.protected abstract voidinvoke(TXN transaction, IN value, org.apache.flink.streaming.api.functions.sink.legacy.SinkFunction.Context context) Deprecated.Write value within a transaction.voidnotifyCheckpointAborted(long checkpointId) Deprecated.final voidnotifyCheckpointComplete(long checkpointId) Deprecated.Deprecated.protected abstract voidDeprecated.Pre commit previously created transaction.protected voidrecoverAndAbort(TXN transaction) Deprecated.Abort a transaction that was rejected by a coordinator after a failure.protected voidrecoverAndCommit(TXN transaction) Deprecated.Invoked on recovered transactions after a failure.protected TwoPhaseCommitSinkFunction<IN,TXN, CONTEXT> setTransactionTimeout(long transactionTimeout) Deprecated.Sets the transaction timeout.voidsnapshotState(org.apache.flink.runtime.state.FunctionSnapshotContext context) Deprecated.Methods inherited from class org.apache.flink.api.common.functions.AbstractRichFunction
getIterationRuntimeContext, getRuntimeContext, open, setRuntimeContextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.flink.streaming.api.functions.sink.legacy.SinkFunction
writeWatermark
-
Field Details
-
pendingCommitTransactions
protected final LinkedHashMap<Long,TwoPhaseCommitSinkFunction.TransactionHolder<TXN>> pendingCommitTransactionsDeprecated. -
userContext
Deprecated. -
state
protected transient org.apache.flink.api.common.state.ListState<TwoPhaseCommitSinkFunction.State<TXN,CONTEXT>> stateDeprecated.
-
-
Constructor Details
-
TwoPhaseCommitSinkFunction
public TwoPhaseCommitSinkFunction(org.apache.flink.api.common.typeutils.TypeSerializer<TXN> transactionSerializer, org.apache.flink.api.common.typeutils.TypeSerializer<CONTEXT> contextSerializer) Deprecated.Use defaultListStateDescriptorfor internal state serialization. Helpful utilities for using this constructor areTypeInformation.of(Class),TypeHintandTypeInformation.of(TypeHint). Example:TwoPhaseCommitSinkFunction(TypeInformation.of(new TypeHint<State<TXN, CONTEXT>>() {}));- Parameters:
transactionSerializer-TypeSerializerfor the transaction type of this sinkcontextSerializer-TypeSerializerfor the context type of this sink
-
-
Method Details
-
initializeUserContext
Deprecated. -
getUserContext
Deprecated. -
currentTransaction
Deprecated. -
pendingTransactions
Deprecated. -
invoke
protected abstract void invoke(TXN transaction, IN value, org.apache.flink.streaming.api.functions.sink.legacy.SinkFunction.Context context) throws Exception Deprecated.Write value within a transaction.- Throws:
Exception
-
beginTransaction
Deprecated.Method that starts a new transaction.- Returns:
- newly created transaction.
- Throws:
Exception
-
preCommit
Deprecated.Pre commit previously created transaction. Pre commit must make all of the necessary steps to prepare the transaction for a commit that might happen in the future. After this point the transaction might still be aborted, but underlying implementation must ensure that commit calls on already pre committed transactions will always succeed.Usually implementation involves flushing the data.
- Throws:
Exception
-
commit
Deprecated.Commit a pre-committed transaction. If this method fail, Flink application will be restarted andrecoverAndCommit(Object)will be called again for the same transaction. -
recoverAndCommit
Deprecated.Invoked on recovered transactions after a failure. User implementation must ensure that this call will eventually succeed. If it fails, Flink application will be restarted and it will be invoked again. If it does not succeed eventually, a data loss will occur. Transactions will be recovered in an order in which they were created. -
abort
Deprecated.Abort a transaction. -
recoverAndAbort
Deprecated.Abort a transaction that was rejected by a coordinator after a failure. -
finishRecoveringContext
Deprecated.Callback for subclasses which is called after restoring (each) user context.- Parameters:
handledTransactions- transactions which were already committed or aborted and do not need further handling
-
finishProcessing
Deprecated.This method is called at the end of data processing.The method is expected to flush all remaining buffered data. Exceptions will cause the pipeline to be recognized as failed, because the last data items are not processed properly. You may use this method to flush remaining buffered elements in the state into the current transaction which will be committed in the last checkpoint.
-
invoke
Deprecated.This should not be implemented by subclasses. -
invoke
public final void invoke(IN value, org.apache.flink.streaming.api.functions.sink.legacy.SinkFunction.Context context) throws Exception Deprecated. -
finish
Deprecated. -
notifyCheckpointComplete
Deprecated.- Specified by:
notifyCheckpointCompletein interfaceorg.apache.flink.api.common.state.CheckpointListener- Throws:
Exception
-
notifyCheckpointAborted
public void notifyCheckpointAborted(long checkpointId) Deprecated.- Specified by:
notifyCheckpointAbortedin interfaceorg.apache.flink.api.common.state.CheckpointListener
-
snapshotState
public void snapshotState(org.apache.flink.runtime.state.FunctionSnapshotContext context) throws Exception Deprecated.- Specified by:
snapshotStatein interfaceorg.apache.flink.streaming.api.checkpoint.CheckpointedFunction- Throws:
Exception
-
initializeState
public void initializeState(org.apache.flink.runtime.state.FunctionInitializationContext context) throws Exception Deprecated.- Specified by:
initializeStatein interfaceorg.apache.flink.streaming.api.checkpoint.CheckpointedFunction- Throws:
Exception
-
close
Deprecated.- Specified by:
closein interfaceorg.apache.flink.api.common.functions.RichFunction- Overrides:
closein classorg.apache.flink.api.common.functions.AbstractRichFunction- Throws:
Exception
-
setTransactionTimeout
Deprecated.Sets the transaction timeout. Setting only the transaction timeout has no effect in itself.- Parameters:
transactionTimeout- The transaction timeout in ms.- See Also:
-
ignoreFailuresAfterTransactionTimeout
Deprecated.If called, the sink will only log but not propagate exceptions thrown inrecoverAndCommit(Object)if the transaction is older than a specified transaction timeout. The start time of an transaction is determined bySystem.currentTimeMillis(). By default, failures are propagated. -
enableTransactionTimeoutWarnings
protected TwoPhaseCommitSinkFunction<IN,TXN, enableTransactionTimeoutWarningsCONTEXT> (double warningRatio) Deprecated.Enables logging of warnings if a transaction's elapsed time reaches a specified ratio of thetransactionTimeout. IfwarningRatiois 0, a warning will be always logged when committing the transaction.- Parameters:
warningRatio- A value in the range [0,1].- Returns:
-
Sinkinterface instead.