[Zodb-checkins] CVS: ZODB3/ZEO - ClientStorage.py:1.43
Jeremy Hylton
jeremy@zope.com
Wed, 14 Aug 2002 12:22:23 -0400
Update of /cvs-repository/ZODB3/ZEO
In directory cvs.zope.org:/tmp/cvs-serv30624
Modified Files:
ClientStorage.py
Log Message:
Add some comments and assertions about expected used of condition variable.
=== ZODB3/ZEO/ClientStorage.py 1.42 => 1.43 ===
--- ZODB3/ZEO/ClientStorage.py:1.42 Thu Aug 1 15:15:42 2002
+++ ZODB3/ZEO/ClientStorage.py Wed Aug 14 12:22:23 2002
@@ -12,8 +12,9 @@
#
##############################################################################
"""Network ZODB storage client
+
+$Id$
"""
-__version__='$Revision$'[11:-2]
import cPickle
import os
@@ -62,6 +63,13 @@
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:
def __init__(self, addr, storage='1', cache_size=20000000,
@@ -113,9 +121,12 @@
self.__name__ = name
# A ClientStorage only allows one client to commit at a time.
- # A client enters the commit state by finding tpc_tid set to
- # None and updating it to the new transaction's id. The
- # tpc_tid variable is protected by tpc_cond.
+ # Mutual exclusion is achieved using tpc_cond(), which
+ # protects _transaction. A thread that wants to assign to
+ # 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._transaction = None
@@ -218,14 +229,6 @@
raise exc(self._transaction, trans)
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):
if self._is_read_only:
raise POSException.ReadOnlyError()
@@ -330,6 +333,7 @@
def tpc_abort(self, transaction):
if transaction is not self._transaction:
return
+ assert check_thread_id(transaction)
try:
self._server.tpc_abort(self._serial)
self._tbuf.clear()
@@ -389,6 +393,7 @@
def tpc_finish(self, transaction, f=None):
if transaction is not self._transaction:
return
+ assert check_thread_id(transaction)
try:
if f is not None:
f()