Drive beforeCompletion against sync objects registered with
this transaction.
545879
protected boolean prePrepare() {
        if (tc.isEntryEnabled())
            Tr.entry(tc, "prePrepare");

        //
        // Cancel timeout prior to completion phase
        //
        cancelAlarms();

        //
        // Inform the Synchronisations we are about to complete
        //
        if (!_rollbackOnly) {
            if (_syncs != null) {
                _syncs.distributeBefore();
            }
        }

        if (tc.isEntryEnabled())
            Tr.exit(tc, "prePrepare", !_rollbackOnly);
        return !_rollbackOnly;
    }
788683
public synchronized void removeMPReadTransactions() {
        TransactionTask  task = m_backlog.peekFirst();
        while (task != null && task.getTransactionState().isReadOnly()) {
            task.getTransactionState().setDone();
            flush(task.getTxnId());
            task = m_backlog.peekFirst();
        }
    }
36782
@Override
    public void afterCompletion(int status) {
        if (status == Status.STATUS_COMMITTED) {
            Boolean previous = persistentExecutor.inMemoryTaskIds.put(taskId, Boolean.TRUE);
            if (previous == null) {
                long delay = expectedExecTime - new Date().getTime();
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                    Tr.debug(this, tc, "Schedule " + taskId + " for " + delay + "ms from now");
                persistentExecutor.scheduledExecutor.schedule(this, delay, TimeUnit.MILLISECONDS);
            } else {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                    Tr.debug(this, tc, "Found task " + taskId + " already scheduled");
            }
        }
    }
767867
void afterCompletion(Task task) {
        boolean delayable = schedule(task);
        if (shouldDrainBuffers(delayable)) {
            tryToDrainBuffers(AMORTIZED_DRAIN_THRESHOLD);
        }
        notifyListener();
    }
706399
public final synchronized void notifyCompletion() {
        if (tc.isEntryEnabled())
            Tr.entry(tc, "notifyCompletion", "finishCount=" + _finishCount);

        if (--_finishCount < 0) {
            // may need to make final state transition here ?
            try {
                switch (_status.getState()) {
                    case TransactionState.STATE_COMMITTING:
                    case TransactionState.STATE_HEURISTIC_ON_COMMIT:
                        _status.setState(TransactionState.STATE_COMMITTED);
                        break;
                    case TransactionState.STATE_ROLLING_BACK:
                    case TransactionState.STATE_HEURISTIC_ON_ROLLBACK:
                        _status.setState(TransactionState.STATE_ROLLED_BACK);
                        break;

                    // one phase commit that resulted in retries ...
                    case TransactionState.STATE_PREPARING:
                    case TransactionState.STATE_COMMITTING_ONE_PHASE:
                        _status.setState(TransactionState.STATE_COMMITTED);
                } // end switch
            } catch (SystemException se) {
                FFDCFilter.processException(se, "com.ibm.tx.jta.TransactionImpl.notifyCompletion", "2416", this);
                if (tc.isDebugEnabled())
                    Tr.debug(tc, "SystemException setting state during completion processing", se);
                // swallow this exception ... we're called in finally blocks!
            } finally {
                forgetTransaction(true);
            }
        } // end if
        if (tc.isEntryEnabled())
            Tr.exit(tc, "notifyCompletion");

    }
1331936
@BeforeClass
    public static void beforeSuite() throws Exception {
        // Delete the Derby-only database that is used by the persistent scheduled executor
        Machine machine = server.getMachine();
        String installRoot = server.getInstallRoot();
        LibertyFileManager.deleteLibertyDirectoryAndContents(machine, installRoot + "/usr/shared/resources/data/lockdb");
    }
1007089
def before_processing(eng, objects):
        """"""
        super(InvenioProcessingFactory, InvenioProcessingFactory)\
            .before_processing(eng, objects)
        eng.save(WorkflowStatus.RUNNING)
        db.session.commit()
1033959
public void distributeBefore()
    {
        if (tc.isEntryEnabled()) Tr.entry(tc, "distributeBefore", this);
        boolean setRollback = false;

        try
        {
            coreDistributeBefore();
        }
        catch (Throwable exc)
        {
            // No FFDC Code Needed.
            Tr.error(tc, "WTRN0074_SYNCHRONIZATION_EXCEPTION", new Object[] {"before_completion", exc});
            // PK19059 starts here
            _tran.setOriginalException(exc);
            // PK19059 ends here
            setRollback = true;           
        }

        // Finally issue the RRS syncs - z/OS always issues these even if RBO has occurred
        // during previous syncs.  Need to check with Matt if we need to do these even if the
        // overall transaction is set to RBO as we bypass distributeBefore in this case.
        final List RRSsyncs = _syncs[SYNC_TIER_RRS];
                
        if (RRSsyncs != null)
        {       
            for (int j = 0; j < RRSsyncs.size(); j++ )  // d162354 array could grow
            {
                final Synchronization sync = (Synchronization)RRSsyncs.get(j);
       
                if (tc.isEventEnabled()) Tr.event(tc, "driving RRS before sync[" + j + "]", Util.identity(sync));

                try
                {
                    sync.beforeCompletion();
                }
                catch (Throwable exc)
                {
                    // No FFDC Code Needed.
                    Tr.error(tc, "WTRN0074_SYNCHRONIZATION_EXCEPTION", new Object[] {"before_completion", exc});
                    setRollback = true;           
                }      
            }                

            // If RRS syncs, one may be DB2 type 2, so issue thread switch
            // NativeJDBCDriverHelper.threadSwitch();              /* @367977A*/
        }

        //----------------------------------------------------------
        // If we've encountered an error, try to set rollback only
        //----------------------------------------------------------
        if (setRollback && _tran != null)
        {
            try
            {
                _tran.setRollbackOnly();
            }
            catch (Exception ex)
            {
                if (tc.isDebugEnabled()) Tr.debug(tc, "setRollbackOnly raised exception", ex);
            }
        }

        if (tc.isEntryEnabled()) Tr.exit(tc, "distributeBefore");
    }
