[Zodb-checkins] CVS: StandaloneZODB/ZODB - FileStorage.py:1.69

Jeremy Hylton jeremy@zope.com
Fri, 5 Oct 2001 13:58:59 -0400


Update of /cvs-repository/StandaloneZODB/ZODB
In directory cvs.zope.org:/tmp/cvs-serv14851

Modified Files:
	FileStorage.py 
Log Message:
Various small cleanups.

In tpc_vote() rename local variable id to tid.

Add doc string to read_index(), helpful but not complete yet.

In read_index(), replace an iteration over the tindex for each
transaction with a few calls that do the work with much less
overhead.


=== StandaloneZODB/ZODB/FileStorage.py 1.68 => 1.69 ===
 
         r=self._restore_index()
-        if r:
+        if r is not None:
             index, vindex, start, maxoid, ltid = r
             self._initIndex(index, vindex, tindex, tvindex)
             self._pos, self._oid, tid = read_index(
@@ -324,7 +324,6 @@
                 self._ts=t
 
         self._quota=quota
-            
 
     def _initIndex(self, index, vindex, tindex, tvindex):
         self._index=index
@@ -380,8 +379,8 @@
         check to see that the included records are consistent
         with the index.  Any invalid record records or inconsistent
         object positions cause zero to be returned.
-
         """
+        
         if pos < 100: return 0
         file=self._file
         seek=file.seek
@@ -740,7 +739,7 @@
             file=self._file
             write=file.write
             tfile.seek(0)
-            id=self._serial
+            tid=self._serial
             user, desc, ext = self._ude
             luser=len(user)
             ldesc=len(desc)
@@ -764,7 +763,7 @@
                 # suspect.
                 write(pack(
                     ">8s" "8s" "c"  "H"        "H"        "H"
-                     ,id, stl, 'c', luser,     ldesc,     lext,
+                     ,tid, stl, 'c', luser,     ldesc,     lext,
                     ))
                 if user: write(user)
                 if desc: write(desc)
@@ -1595,8 +1594,8 @@
             self._packt=z64
             _lock_release()
 
-    def iterator(self): return FileIterator(self._file_name)
-        
+    def iterator(self):
+        return FileIterator(self._file_name)
 
 def shift_transactions_forward(index, vindex, tindex, file, pos, opos):
     """Copy transactions forward in the data file
@@ -1760,6 +1759,27 @@
 
 def read_index(file, name, index, vindex, tindex, stop='\377'*8,
                ltid=z64, start=4L, maxoid=z64, recover=0, read_only=0):
+    """Scan the entire file storage and recreate the index.
+
+    Returns file position, max oid, and last transaction id.  It also
+    stores index information in the three dictionary arguments.
+
+    Arguments:
+    file -- a file object (the Data.fs)
+    name -- the name of the file (presumably file.name)
+    index -- dictionary, oid -> data record
+    vindex -- dictionary, oid -> data record for version data
+    tindex -- dictionary, oid -> data record
+       XXX tindex is cleared before return, so it will be empty
+
+    There are several default arguments that affect the scan or the
+    return values.  XXX should document them.
+
+    The file position returned is the position just after the last
+    valid transaction record.  The oid returned is the maximum object
+    id in the data.  The transaction id is the tid of the last
+    transaction. 
+    """
     
     read=file.read
     seek=file.seek
@@ -1884,7 +1904,7 @@
                 panic("%s data record exceeds transaction record at %s",
                       name, pos)
                 
-            if index_get(oid,0) != prev:
+            if index_get(oid, 0) != prev:
                 if prev:
                     if recover: return tpos, None, None
                     error("%s incorrect previous pointer at %s", name, pos)
@@ -1905,10 +1925,10 @@
             panic("%s redundant transaction length check failed at %s",
                   name, pos)
         pos=pos+8
-        
-        for oid, p in tindex.items():
-            maxoid=max(maxoid,oid)
-            index[oid]=p # Record the position
+
+        _maxoid = max(tindex.keys()) # in 2.2, just max(tindex)
+        maxoid = max(_maxoid, maxoid)
+        index.update(tindex)
 
         tindex.clear()
 
@@ -2053,8 +2073,6 @@
                 else:
                     warn('%s has invalid transaction header at %s', name, pos)
                     break
-
-            # if tid >= stop: raise IndexError, index
 
             tpos=pos
             tend=tpos+tl