[Zodb-checkins] CVS: ZODB3/ZODB - BaseStorage.py:1.36.2.5 Connection.py:1.100.2.6 DemoStorage.py:1.21.2.6 MappingStorage.py:1.9.40.5

Jeremy Hylton cvs-admin at zope.org
Tue Dec 2 02:11:06 EST 2003


Update of /cvs-repository/ZODB3/ZODB
In directory cvs.zope.org:/tmp/cvs-serv24432/ZODB

Modified Files:
      Tag: ZODB3-mvcc-2-branch
	BaseStorage.py Connection.py DemoStorage.py MappingStorage.py 
Log Message:
First cut at removal of serial numbers.
Rename loadNonCurrent() to loadBefore() (Jim's suggestion).

A few tests fail, but it's close enough to share the code with Tim.

In all case, the _p_serial attribute of a Persistent object matches
the id of the transaction that wrote the current revision.  Within the
storage API, we eliminate the abortVersion case where the txn id is
greater than the serial number.

Rename as many variables and attributes from serial to tid, with the
exception of store() and restore() arguments.  They're being passed in
from a client, which is getting the value from _p_serial; it makes
some sense there.

When tid and serial were both returned, eliminate serial and just use
tid.  

Replace "serial" with "tid" in some methods names, but not all.  I'll
get to the rest tomorrow.  The remaining ones are just used a lot.

Add XXX comment about now-bogus ZEO protocol that passes identical
serialnos for every object committed.


=== ZODB3/ZODB/BaseStorage.py 1.36.2.4 => 1.36.2.5 ===
--- ZODB3/ZODB/BaseStorage.py:1.36.2.4	Mon Nov 24 12:54:21 2003
+++ ZODB3/ZODB/BaseStorage.py	Tue Dec  2 02:10:30 2003
@@ -28,7 +28,6 @@
 
 class BaseStorage(UndoLogCompatible):
     _transaction=None # Transaction that is being committed
-    _serial=z64       # Transaction serial number
     _tstatus=' '      # Transaction status, used for copying data
     _is_read_only = 0
 
@@ -47,7 +46,7 @@
 
         t=time.time()
         t=self._ts=apply(TimeStamp,(time.gmtime(t)[:5]+(t%60,)))
-        self._serial=`t`
+        self._tid = `t`
         if base is None:
             self._oid='\0\0\0\0\0\0\0\0'
         else:
@@ -56,12 +55,12 @@
     def abortVersion(self, src, transaction):
         if transaction is not self._transaction:
             raise POSException.StorageTransactionError(self, transaction)
-        return self._serial, []
+        return self._tid, []
 
     def commitVersion(self, src, dest, transaction):
         if transaction is not self._transaction:
             raise POSException.StorageTransactionError(self, transaction)
-        return self._serial, []
+        return self._tid, []
 
     def close(self):
         pass
@@ -166,13 +165,13 @@
                 now = time.time()
                 t = TimeStamp(*(time.gmtime(now)[:5] + (now % 60,)))
                 self._ts = t = t.laterThan(self._ts)
-                self._serial = `t`
+                self._tid = `t`
             else:
                 self._ts = TimeStamp(tid)
-                self._serial = tid
+                self._tid = tid
 
             self._tstatus = status
-            self._begin(self._serial, user, desc, ext)
+            self._begin(self._tid, user, desc, ext)
         finally:
             self._lock_release()
 
@@ -202,10 +201,11 @@
                 return
             try:
                 if f is not None:
-                    f(self._serial)
+                    f(self._tid)
                 u, d, e = self._ude
-                self._finish(self._serial, u, d, e)
+                self._finish(self._tid, u, d, e)
                 self._clear_temp()
+                return self._tid
             finally:
                 self._ude = None
                 self._transaction = None
@@ -249,10 +249,10 @@
         raise POSException.Unsupported, (
             "Retrieval of historical revisions is not supported")
 
-    def loadNonCurrent(self, oid, tid):
+    def loadBefore(self, oid, tid):
         """Return most recent revision of oid before tid committed."""
 
-        # XXX Is it okay for loadNonCurrent() to return current data?
+        # XXX Is it okay for loadBefore() to return current data?
         # There doesn't seem to be a good reason to forbid it, even
         # though the typical use of this method will never find
         # current data.  But maybe we should call it loadByTid()?
@@ -289,7 +289,7 @@
         if start_time is None:
             return None
         data = self.loadSerial(oid, start_time)
-        return data, start_time, start_time, end_time
+        return data, start_time, end_time
 
     def getExtensionMethods(self):
         """getExtensionMethods
@@ -355,7 +355,7 @@
                 oid=r.oid
                 if verbose: print oid_repr(oid), r.version, len(r.data)
                 if restoring:
-                    self.restore(oid, r.serial, r.data, r.version,
+                    self.restore(oid, r.tid, r.data, r.version,
                                  r.data_txn, transaction)
                 else:
                     pre=preget(oid, None)


=== ZODB3/ZODB/Connection.py 1.100.2.5 => 1.100.2.6 ===
--- ZODB3/ZODB/Connection.py:1.100.2.5	Mon Dec  1 12:32:05 2003
+++ ZODB3/ZODB/Connection.py	Tue Dec  2 02:10:30 2003
@@ -635,19 +635,19 @@
         """
         try:
             # Load data that was current before the commit at txn_time.
-            t = self._storage.loadNonCurrent(obj._p_oid, self._txn_time)
+            t = self._storage.loadBefore(obj._p_oid, self._txn_time)
         except KeyError:
             return False
         if t is None:
             return False
-        data, serial, start, end = t
+        data, start, end = t
         # The non-current transaction must have been written before
         # txn_time.  It must be current at txn_time, but could have
         # been modified at txn_time.
         assert start < self._txn_time <= end, \
                (U64(start), U64(self._txn_time), U64(end))
         self._noncurrent[obj._p_oid] = True
-        self._set_ghost_state(obj, data, serial)
+        self._set_ghost_state(obj, data, start)
 
     def _set_ghost_state(self, obj, p, serial):
         file = StringIO(p)


=== ZODB3/ZODB/DemoStorage.py 1.21.2.5 => 1.21.2.6 ===
--- ZODB3/ZODB/DemoStorage.py:1.21.2.5	Mon Dec  1 10:16:09 2003
+++ ZODB3/ZODB/DemoStorage.py	Tue Dec  2 02:10:31 2003
@@ -45,14 +45,12 @@
 
 A record is a tuple:
 
-  oid, serial, pre, vdata, p, tid
+  oid, pre, vdata, p, tid
 
 where:
 
      oid -- object id
 
-     serial -- object serial number
-
      pre -- The previous record for this object (or None)
 
      vdata -- version data
@@ -62,7 +60,7 @@
 
      p -- the pickle data or None
 
-     tid -- the transaction id that wrote the record (usually == serial)
+     tid -- the transaction id that wrote the record
 
 The pickle data will be None for a record for an object created in
 an aborted version.
@@ -116,7 +114,7 @@
         s=100
         for tid, (p, u, d, e, t) in self._data.items():
             s=s+16+24+12+4+16+len(u)+16+len(d)+16+len(e)+16
-            for oid, serial, pre, vdata, p, tid in t:
+            for oid, pre, vdata, p, tid in t:
                 s=s+16+24+24+4+4+(p and (16+len(p)) or 4)
                 if vdata: s=s+12+16+len(vdata[0])+4
 
@@ -142,16 +140,16 @@
 
             oids = []
             for r in v.values():
-                oid, serial, pre, (version, nv), p, tid = r
+                oid, pre, (version, nv), p, tid = r
                 oids.append(oid)
                 if nv:
-                    oid, serial, pre, vdata, p, tid = nv
-                    self._tindex.append([oid, serial, r, None, p, self._serial])
+                    oid, pre, vdata, p, tid = nv
+                    self._tindex.append([oid, r, None, p, self._tid])
                 else:
                     # effectively, delete the thing
-                    self._tindex.append([oid, None, r, None, None, self._serial])
+                    self._tindex.append([oid, r, None, None, self._tid])
 
-            return self._serial, oids
+            return self._tid, oids
 
         finally: self._lock_release()
 
@@ -170,21 +168,21 @@
             v=self._vindex.get(src, None)
             if v is None: return
 
-            newserial = self._serial
+            newserial = self._tid
             tindex=self._tindex
             oids=[]
             for r in v.values():
-                oid, serial, pre, vdata, p, tid = r
+                oid, pre, vdata, p, tid = r
                 assert vdata is not None
                 oids.append(oid)
                 if dest:
                     new_vdata = dest, vdata[1]
                 else:
                     new_vdata = None
-                tindex.append([oid, newserial, r, new_vdata, p, self._serial])
+                tindex.append([oid, r, new_vdata, p, self._tid])
 
 
-            return self._serial, oids
+            return self._tid, oids
 
         finally: self._lock_release()
 
@@ -192,7 +190,7 @@
         self._lock_acquire()
         try:
             try:
-                oid, serial, pre, vdata, p, tid = self._index[oid]
+                oid, pre, vdata, p, tid = self._index[oid]
             except KeyError:
                 if self._base:
                     return self._base.load(oid, '')
@@ -205,7 +203,7 @@
                     if nv:
                         # Return the current txn's tid with the non-version
                         # data.
-                        oid, serial, pre, vdata, p, skiptid = nv
+                        oid, pre, vdata, p, skiptid = nv
                     else:
                         raise KeyError, oid
                 ver = oversion
@@ -213,7 +211,7 @@
             if p is None:
                 raise KeyError, oid
 
-            return p, serial, tid, ver
+            return p, tid, ver
         finally: self._lock_release()
 
     def load(self, oid, version):
@@ -223,7 +221,7 @@
         self._lock_acquire()
         try:
             try:
-                oid, serial, pre, vdata, p, tid = self._index[oid]
+                oid, pre, vdata, p, tid = self._index[oid]
                 if vdata: return vdata[0]
                 return ''
             except: return ''
@@ -240,15 +238,15 @@
                 # Hm, nothing here, check the base version:
                 if self._base:
                     try:
-                        p, oserial = self._base.load(oid, '')
+                        p, tid = self._base.load(oid, '')
                     except KeyError:
                         pass
                     else:
-                        old = oid, oserial, None, None, p
+                        old = oid, None, None, p, tid
 
             nv=None
             if old:
-                oid, oserial, pre, vdata, p, tid = old
+                oid, pre, vdata, p, tid = old
 
                 if vdata:
                     if vdata[0] != version:
@@ -258,12 +256,10 @@
                 else:
                     nv=old
 
-                if serial != oserial:
-                    raise POSException.ConflictError(serials=(oserial, serial))
+                if serial != tid:
+                    raise POSException.ConflictError(serials=(tid, serial))
 
-            serial=self._serial
-            r = [oid, serial, old, version and (version, nv) or None, data,
-                 self._serial]
+            r = [oid, old, version and (version, nv) or None, data, self._tid]
             self._tindex.append(r)
 
             s=self._tsize
@@ -277,7 +273,7 @@
                     has been exceeded.<br>Have a nice day.''')
 
         finally: self._lock_release()
-        return serial
+        return self._tid
 
     def supportsUndo(self):
         return 1
@@ -300,11 +296,11 @@
 
         self._data[tid] = None, user, desc, ext, tuple(self._tindex)
         for r in self._tindex:
-            oid, serial, pre, vdata, p, tid = r
+            oid, pre, vdata, p, tid = r
             old = self._index.get(oid)
             # If the object had version data, remove the version data.
             if old is not None:
-                oldvdata = old[3]
+                oldvdata = old[2]
                 if oldvdata:
                     v = self._vindex[oldvdata[0]]
                     del v[oid]
@@ -321,7 +317,7 @@
                 if v is None:
                     v = self._vindex[version] = {}
                 v[oid] = r
-        self._ltid = self._serial
+        self._ltid = self._tid
 
     def undo(self, transaction_id):
         self._lock_acquire()
@@ -340,7 +336,7 @@
 
             oids=[]
             for r in t:
-                oid, serial, pre, vdata, p, tid = r
+                oid, pre, vdata, p, tid = r
                 if pre:
 
                     index[oid] = pre
@@ -353,7 +349,7 @@
                         if v: del v[oid]
 
                     # Add new version data (from pre):
-                    oid, serial, prepre, vdata, p, tid = pre
+                    oid, prepre, vdata, p, tid = pre
                     if vdata:
                         version=vdata[0]
                         v=vindex.get(version, None)
@@ -426,11 +422,11 @@
             if tid >= stop:
                 break
             for r in t:
-                oid, serial, pre, vdata, p, tid = r
+                oid, pre, vdata, p, tid = r
                 old=index.get(oid, None)
 
                 if old is not None:
-                    oldvdata=old[3]
+                    oldvdata=old[2]
                     if oldvdata:
                         v=vindex[oldvdata[0]]
                         del v[oid]
@@ -476,12 +472,12 @@
                         referencesf(p, rootl)
                 else:
                     pindex[oid] = r
-                    oid, serial, pre, vdata, p, tid = r
+                    oid, pre, vdata, p, tid = r
                     referencesf(p, rootl)
                     if vdata:
                         nv = vdata[1]
                         if nv:
-                            oid, serial, pre, vdata, p, tid = nv
+                            oid, pre, vdata, p, tid = nv
                             referencesf(p, rootl)
 
             # Now we're ready to do the actual packing.
@@ -537,11 +533,11 @@
 
             # Now reset previous pointers for "current" records:
             for r in pindex.values():
-                r[2] = None # Previous record
-                if r[3] and r[3][1]: # vdata
+                r[1] = None # Previous record
+                if r[2] and r[2][1]: # vdata
                     # If this record contains version data and
                     # non-version data, then clear it out.
-                    r[3][1][2] = None
+                    r[2][1][2] = None
 
             # Finally, rebuild indexes from transaction data:
             self._index, self._vindex = self._build_indexes()
@@ -559,15 +555,15 @@
         for tid, (p, u, d, e, t) in self._data.items():
             o.append("  %s %s" % (TimeStamp(tid), p))
             for r in t:
-                oid, serial, pre, vdata, p, tid = r
+                oid, pre, vdata, p, tid = r
                 oid = utils.oid_repr(oid)
                 tid = utils.oid_repr(tid)
-                if serial is not None: serial=str(TimeStamp(serial))
+##                if serial is not None: serial=str(TimeStamp(serial))
                 pre=id(pre)
                 if vdata and vdata[1]: vdata=vdata[0], id(vdata[1])
                 if p: p=''
                 o.append('    %s: %s' %
-                         (id(r), `(oid, serial, pre, vdata, p, tid)`))
+                         (id(r), `(oid, pre, vdata, p, tid)`))
 
         o.append('\nIndex:')
         items=self._index.items()


=== ZODB3/ZODB/MappingStorage.py 1.9.40.4 => 1.9.40.5 ===
--- ZODB3/ZODB/MappingStorage.py:1.9.40.4	Mon Dec  1 10:16:10 2003
+++ ZODB3/ZODB/MappingStorage.py	Tue Dec  2 02:10:31 2003
@@ -64,11 +64,10 @@
             # Since this storage doesn't support versions, tid and
             # serial will always be the same.
             p = self._index[oid]
-            return p[8:], p[:8], p[:8], "" # pickle, serial, tid
+            return p[8:], p[:8], "" # pickle, serial, tid
         finally:
             self._lock_release()
 
-
     def store(self, oid, serial, data, version, transaction):
         if transaction is not self._transaction:
             raise POSException.StorageTransactionError(self, transaction)
@@ -84,11 +83,10 @@
                 if serial != oserial:
                     raise POSException.ConflictError(serials=(oserial, serial))
 
-            serial = self._serial
-            self._tindex.append((oid, serial + data))
+            self._tindex.append((oid, self._tid + data))
         finally:
             self._lock_release()
-        return serial
+        return self._tid
 
     def _clear_temp(self):
         self._tindex = []
@@ -96,7 +94,7 @@
     def _finish(self, tid, user, desc, ext):
         for oid, p in self._tindex:
             self._index[oid] = p
-        self._ltid = self._serial
+        self._ltid = self._tid
 
     def lastTransaction(self):
         return self._ltid




More information about the Zodb-checkins mailing list