[Zodb-checkins] CVS: Packages/ZEO - ClientStorage.py:1.26.4.19
jeremy@digicool.com
jeremy@digicool.com
Mon, 7 May 2001 09:15:08 -0400 (EDT)
Update of /cvs-repository/Packages/ZEO
In directory korak:/tmp/cvs-serv21141
Modified Files:
Tag: ZEO-ZRPC-Dev
ClientStorage.py
Log Message:
Remove cache_lock. (The cache locks itself.)
Add oid_cond, so that only a single thread fetches new oids from the
server.
Remove unneeded XXX sync comments.
Move cache invalidate/update logic on commit to separate method.
--- Updated File ClientStorage.py in package Packages/ZEO --
--- ClientStorage.py 2001/05/03 03:10:37 1.26.4.18
+++ ClientStorage.py 2001/05/07 13:15:06 1.26.4.19
@@ -194,14 +194,10 @@
self.tpc_cond = threading.Condition()
self._transaction = None
- # Cache synchronization
- # We need to make sure the cache isn't accessed in an
- # inconsistent state. If one client is doing a load while
- # another is committing a transaction, the cache could contain
- # partial results for the committing transaction. Thus, there
- # needs to be locking so that only one thread is
- # reading/writing the cache at a time.
- self.cache_lock = threading.Lock()
+ # Prevent multiple new_oid calls from going out. The _oids
+ # variable should only be modified while holding the
+ # oid_cond.
+ self.oid_cond = threading.Condition()
commit_lock = thread.allocate_lock()
self._commit_lock_acquire = commit_lock.acquire
@@ -341,15 +337,12 @@
return oids
def history(self, oid, version, length=1):
- # XXX sync
return self._server.history(oid, version, length)
def loadSerial(self, oid, serial):
- # XXX sync
return self._server.loadSerial(oid, serial)
def load(self, oid, version, _stuff=None):
- # XXX sync
p = self._cache.load(oid, version)
if p:
return p
@@ -364,20 +357,22 @@
raise KeyError, oid # no non-version data for this
def modifiedInVersion(self, oid):
- # XXX sync
v = self._cache.modifiedInVersion(oid)
if v is not None:
return v
return self._server.modifiedInVersion(oid)
def new_oid(self, last=None):
-## if self._transaction is None:
-## # XXX What exception?
-## raise POSException.StorageTransactionError()
+ # We want to avoid a situation where multiple oid requests are
+ # made at the same time.
+ self.oid_cond.acquire()
if not self._oids:
self._oids = self._server.new_oids()
self._oids.reverse()
- return self._oids.pop()
+ self.oid_cond.notifyAll()
+ oid = self._oids.pop()
+ self.oid_cond.release()
+ return oid
def pack(self, t=None, rf=None, wait=0, days=0):
# Note that we ignore the rf argument. The server
@@ -459,10 +454,16 @@
r = self._check_serials()
assert r is None or len(r) == 0, "unhandled serialnos: %s" % r
- self._cache.checkSize(self._tbuf.get_size())
+ self._update_cache()
+
+ self._transaction = None
+ self.tpc_cond.notify()
+ self.tpc_cond.release()
+ def _update_cache(self):
# Iterate over the objects in the transaction buffer and
# update or invalidate the cache.
+ self._cache.checkSize(self._tbuf.get_size())
self._tbuf.begin_iterate()
while 1:
try:
@@ -483,10 +484,6 @@
else:
self._cache.update(oid, s, v, p)
self._tbuf.clear()
-
- self._transaction = None
- self.tpc_cond.notify()
- self.tpc_cond.release()
def transactionalUndo(self, trans_id, trans):
self._check_trans(trans, POSException.StorageTransactionError)