def tpc_begin(self, transaction): tdata = TransactionMetaData( transaction.user, transaction.description, transaction.extension) transaction.set_data(self, tdata) self._storage.tpc_begin(tdata)
def _begin(self, transaction): # This function is called when PJDataManager joins transaction. When # two phase commit is requested, we will assign transaction id to # underlying connection. if not PJ_TWO_PHASE_COMMIT_ENABLED: # We don't need to do anything special when two phase commit is # disabled. Transaction starts automatically. return assert self._pristine, ("Error attempting to add data manager " "from old transaction. Create a new " "PJDataManager for new transaction, do not " "modify objects from previously committed " "transactions") self._pristine = False # Create a global id for the transaction. If it wasn't yet created, # create now. try: txnid = transaction.data(PREPARED_TRANSACTION_ID) except KeyError: txnid = str(uuid.uuid4()) transaction.set_data(PREPARED_TRANSACTION_ID, txnid) try: xid = self._conn.xid(0, txnid, self.database) self._conn.tpc_begin(xid) except psycopg2.Error as e: check_for_disconnect(e, 'PJDataManager._begin') raise self._tpc_activated = True
def tpc_begin(self, transaction): """Begin commit of a transaction, starting the two-phase commit.""" self._modified = [] meta_data = TransactionMetaData(transaction.user, transaction.description, transaction.extension) transaction.set_data(self, meta_data) # _creating is a list of oids of new objects, which is used to # remove them from the cache if a transaction aborts. self._creating.clear() self._normal_storage.tpc_begin(meta_data)
def tpc_begin(self, transaction): """Begin commit of a transaction, starting the two-phase commit.""" self._modified = [] meta_data = TransactionMetaData( transaction.user, transaction.description, transaction.extension) transaction.set_data(self, meta_data) # _creating is a list of oids of new objects, which is used to # remove them from the cache if a transaction aborts. self._creating.clear() self._normal_storage.tpc_begin(meta_data)
def tpc_begin(self, transaction): assert self._storage is None, "Already in an active transaction" tdata = TransactionMetaData( transaction.user, transaction.description, transaction.extension) transaction.set_data(self, tdata) # `undo_instance` is not part of any IStorage interface; # it is defined in our MVCCAdapter. Regardless, we're opening # a new storage instance, and so we must close it to be sure # to reclaim resources in a timely manner. # # Once the tpc_begin method has been called, the transaction manager will # guarantee to call either `tpc_finish` or `tpc_abort`, so those are the only # methods we need to be concerned about calling close() from. db_mvcc_storage = self._db._mvcc_storage self._storage = getattr( db_mvcc_storage, 'undo_instance', db_mvcc_storage.new_instance)() self._storage.tpc_begin(tdata)