[Zodb-checkins] CVS: ZODB3/ZODB - DemoStorage.py:1.14.4.1

Jeremy Hylton jeremy at zope.com
Tue Apr 29 18:35:33 EDT 2003


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

Modified Files:
      Tag: ZODB3-3_1-branch
	DemoStorage.py 
Log Message:
Two backports.

Fix undoLog() to process arguments correctly.
Fix edge case in pack() -- backpointer to object created in version.


=== ZODB3/ZODB/DemoStorage.py 1.14 => 1.14.4.1 ===
--- ZODB3/ZODB/DemoStorage.py:1.14	Wed Aug 28 14:48:59 2002
+++ ZODB3/ZODB/DemoStorage.py	Tue Apr 29 17:35:32 2003
@@ -90,7 +90,6 @@
 class DemoStorage(BaseStorage.BaseStorage):
 
     def __init__(self, name='Demo Storage', base=None, quota=None):
-
         BaseStorage.BaseStorage.__init__(self, name, base)
 
         # We use a BTree because the items are sorted!
@@ -141,8 +140,8 @@
             oids = []
             for r in v.values():
                 oid, serial, pre, (version, nv), p = r
+                oids.append(oid)
                 if nv:
-                    oids.append(oid)
                     oid, serial, pre, vdata, p = nv
                     self._tindex.append([oid, serial, r, None, p])
                 else:
@@ -226,13 +225,16 @@
 
         self._lock_acquire()
         try:
-            old=self._index.get(oid, None)
+            old = self._index.get(oid, None)
             if old is None:
                 # Hm, nothing here, check the base version:
-                try: p, oserial = self._base.load(oid, '')
-                except: pass
-                else:
-                    old= oid, oserial, None, None, p
+                if self._base:
+                    try:
+                        p, oserial = self._base.load(oid, '')
+                    except KeyError:
+                        pass
+                    else:
+                        old = oid, oserial, None, None, p
 
             nv=None
             if old:
@@ -355,10 +357,11 @@
         finally: self._lock_release()
 
     def undoLog(self, first, last, filter=None):
-        # I think this is wrong given the handling of first and last
-        # in FileStorage.
+        if last < 0:
+            last = first - last + 1
         self._lock_acquire()
         try:
+            # XXX Shouldn't this be sorted?
             transactions = self._data.items()
             pos = len(transactions)
             r = []
@@ -452,9 +455,9 @@
                 # Scan non-version pickle for references
                 r=index.get(oid, None)
                 if r is None:
-                    # Base storage
-                    p, s = self._base.load(oid, '')
-                    referencesf(p, rootl)
+                    if self._base:
+                        p, s = self._base.load(oid, '')
+                        referencesf(p, rootl)
                 else:
                     pindex[oid]=r
                     oid, serial, pre, vdata, p = r
@@ -504,25 +507,27 @@
 
                 if o:
                     if len(o) != len(t):
-                        _data[tid]=1, u, d, e, tuple(o) # Reset data
+                        _data[tid] = 1, u, d, e, tuple(o) # Reset data
                 else:
                     deleted.append(tid)
 
             # Now delete empty transactions
-            for tid in deleted: del _data[tid]
+            for tid in deleted:
+                del _data[tid]
 
             # Now reset previous pointers for "current" records:
             for r in pindex.values():
-                r[2]=None # Previous record
-                if r[3]: # vdata
-                    r[3][1][2]=None
-
-            pindex=None
+                r[2] = None # Previous record
+                if r[3] and r[3][1]: # vdata
+                    # If this record contains version data and
+                    # non-version data, then clear it out.
+                    r[3][1][2] = None
 
             # Finally, rebuild indexes from transaction data:
             self._index, self._vindex = self._build_indexes()
 
-        finally: self._lock_release()
+        finally:
+            self._lock_release()
         self.getSize()
 
     def _splat(self):




More information about the Zodb-checkins mailing list