IN - Input type for SinkFunction.TXN - Transaction to store all of the information required to handle a transaction.CONTEXT - Context that will be shared across all invocations for the given TwoPhaseCommitSinkFunction instance. Context is created onceSink interface instead.@Deprecated @PublicEvolving public abstract class TwoPhaseCommitSinkFunction<IN,TXN,CONTEXT> extends RichSinkFunction<IN> implements CheckpointedFunction, org.apache.flink.api.common.state.CheckpointListener
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.| 限定符和类型 | 类和说明 |
|---|---|
static class |
TwoPhaseCommitSinkFunction.State<TXN,CONTEXT>
已过时。
State POJO class coupling pendingTransaction, context and pendingCommitTransactions.
|
static class |
TwoPhaseCommitSinkFunction.StateSerializer<TXN,CONTEXT>
已过时。
Custom
TypeSerializer for the sink state. |
static class |
TwoPhaseCommitSinkFunction.StateSerializerSnapshot<TXN,CONTEXT>
已过时。
Snapshot for the
TwoPhaseCommitSinkFunction.StateSerializer. |
static class |
TwoPhaseCommitSinkFunction.TransactionHolder<TXN>
已过时。
Adds metadata (currently only the start time of the transaction) to the transaction object.
|
SinkFunction.Context| 限定符和类型 | 字段和说明 |
|---|---|
protected LinkedHashMap<Long,TwoPhaseCommitSinkFunction.TransactionHolder<TXN>> |
pendingCommitTransactions
已过时。
|
protected org.apache.flink.api.common.state.ListState<TwoPhaseCommitSinkFunction.State<TXN,CONTEXT>> |
state
已过时。
|
protected Optional<CONTEXT> |
userContext
已过时。
|
| 构造器和说明 |
|---|
TwoPhaseCommitSinkFunction(org.apache.flink.api.common.typeutils.TypeSerializer<TXN> transactionSerializer,
org.apache.flink.api.common.typeutils.TypeSerializer<CONTEXT> contextSerializer)
已过时。
Use default
ListStateDescriptor for internal state serialization. |
| 限定符和类型 | 方法和说明 |
|---|---|
protected abstract void |
abort(TXN transaction)
已过时。
Abort a transaction.
|
protected abstract TXN |
beginTransaction()
已过时。
Method that starts a new transaction.
|
void |
close()
已过时。
|
protected abstract void |
commit(TXN transaction)
已过时。
Commit a pre-committed transaction.
|
protected TXN |
currentTransaction()
已过时。
|
protected TwoPhaseCommitSinkFunction<IN,TXN,CONTEXT> |
enableTransactionTimeoutWarnings(double warningRatio)
已过时。
Enables logging of warnings if a transaction's elapsed time reaches a specified ratio of the
transactionTimeout. |
void |
finish()
已过时。
This method is called at the end of data processing.
|
protected void |
finishProcessing(TXN transaction)
已过时。
This method is called at the end of data processing.
|
protected void |
finishRecoveringContext(Collection<TXN> handledTransactions)
已过时。
Callback for subclasses which is called after restoring (each) user context.
|
protected Optional<CONTEXT> |
getUserContext()
已过时。
|
protected TwoPhaseCommitSinkFunction<IN,TXN,CONTEXT> |
ignoreFailuresAfterTransactionTimeout()
已过时。
If called, the sink will only log but not propagate exceptions thrown in
recoverAndCommit(Object) if the transaction is older than a specified transaction timeout. |
void |
initializeState(org.apache.flink.runtime.state.FunctionInitializationContext context)
已过时。
This method is called when the parallel function instance is created during distributed
execution.
|
protected Optional<CONTEXT> |
initializeUserContext()
已过时。
|
void |
invoke(IN value)
已过时。
This should not be implemented by subclasses.
|
void |
invoke(IN value,
SinkFunction.Context context)
已过时。
Writes the given value to the sink.
|
protected abstract void |
invoke(TXN transaction,
IN value,
SinkFunction.Context context)
已过时。
Write value within a transaction.
|
void |
notifyCheckpointAborted(long checkpointId)
已过时。
|
void |
notifyCheckpointComplete(long checkpointId)
已过时。
|
protected Stream<Map.Entry<Long,TXN>> |
pendingTransactions()
已过时。
|
protected abstract void |
preCommit(TXN transaction)
已过时。
Pre commit previously created transaction.
|
protected void |
recoverAndAbort(TXN transaction)
已过时。
Abort a transaction that was rejected by a coordinator after a failure.
|
protected void |
recoverAndCommit(TXN transaction)
已过时。
Invoked on recovered transactions after a failure.
|
protected TwoPhaseCommitSinkFunction<IN,TXN,CONTEXT> |
setTransactionTimeout(long transactionTimeout)
已过时。
Sets the transaction timeout.
|
void |
snapshotState(org.apache.flink.runtime.state.FunctionSnapshotContext context)
已过时。
This method is called when a snapshot for a checkpoint is requested.
|
getIterationRuntimeContext, getRuntimeContext, open, setRuntimeContextclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitwriteWatermarkprotected final LinkedHashMap<Long,TwoPhaseCommitSinkFunction.TransactionHolder<TXN>> pendingCommitTransactions
protected transient org.apache.flink.api.common.state.ListState<TwoPhaseCommitSinkFunction.State<TXN,CONTEXT>> state
public TwoPhaseCommitSinkFunction(org.apache.flink.api.common.typeutils.TypeSerializer<TXN> transactionSerializer, org.apache.flink.api.common.typeutils.TypeSerializer<CONTEXT> contextSerializer)
ListStateDescriptor for internal state serialization. Helpful utilities
for using this constructor are TypeInformation.of(Class), TypeHint and TypeInformation.of(TypeHint).
Example:
TwoPhaseCommitSinkFunction(TypeInformation.of(new TypeHint<State<TXN, CONTEXT>>() {}));
transactionSerializer - TypeSerializer for the transaction type of this sinkcontextSerializer - TypeSerializer for the context type of this sinkprotected abstract void invoke(TXN transaction, IN value, SinkFunction.Context context) throws Exception
Exceptionprotected abstract TXN beginTransaction() throws Exception
Exceptionprotected abstract void preCommit(TXN transaction) throws Exception
Usually implementation involves flushing the data.
Exceptionprotected abstract void commit(TXN transaction)
recoverAndCommit(Object) will be called again for the
same transaction.protected void recoverAndCommit(TXN transaction)
protected abstract void abort(TXN transaction)
protected void recoverAndAbort(TXN transaction)
protected void finishRecoveringContext(Collection<TXN> handledTransactions)
handledTransactions - transactions which were already committed or aborted and do not
need further handlingprotected void finishProcessing(@Nullable TXN transaction)
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.
public final void invoke(IN value) throws Exception
invoke 在接口中 SinkFunction<IN>Exceptionpublic final void invoke(IN value, SinkFunction.Context context) throws Exception
SinkFunctionYou have to override this method when implementing a SinkFunction, this is a
default method for backward compatibility with the old-style method only.
invoke 在接口中 SinkFunction<IN>value - The input record.context - Additional context about the input record.Exception - This method may throw exceptions. Throwing an exception will cause the
operation to fail and may trigger recovery.public final void finish()
throws Exception
SinkFunctionThe 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 transactions which you can commit in the last checkpoint.
NOTE:This method does not need to close any resources. You should release external
resources in the AbstractRichFunction.close() method.
finish 在接口中 SinkFunction<IN>Exception - This method may throw exceptions. Throwing an exception will cause the
operation to fail and may trigger recovery.public final void notifyCheckpointComplete(long checkpointId)
throws Exception
notifyCheckpointComplete 在接口中 org.apache.flink.api.common.state.CheckpointListenerExceptionpublic void notifyCheckpointAborted(long checkpointId)
notifyCheckpointAborted 在接口中 org.apache.flink.api.common.state.CheckpointListenerpublic void snapshotState(org.apache.flink.runtime.state.FunctionSnapshotContext context)
throws Exception
CheckpointedFunctionFunctionInitializationContext when the Function was initialized, or offered now by FunctionSnapshotContext itself.snapshotState 在接口中 CheckpointedFunctioncontext - the context for drawing a snapshot of the operatorException - Thrown, if state could not be created ot restored.public void initializeState(org.apache.flink.runtime.state.FunctionInitializationContext context)
throws Exception
CheckpointedFunctioninitializeState 在接口中 CheckpointedFunctioncontext - the context for initializing the operatorException - Thrown, if state could not be created ot restored.public void close()
throws Exception
close 在接口中 org.apache.flink.api.common.functions.RichFunctionclose 在类中 org.apache.flink.api.common.functions.AbstractRichFunctionExceptionprotected TwoPhaseCommitSinkFunction<IN,TXN,CONTEXT> setTransactionTimeout(long transactionTimeout)
transactionTimeout - The transaction timeout in ms.ignoreFailuresAfterTransactionTimeout(),
enableTransactionTimeoutWarnings(double)protected TwoPhaseCommitSinkFunction<IN,TXN,CONTEXT> ignoreFailuresAfterTransactionTimeout()
recoverAndCommit(Object) if the transaction is older than a specified transaction timeout.
The start time of an transaction is determined by System.currentTimeMillis(). By
default, failures are propagated.protected TwoPhaseCommitSinkFunction<IN,TXN,CONTEXT> enableTransactionTimeoutWarnings(double warningRatio)
transactionTimeout. If warningRatio is 0, a warning will be always
logged when committing the transaction.warningRatio - A value in the range [0,1].Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.