Tell the cache to start a new transaction. If no other transaction is
 active, the write cache is flushed before the transaction is started.
12025
def begin_transaction
      if @transaction_stack.empty?
        # The new transaction is the top-level transaction. Flush the write
        # buffer to save the current state of all objects.
        flush
      else
        # Save a copy of all objects that were modified during the enclosing
        # transaction.
        @transaction_stack.last.each do |id|
          @transaction_objects[id]._stash(@transaction_stack.length - 1)
        end
      end
      # Push a transaction buffer onto the transaction stack. This buffer will
      # hold a reference to all objects modified during this transaction.
      @transaction_stack.push(::Array.new)
    end
320514
def sync
      if @cache.in_transaction?
        @cache.abort_transaction
        @cache.flush
        PEROBS.log.fatal "You cannot call sync() during a transaction: \n" +
          Kernel.caller.join("\n")
      end
      @cache.flush
    end
1110669
@Start(priority = 20)
   public void start() {
      cacheName = cache.wired().getName();
      isInvalidationMode = configuration.clustering().cacheMode().isInvalidation();
      isTransactional = configuration.transaction().transactionMode().isTransactional();
      isTotalOrder = configuration.transaction().transactionProtocol().isTotalOrder();
      timeout = configuration.clustering().stateTransfer().timeout();

      CacheMode mode = configuration.clustering().cacheMode();
      isFetchEnabled = mode.needsStateTransfer() &&
              (configuration.clustering().stateTransfer().fetchInMemoryState() || configuration.persistence().fetchPersistentState());

      rpcOptions = new RpcOptions(DeliverOrder.NONE, timeout, TimeUnit.MILLISECONDS);

      stateRequestExecutor = new LimitedExecutor("StateRequest-" + cacheName, stateTransferExecutor, 1);
      running = true;
   }
612410
function StartTransaction()
	{
		if ($this->IsTransactionInProgress())
			throw new Exception('Transaction is already in progress.  Commit or rollback must be called before beginning a new transaction');
		
		if ($this->ConnectionSetting->IsReadOnlySlave)
			throw new Exception('Transactions are not allowed on a read-only slave');
		
		$this->RequireConnection(true);
		$this->Observe("DataAdapter ($this->_label) (DataAdapter.StartTransaction)", OBSERVE_QUERY);
		$this->_transactionInProgress = true;
		return $this->_driver->StartTransaction($this->_dbconn);
	}
1260621
def reset(self, force_flush_cache: bool = False) -> None:
        
        super(LDAPwrapper, self).reset()
        if len(self._transactions) == 0:
            raise RuntimeError("reset called outside a transaction.")
        self._transactions[-1] = []
793671
def _init_cache(self):
        
        self._last_update_id = None
        self._depth_message_buffer = []

        res = self._client.get_order_book(symbol=self._symbol, limit=self._limit)

        # process bid and asks from the order book
        for bid in res['bids']:
            self._depth_cache.add_bid(bid)
        for ask in res['asks']:
            self._depth_cache.add_ask(ask)

        # set first update id
        self._last_update_id = res['lastUpdateId']

        # set a time to refresh the depth cache
        if self._refresh_interval:
            self._refresh_time = int(time.time()) + self._refresh_interval

        # Apply any updates from the websocket
        for msg in self._depth_message_buffer:
            self._process_depth_message(msg, buffer=True)

        # clear the depth buffer
        del self._depth_message_buffer
67971
public synchronized void prepared() {
      if (trace) {
         log.tracef("[%s] Current status is %s, setting status to: PREPARED", globalTransaction.globalId(),
                    transactionState);
      }
      transactionState.add(State.PREPARED);
      notifyAll();
   }
1198823
public function transaction_starts() {
        if ($this->buffer !== null) {
            $this->unregister();
            return;
        }
        if (!$this->rsrc) {
            $this->unregister();
            return;
        }
        // This might eat memory pretty quickly...
        raise_memory_limit('2G');
        $this->buffer = array();

        while($next = $this->fetch_next()) {
            $this->buffer[] = $next;
        }
    }
