Commit c41bc70d authored by Jeremy Hylton's avatar Jeremy Hylton

Add some comments and assertions about expected used of condition variable.

parent 16b081c8
...@@ -12,8 +12,9 @@ ...@@ -12,8 +12,9 @@
# #
############################################################################## ##############################################################################
"""Network ZODB storage client """Network ZODB storage client
$Id: ClientStorage.py,v 1.43 2002/08/14 16:22:23 jeremy Exp $
""" """
__version__='$Revision: 1.42 $'[11:-2]
import cPickle import cPickle
import os import os
...@@ -62,6 +63,13 @@ class DisconnectedServerStub: ...@@ -62,6 +63,13 @@ class DisconnectedServerStub:
disconnected_stub = DisconnectedServerStub() disconnected_stub = DisconnectedServerStub()
import thread
def check_thread_id(txn):
if txn._id is None: # We can't tell what thread created this
return 1
return txn._id == thread.get_ident()
class ClientStorage: class ClientStorage:
def __init__(self, addr, storage='1', cache_size=20000000, def __init__(self, addr, storage='1', cache_size=20000000,
...@@ -113,9 +121,12 @@ class ClientStorage: ...@@ -113,9 +121,12 @@ class ClientStorage:
self.__name__ = name self.__name__ = name
# A ClientStorage only allows one client to commit at a time. # A ClientStorage only allows one client to commit at a time.
# A client enters the commit state by finding tpc_tid set to # Mutual exclusion is achieved using tpc_cond(), which
# None and updating it to the new transaction's id. The # protects _transaction. A thread that wants to assign to
# tpc_tid variable is protected by tpc_cond. # self._transaction must acquire tpc_cond() first.
# Invariant: If self._transaction is not None, then tpc_cond()
# must be acquired.
self.tpc_cond = threading.Condition() self.tpc_cond = threading.Condition()
self._transaction = None self._transaction = None
...@@ -218,14 +229,6 @@ class ClientStorage: ...@@ -218,14 +229,6 @@ class ClientStorage:
raise exc(self._transaction, trans) raise exc(self._transaction, trans)
return 1 return 1
def _check_tid(self, tid, exc=None):
if self.tpc_tid != tid:
if exc is None:
return 0
else:
raise exc(self.tpc_tid, tid)
return 1
def abortVersion(self, src, transaction): def abortVersion(self, src, transaction):
if self._is_read_only: if self._is_read_only:
raise POSException.ReadOnlyError() raise POSException.ReadOnlyError()
...@@ -330,6 +333,7 @@ class ClientStorage: ...@@ -330,6 +333,7 @@ class ClientStorage:
def tpc_abort(self, transaction): def tpc_abort(self, transaction):
if transaction is not self._transaction: if transaction is not self._transaction:
return return
assert check_thread_id(transaction)
try: try:
self._server.tpc_abort(self._serial) self._server.tpc_abort(self._serial)
self._tbuf.clear() self._tbuf.clear()
...@@ -389,6 +393,7 @@ class ClientStorage: ...@@ -389,6 +393,7 @@ class ClientStorage:
def tpc_finish(self, transaction, f=None): def tpc_finish(self, transaction, f=None):
if transaction is not self._transaction: if transaction is not self._transaction:
return return
assert check_thread_id(transaction)
try: try:
if f is not None: if f is not None:
f() f()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment