Github user pnowojski commented on a diff in the pull request:

    https://github.com/apache/flink/pull/4910#discussion_r147661454
  
    --- Diff: 
flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/sink/TwoPhaseCommitSinkFunction.java
 ---
    @@ -293,26 +330,110 @@ public void 
initializeState(FunctionInitializationContext context) throws Except
                }
                // if in restore we didn't get any userContext or we are 
initializing from scratch
                if (userContext == null) {
    -                   LOG.info("{} - no state to restore", name());
    +                   log.info("{} - no state to restore", name());
     
                        userContext = initializeUserContext();
                }
                this.pendingCommitTransactions.clear();
     
    -           currentTransaction = beginTransaction();
    -           LOG.debug("{} - started new transaction '{}'", name(), 
currentTransaction);
    +           currentTransaction = beginTransaction0();
    +           log.debug("{} - started new transaction '{}'", name(), 
currentTransaction);
    +   }
    +
    +   /**
    +    * This method must be the only place to call {@link 
#beginTransaction()} to ensure that the
    +    * {@link TransactionHolder} is created at the same time.
    +    */
    +   private TransactionHolder<TXN> beginTransaction0() throws Exception {
    +           return new TransactionHolder<>(beginTransaction(), 
clock.millis());
    +   }
    +
    +   /**
    +    * This method must be the only place to call {@link 
#recoverAndCommit(Object)} to ensure that
    +    * the configuration parameters {@link #transactionTimeout} and
    +    * {@link #failureOnCommitAfterTransactionTimeoutDisabled} are 
respected.
    +    */
    +   private void recoverAndCommit(TransactionHolder<TXN> transactionHolder) 
{
    +           try {
    +                   logWarningIfTimeoutAlmostReached(transactionHolder);
    +                   recoverAndCommit(transactionHolder.handle);
    +           } catch (final Exception e) {
    +                   final long elapsedTime = clock.millis() - 
transactionHolder.transactionStartTime;
    +                   if (failureOnCommitAfterTransactionTimeoutDisabled && 
elapsedTime > transactionTimeout) {
    +                           log.error("Error while committing transaction 
{}. " +
    --- End diff --
    
    `"Error while committing transaction {}. Data loss might occurred"` 


---

Reply via email to