296050
protected void modify(Transaction t) {
        try {
            this.lock.writeLock().lock();
            t.perform();
        } finally {
            this.lock.writeLock().unlock();
        }
    }
468304
synchronized void offer(TransactionTask task)
    {
        Iv2Trace.logTransactionTaskQueueOffer(task);
        TransactionState txnState = task.getTransactionState();
        if (!m_backlog.isEmpty()) {
            /*
             * This branch happens during regular execution when a multi-part is in progress.
             * The first task for the multi-part is the head of the queue, and all the single parts
             * are being queued behind it. The txnid check catches tasks that are part of the multi-part
             * and immediately queues them for execution. If any multi-part txn with smaller txnId shows up,
             * it must from repair process, just let it through.
             */
            if (txnState.isSinglePartition() ){
                m_backlog.addLast(task);
                return;
            }

            //It is possible a RO MP read with higher TxnId could be executed before a RO MP reader with lower TxnId
            //so do not offer them to the site task queue in the same time, place it in the backlog instead. However,
            //if it is an MP Write with a lower TxnId than the TxnId at the head of the backlog it could be a repair
            //task so put the MP Write task into the Scoreboard or the SiteTaskQueue
            TransactionTask headTask = m_backlog.getFirst();
            if (txnState.isReadOnly() && headTask.getTransactionState().isReadOnly() ?
                    TxnEgo.getSequence(task.getTxnId()) != TxnEgo.getSequence(headTask.getTxnId()) :
                    TxnEgo.getSequence(task.getTxnId()) > TxnEgo.getSequence(headTask.getTxnId())) {
                m_backlog.addLast(task);
            } else if (task.needCoordination() && m_scoreboardEnabled) {
                /*
                 * This branch coordinates FragmentTask or CompletedTransactionTask,
                 * holds the tasks until all the sites on the node receive the task.
                 * Task with newer spHandle will
                 */
                coordinatedTaskQueueOffer(task);
            } else {
                taskQueueOffer(task);
            }
        } else {
            /*
             * Base case nothing queued nothing in progress
             * If the task is a multipart then put an entry in the backlog which
             * will act as a barrier for single parts, queuing them for execution after the
             * multipart
             */
            if (!txnState.isSinglePartition()) {
                m_backlog.addLast(task);
            }
            /*
             * This branch coordinates FragmentTask or CompletedTransactionTask,
             * holds the tasks until all the sites on the node receive the task.
             * Task with newer spHandle will
             */
            if (task.needCoordination() && m_scoreboardEnabled) {
                coordinatedTaskQueueOffer(task);
            } else {
                taskQueueOffer(task);
            }
        }
    }
73224
@Override
    public void begin()
    {
        if (isActive())
        {
            throw new IllegalStateException("Transaction is already active");
        }
        else
        {
            this.coordinator = ((EntityManagerImpl) entityManager).getPersistenceDelegator().getCoordinator();
            ((EntityManagerImpl) entityManager).getPersistenceDelegator().begin(); // transaction
                                                                                   // de-marcation.
            this.coordinator.coordinate(TxAction.BEGIN);
        }
    }
