def tpc_begin(self, txn, tid=None, status=' '): """Storage API: begin a transaction.""" if self._is_read_only: raise POSException.ReadOnlyError() try: tbuf = txn.data(self) except AttributeError: # Gaaaa. This is a recovery transaction. Work around this # until we can think of something better. XXX tb = {} txn.data = tb.__getitem__ txn.set_data = tb.__setitem__ except KeyError: pass else: if tbuf is not None: raise POSException.StorageTransactionError( "Duplicate tpc_begin calls for same transaction") txn.set_data(self, TransactionBuffer(self._connection_generation)) # XXX we'd like to allow multiple transactions at a time at some point, # but for now, due to server limitations, TCBOO. self._commit_lock.acquire() self._tbuf = txn.data(self) try: self._async('tpc_begin', id(txn), txn.user, txn.description, txn.extension, tid, status) except ClientDisconnected: self.tpc_end(txn) raise
def tpc_begin(self, transaction, tid=None, status=' '): if self._is_read_only: raise POSException.ReadOnlyError() self._lock_acquire() try: if self._transaction is transaction: return self._lock_release() self._commit_lock_acquire() self._lock_acquire() self._transaction = transaction self._clear_temp() user = transaction.user desc = transaction.description ext = transaction._extension if ext: ext = cPickle.dumps(ext, 1) else: ext = "" self._ude = user, desc, ext if tid is None: now = time.time() t = TimeStamp(*(time.gmtime(now)[:5] + (now % 60, ))) self._ts = t = t.laterThan(self._ts) self._tid = repr(t) else: self._ts = TimeStamp(tid) self._tid = tid self._tstatus = status self._begin(self._tid, user, desc, ext) finally: self._lock_release()
def tpc_begin(self, txn, tid=None, status=' '): """Storage API: begin a transaction.""" if self._is_read_only: raise POSException.ReadOnlyError() self._tpc_cond.acquire() self._midtxn_disconnect = 0 while self._transaction is not None: # It is allowable for a client to call two tpc_begins in a # row with the same transaction, and the second of these # must be ignored. if self._transaction == txn: self._tpc_cond.release() return self._tpc_cond.wait(30) self._transaction = txn self._tpc_cond.release() try: self._server.tpc_begin(id(txn), txn.user, txn.description, txn._extension, tid, status) except: # Client may have disconnected during the tpc_begin(). if self._server is not disconnected_stub: self.end_transaction() raise self._tbuf.clear() self._seriald.clear() del self._serials[:]
def _check_trans(self, trans): """Internal helper to check a transaction argument for sanity.""" if self._is_read_only: raise POSException.ReadOnlyError() if self._transaction is not trans: raise POSException.StorageTransactionError(self._transaction, trans)
def new_oid(self): """Storage API: return a new object identifier. """ if self._is_read_only: raise POSException.ReadOnlyError() while 1: try: return self._oids.pop() except IndexError: pass # We ran out. We need to get some more. self._oids[:0] = reversed(self._call('new_oids'))
def new_oid(self): """Storage API: return a new object identifier.""" if self._is_read_only: raise POSException.ReadOnlyError() # avoid multiple oid requests to server at the same time self._oid_lock.acquire() try: if not self._oids: self._oids = self._server.new_oids() self._oids.reverse() return self._oids.pop() finally: self._oid_lock.release()
def new_oid(self): if self._is_read_only: raise POSException.ReadOnlyError() self._lock_acquire() try: last = self._oid d = ord(last[-1]) if d < 255: # fast path for the usual case last = last[:-1] + chr(d + 1) else: # there's a carry out of the last byte last_as_long, = _structunpack(">Q", last) last = _structpack(">Q", last_as_long + 1) self._oid = last return last finally: self._lock_release()
def _check_trans(self, trans, meth): """Internal helper to check a transaction argument for sanity.""" if self._is_read_only: raise POSException.ReadOnlyError() try: buf = trans.data(self) except KeyError: buf = None if buf is None: raise POSException.StorageTransactionError( "Transaction not committing", meth, trans) if buf.connection_generation != self._connection_generation: # We were disconnected, so this one is poisoned raise ClientDisconnected(meth, 'on a disconnected transaction') return buf
def tpc_begin(self, transaction, tid=None, status=' '): if self._is_read_only: raise POSException.ReadOnlyError() self._lock_acquire() try: if self._transaction is transaction: raise POSException.StorageTransactionError( "Duplicate tpc_begin calls for same transaction") self._lock_release() self._commit_lock_acquire() self._lock_acquire() self._transaction = transaction self._clear_temp() user = transaction.user desc = transaction.description ext = transaction._extension if ext: ext = dumps(ext, _protocol) else: ext = "" self._ude = user, desc, ext if tid is None: now = time.time() t = TimeStamp(*(time.gmtime(now)[:5] + (now % 60, ))) self._ts = t = t.laterThan(self._ts) self._tid = t.raw() else: self._ts = TimeStamp(tid) self._tid = tid self._tstatus = status self._begin(self._tid, user, desc, ext) finally: self._lock_release()
def pack(self, t, referencesf): if self._is_read_only: raise POSException.ReadOnlyError()
def undo(self, transaction_id, txn): if self._is_read_only: raise POSException.ReadOnlyError() raise POSException.UndoError('non-undoable transaction')
def raiseReadOnlyError(*args, **kw): raise POSException.ReadOnlyError()