[Zodb-checkins] CVS: Packages/ZEO - ClientStorage.py:1.26.4.9

jeremy@digicool.com jeremy@digicool.com
Fri, 20 Apr 2001 09:51:25 -0400 (EDT)


Update of /cvs-repository/Packages/ZEO
In directory korak:/tmp/cvs-serv13565

Modified Files:
      Tag: ZEO-ZRPC-Dev
	ClientStorage.py 
Log Message:
More cleanups

Add untested support for confliction resolution.

Move timestamp generation process to function.   XXX Might be better
as a method.

Simplify logic of new_oid(), depending on list[:] to have a side
effect on an aliased attribute was too subtle.

Eliminate some used-once local variables in tpc_begin().



--- Updated File ClientStorage.py in package Packages/ZEO --
--- ClientStorage.py	2001/04/19 18:24:02	1.26.4.8
+++ ClientStorage.py	2001/04/20 13:51:24	1.26.4.9
@@ -101,6 +101,11 @@
 from ZODB.TimeStamp import TimeStamp
 from zLOG import LOG, PROBLEM, INFO, BLATHER
 
+try:
+    from ZODB.ConflictResolution import ResolvedSerial
+except ImportError:
+    ResolvedSerial = 'rs'
+
 import sys
 from types import TupleType, StringType
 
@@ -113,6 +118,12 @@
 class ClientDisconnected(ClientStorageError):
     """The database storage is disconnected from the storage."""
 
+def get_timestamp(prev_ts):
+    t = time.time()
+    t = apply(TimeStamp, (time.gmtime(t)[:5] + (t % 60,)))
+    t = t.laterThan(prev_ts)
+    return t
+
 class ClientStorage(BaseStorage.BaseStorage):
     __super_init = BaseStorage.BaseStorage.__init__
 
@@ -306,11 +317,10 @@
     def new_oid(self, last=None):
         self._lock_acquire()
         try:
-            oids = self._oids
-            if not oids:
-                oids[:] = self._server.new_oids()
-                oids.reverse()
-            return oids.pop()
+            if not self._oids:
+                self._oids = self._server.new_oids()
+                self._oids.reverse()
+            return self._oids.pop()
         finally:
             self._lock_release()
         
@@ -327,7 +337,6 @@
             self._lock_release()
 
     def _check_serials(self):
-        # XXX I don't really understand what this does
         if self._serials:
             l = len(self._serials)
             r = self._serials[:l]
@@ -343,9 +352,6 @@
             raise POSException.StorageTransactionError(self, transaction)
         self._lock_acquire()
         try:
-            # XXX this code used to store the value returned by
-            # sendMessage and then return it if _serials was None.
-            # But sendMessage always returned None.
             self._server.storea(oid, serial, data, version, self._serial) 
             self._tbuf.store(oid, version, data)
             return self._check_serials()
@@ -387,26 +393,22 @@
         # vote stage.  
         self._lock_acquire()
         try:
-            if self._transaction is transaction: return
+            if self._transaction is transaction:
+                return # can start the same transaction many times
 
-            user=transaction.user
-            desc=transaction.description
-            ext=transaction._extension
-
             while 1:
                 self._lock_release()
                 self._commit_lock_acquire()
                 self._lock_acquire()
 
-                # We've got the local commit lock. Now get
-                # a (tentative) transaction time stamp.
-                t=time.time()
-                t=apply(TimeStamp,(time.gmtime(t)[:5]+(t%60,)))
-                self._ts=t=t.laterThan(self._ts)
-                id=`t`
+                self._ts = get_timestamp(self._ts)
+                id = `self._ts`
                 
                 try:
-                    r = self._server.tpc_begin(id, user, desc, ext)
+                    r = self._server.tpc_begin(id,
+                                               transaction.user,
+                                               transaction.description,
+                                               transaction._extension)
                 except:
                     self._commit_lock_release()
                     raise
@@ -421,7 +423,6 @@
             del self._serials[:]
 
             self._transaction = transaction
-            
         finally:
             self._lock_release()
 
@@ -459,7 +460,10 @@
                     LOG("ClientStorage", INFO, "bad serialno: %s for %s" % \
                         (repr(s), repr(oid)))
                 assert type(s) == StringType, "bad serialno: %s" % repr(s)
-                self._cache.update(oid, s, v, p)
+                if s == ResolvedSerial:
+                    self._cache.invalidate(oid, v)
+                else:
+                    self._cache.update(oid, s, v, p)
             self._tbuf.clear()
 
             self._transaction=None