854585
private static void cacheOnStart()
    {
        try {
            boolean closeContext = false;
            if (!Context.isThreadActive()) {
                Context.begin();
                closeContext = true;
            }
            Context.getThreadContext();
            final Connection con = Context.getConnection();
            final PreparedStatement stmtLang = con.prepareStatement(DBProperties.SQLLANG);
            final ResultSet rsLang = stmtLang.executeQuery();
            final Set<String> languages = new HashSet<>();
            while (rsLang.next()) {
                languages.add(rsLang.getString(1).trim());
            }
            rsLang.close();
            stmtLang.close();
            final Cache<String, String> cache = InfinispanCache.get().<String, String>getCache(
                            DBProperties.CACHENAME);
            final PreparedStatement stmt = con.prepareStatement(DBProperties.SQLSELECTONSTART);
            final ResultSet resultset = stmt.executeQuery();
            while (resultset.next()) {
                final String propKey = resultset.getString(1).trim();
                final String defaultValue = resultset.getString(2);
                if (defaultValue != null) {
                    final String value = defaultValue.trim();
                    for (final String lang : languages) {
                        final String cachKey = lang + ":" + propKey;
                        if (!cache.containsKey(cachKey)) {
                            cache.put(cachKey, value);
                        }
                    }
                }
                final String value = resultset.getString(3);
                final String lang = resultset.getString(4);
                if (value != null) {
                    final String cachKey = lang.trim() + ":" + propKey;
                    cache.put(cachKey, value.trim());
                }
            }
            resultset.close();
            stmt.close();
            con.commit();
            con.close();
            if (closeContext) {
                Context.rollback();
            }
        } catch (final EFapsException e) {
            DBProperties.LOG.error("initialiseCache()", e);
        } catch (final SQLException e) {
            DBProperties.LOG.error("initialiseCache()", e);
        }
    }
8333
private void tryInit() {
    try {
      Configuration conf = getSnapshotConfiguration();
      if (conf != null) {
        // Since this is only used for background loading of transaction snapshots, we use the no-op metrics collector,
        // as there are no relevant metrics to report
        this.storage = new HDFSTransactionStateStorage(conf, new SnapshotCodecProvider(conf),
                                                       new TxMetricsCollector());
        this.storage.startAndWait();
        this.snapshotRefreshFrequency = conf.getLong(TxConstants.Manager.CFG_TX_SNAPSHOT_INTERVAL,
                                                     TxConstants.Manager.DEFAULT_TX_SNAPSHOT_INTERVAL) * 1000;
        this.initialized = true;
      } else {
        LOG.info("Could not load configuration");
      }
    } catch (Exception e) {
      LOG.info("Failed to initialize TransactionStateCache due to: " + e.getMessage());
    }
  }
254721
public void init(String txn, TransactionConfig btc) {
        if (log.isLoggable(Level.FINE)) {
            log.fine("ProcessManager: initialise btxn '" + txn + "' config=" + btc
                    + " processors=" + btc.getProcessors().size());
        }

        if (btc.getProcessors() != null && !btc.getProcessors().isEmpty()) {
            List<ProcessorWrapper> procs = new ArrayList<ProcessorWrapper>();

            for (int i = 0; i < btc.getProcessors().size(); i++) {
                procs.add(new ProcessorWrapper(btc.getProcessors().get(i)));
            }

            synchronized (processors) {
                processors.put(txn, procs);
            }
        } else {
            synchronized (processors) {
                processors.remove(txn);
            }
        }
    }
281669
def transaction_start(self, name):
        
        if not name:
            raise ValueError("Transaction name cannot be empty")
            #uid = id(self)

        self.transaction_count += 1
        logger.debug("{}. Start transaction {}".format(self.transaction_count, name))
        if self.transaction_count == 1:
            self._transaction_start()
        else:
            self._transaction_started(name)

        return self.transaction_count
1141606
public final void markAsWriteTransaction(GlobalTransaction globalTransaction, boolean local) {
      TransactionStatistics txs = getTransactionStatistic(globalTransaction, local);
      if (txs == null) {
         log.markUnexistingTransactionAsWriteTransaction(globalTransaction == null ? "null" : globalTransaction.globalId());
         return;
      }
      txs.markAsUpdateTransaction();
   }
696896
def begin(self):
        

        if self.journal != None:
            raise Exception('Storage is already active, nested begin not supported')

        # under normal operation journal is deleted at end of transaction
        # if it does exist we need to roll back
        if os.path.isfile(self.j_file):  self.rollback()

        self.journal = open(self.j_file, 'w')