@_SynchronizeTxn
  def Commit(self):
    """Commits the current txn.

    This function hands off the responsibility of calling _Apply to the owning
    TransactionManager.

    Returns:
      The cost of the transaction.
    """
    try:

      trackers = self._GetAllTrackers()
      empty = True
      for tracker in trackers:
        snapshot = tracker._GrabSnapshot(self._txn_manager)
        empty = empty and not tracker._put and not tracker._delete


        for entity, insert in tracker._put.itervalues():
          Check(not insert or self.Get(entity.key()) is None,
                'the id allocated for a new entity was already '
                'in use, please try again')

          old_entity = None
          old_version = None
          key = datastore_types.ReferenceToKeyValue(entity.key())
          self._mutated_references.append(entity.key())
          if key in snapshot:
            old_entity = snapshot[key].entity
            old_version = snapshot[key].metadata.updated_version()
          self._AddWriteOps(old_entity, entity)

          if _IsNoOpWrite(old_entity, entity):
            self._mutation_versions[key] = long(old_version)

        for reference in tracker._delete.itervalues():


          old_entity = None
          key = datastore_types.ReferenceToKeyValue(reference)
          self._mutated_references.append(reference)
          if key in snapshot:
            old_entity = snapshot[key].entity
            self._AddWriteOps(None, old_entity)

          if _IsNoOpWrite(old_entity, None):
            self._mutation_versions[key] = long(tracker._read_timestamp)


      if empty and not self._actions:
        self.Rollback()
        return datastore_pb.Cost()


      meta_data_list = [tracker._meta_data for tracker in trackers]
      self._txn_manager._AcquireWriteLocks(meta_data_list)
    except:

      self.Rollback()
      raise

    try:

      for tracker in trackers:
        Check(tracker._meta_data._log_pos == tracker._read_pos,
              'Concurrency exception.',
              datastore_pb.Error.CONCURRENT_TRANSACTION)


      for tracker in trackers:
        tracker._meta_data.Log(self)
      self._state = self.COMMITTED
      self._commit_time_s = time.time()
      write_timestamp = self._txn_manager._IncrementAndGetCommitTimestamp()

      for reference in self._mutated_references:
        key = datastore_types.ReferenceToKeyValue(reference)
        if key not in self._mutation_versions:
          self._mutation_versions[key] = long(write_timestamp)
    except:

      self.Rollback()
      raise
    else:

      for action in self._actions:
        try:
          apiproxy_stub_map.MakeSyncCall(
              'taskqueue', 'Add', action, api_base_pb.VoidProto())
        except apiproxy_errors.ApplicationError, e:
          logging.warning('Transactional task %s has been dropped, %s',
                          action, e)
      self._actions = []
    finally:
      self._txn_manager._RemoveTxn(self)

      self._txn_manager._ReleaseWriteLocks(meta_data_list)


    self._txn_manager._consistency_policy._OnCommit(self)
    return self._cost
dataset/ETHPy150Open GoogleCloudPlatform/python-compat-runtime/appengine-compat/exported_appengine_sdk/google/appengine/datastore/datastore_stub_util.py/LiveTxn.Commit/original