[Zope-Checkins] CVS: StandaloneZODB/ZODB - FileStorage.py:1.71.2.2

Jeremy Hylton jeremy@zope.com
Mon, 8 Oct 2001 22:40:41 -0400


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

Modified Files:
      Tag: jeremy-Standby-branch
	FileStorage.py 
Log Message:
add lastSerial() implementation

mixin BaseStorage.TransactionRecord and BaseStorage.DataRecord

reformat some lines


=== StandaloneZODB/ZODB/FileStorage.py 1.71.2.1 => 1.71.2.2 ===
     def close(self):
         self._file.close()
-        if hasattr(self,'_lock_file'):  self._lock_file.close()
-        if self._tfile:                 self._tfile.close()
-        try: self._save_index()
-        except: pass # We don't care if this fails.
+        if hasattr(self,'_lock_file'):
+            self._lock_file.close()
+        if self._tfile:
+            self._tfile.close()
+        try:
+            self._save_index()
+        except:
+            # XXX should log the error, though
+            pass # We don't care if this fails.
         
     def commitVersion(self, src, dest, transaction, abort=None):
         # We are going to commit by simply storing back pointers.
@@ -747,9 +752,9 @@
 
             # We have to check lengths here because struct.pack
             # doesn't raise an exception on overflow!
-            if luser > 65535: raise FileStorageError, 'user name too long'
-            if ldesc > 65535: raise FileStorageError, 'description too long'
-            if lext  > 65535: raise FileStorageError, 'too much extension data'
+            if luser > 65535: raise FileStorageError('user name too long')
+            if ldesc > 65535: raise FileStorageError('description too long')
+            if lext > 65535: raise FileStorageError('too much extension data')
 
             tlen=self._thl
             pos=self._pos
@@ -763,7 +768,7 @@
                 # suspect.
                 write(pack(
                     ">8s" "8s" "c"  "H"        "H"        "H"
-                     ,tid, stl, 'c', luser,     ldesc,     lext,
+                     ,tid, stl,'c',  luser,     ldesc,     lext,
                     ))
                 if user: write(user)
                 if desc: write(desc)
@@ -1598,8 +1603,22 @@
         return FileIterator(self._file_name, start, stop)
 
     def lastTransaction(self):
+        """Return transaction id for last committed transaction"""
         return self._ltid
 
+    def lastSerial(self, oid):
+        """Return last serialno committed for object oid."""
+        pos = self._index[oid]
+        self._file.seek(pos)
+        # first 8 bytes are oid, second 8 bytes are serialno
+        h = self._file.read(16)
+        if len(h) < 16:
+            raise CorruptedDataError, h
+        if h[:8] != oid:
+            h = h + self._file.read(26) # get rest of header
+            raise CorruptedDataError, h
+        return h[8:]
+
 def shift_transactions_forward(index, vindex, tindex, file, pos, opos):
     """Copy transactions forward in the data file
 
@@ -2147,7 +2166,7 @@
 
         raise IndexError, index
     
-class RecordIterator(Iterator):
+class RecordIterator(Iterator, BaseStorage.TransactionRecord):
     """Iterate over the transactions in a FileStorage file.
     """
     def __init__(self, tid, status, user, desc, ext, pos, stuff):
@@ -2199,9 +2218,8 @@
             return r
         
         raise IndexError, index
-    
 
-class Record:
+class Record(BaseStorage.DataRecord):
     """An abstract database record
     """
     def __init__(self, *args):