553527
def _pre_tasks(self):
        
        if self.flushdb:
            management.call_command('flush', verbosity=0, interactive=False)
            logger.info('Flushed database')
1075519
private void waitForMoveCompletion() {
    boolean shouldWait;
    int waitedIterations = 0;
    do {
      shouldWait = false;
      for (BalancerDatanode target : plan.targets) {
        if (!target.isPendingQEmpty()) {
          shouldWait = true;
        }
      }
      if (shouldWait) {
        try {
          if (waitedIterations > MAX_WAIT_ITERATIONS) {
            for (BalancerDatanode target : plan.targets) {
              target.killPending();
            }
            continue;
          }
          waitedIterations++;
          Thread.sleep(blockMoveWaitTime);
        } catch (InterruptedException ignored) {
        }
      }
    } while (shouldWait);
  }
18416
public void sync() {

        if (isClosed) {
            return;
        }

        synchronized (fileStreamOut) {
            if (needsSync) {
                if (busyWriting) {
                    forceSync = true;

                    return;
                }

                try {
                    fileStreamOut.flush();
                    outDescriptor.sync();

                    syncCount++;
                } catch (IOException e) {
                    Error.printSystemOut("flush() or sync() error: "
                                         + e.toString());
                }

                needsSync = false;
                forceSync = false;
            }
        }
    }
1323985
@Override
    public void batchPrecommit(TransactionCommon currentTran)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "batchPrecommit", currentTran);
        try
        {
            persistCompletedPrefix(currentTran);
        } catch (SIResourceException e)
        {
            //FFDC
            FFDCFilter.processException(
                                        e,
                                        "com.ibm.ws.sib.processor.gd.GuaranteedTargetStream.batchPrecommit",
                                        "1:1911:1.110",
                                        this);

            SibTr.exception(tc, e);

            //TODO don't know what to do here - rethrow?!
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "batchPrecommit");
    }
346825
@Override
    public void beforeCompletion() {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) { 
            Tr.entry(this, tc, "beforeCompletion");
            Tr.exit(this, tc, "beforeCompletion");
        }
    }
975986
def finalize(self):
        
        if self.finalized:
            self.history.warning("Calling finalize on an already finalized flow.")
            return 1

        self.history.info("Calling flow.finalize.")
        self.finalized = True

        if self.has_db:
            self.history.info("Saving results in database.")
            try:
                self.flow.db_insert()
                self.finalized = True
            except Exception:
                 logger.critical("MongoDb insertion failed.")
                 return 2

        # Here we remove the big output files if we have the garbage collector
        # and the policy is set to "flow."
        if self.gc is not None and self.gc.policy == "flow":
            self.history.info("gc.policy set to flow. Will clean task output files.")
            for task in self.iflat_tasks():
                task.clean_output_files()

        return 0
823973
private void onCachesCollected() {
      if (isTraceEnabled()) {
         log().tracef("[%s] All caches collected: %s", xid, cacheNames);
      }
      int size = cacheNames.size();
      if (size == 0) {
         //it can happen if all caches either commit or thrown an exception
         sendReply();
         return;
      }

      List<CompletableFuture<Void>> futures = new ArrayList<>(size);
      for (ByteString cacheName : cacheNames) {
         try {
            futures.add(completeCache(cacheName));
         } catch (Throwable t) {
            hasErrors = true;
         }
      }
      CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).thenRun(this::sendReply);
   }
911372
private void finish(boolean commit)
   {
      for (Synchronization s : syncs)
      {
         s.beforeCompletion();
      }

      if (commit)
      {
         status = Status.STATUS_COMMITTED;
      }
      else
      {
         status = Status.STATUS_ROLLEDBACK;
      }

      for (Synchronization s : syncs)
      {
         s.afterCompletion(status);
      }

      status = Status.STATUS_UNKNOWN;
      syncs.clear();
      resources.clear();
   }
609402
private void checkForCompletion() {
        final String methodName = "checkForCompletion(): ";
        // mark the list complete if that was the last awaited key
        if (actualIndices.isEmpty()) {
            if (tc.isDebugEnabled())
                Tr.debug(tc, methodName + "setting state=COMPLETE");
            state = failedKeys == null
                            ? COMPLETE
                            : COMPLETE_WITH_FAILURES; // state change must be last action
        }
    }