[Zope3-checkins] CVS: ZODB4/ZODB - POSException.py:1.18.6.1 FileStorage.py:1.110.6.1

Jeremy Hylton jeremy@zope.com
Fri, 6 Dec 2002 18:58:02 -0500


Update of /cvs-repository/ZODB4/ZODB
In directory cvs.zope.org:/tmp/cvs-serv27248/ZODB

Modified Files:
      Tag: ZODB4-Q-branch
	POSException.py FileStorage.py 
Log Message:
Partial progress on conversion to use Q struct code.


=== ZODB4/ZODB/POSException.py 1.18 => 1.18.6.1 ===
--- ZODB4/ZODB/POSException.py:1.18	Tue Dec  3 13:38:02 2002
+++ ZODB4/ZODB/POSException.py	Fri Dec  6 18:58:01 2002
@@ -152,6 +152,14 @@
 class VersionLockError(VersionError, TransactionError):
     """Can't modify an object that is modified in unsaved version."""
 
+    def __init__(self, oid, version):
+        self.oid = oid
+        self.version = version
+
+    def __str__(self):
+        return "%s locked in version %r" % (_fmt_oid(self.oid),
+                                            self.version)
+
 class UndoError(POSError):
     """An attempt was made to undo a non-undoable transaction."""
 


=== ZODB4/ZODB/FileStorage.py 1.110 => 1.110.6.1 === (576/676 lines abridged)
--- ZODB4/ZODB/FileStorage.py:1.110	Wed Dec  4 16:41:36 2002
+++ ZODB4/ZODB/FileStorage.py	Fri Dec  6 18:58:01 2002
@@ -150,17 +150,17 @@
 
 t32 = 1L << 32
 # the struct formats for the headers
-TRANS_HDR = ">8s8scHHH"
-DATA_HDR = ">8s8s8s8sH8s"
+TRANS_HDR = ">8sQcHHH"
+DATA_HDR = ">8s8sQQHQ"
 # constants to support various header sizes
 TRANS_HDR_LEN = 23
 DATA_HDR_LEN = 42
 DATA_VERSION_HDR_LEN = 58
-
-packed_version='FS21'
 assert struct.calcsize(TRANS_HDR) == TRANS_HDR_LEN
 assert struct.calcsize(DATA_HDR) == DATA_HDR_LEN
 
+packed_version = 'FS21'
+
 def warn(message, *data):
     LOG('ZODB FS', WARNING, "%s  warn: %s\n" % (packed_version,
                                                 (message % data)))
@@ -255,11 +255,7 @@
         self._file_name = file_name
 
         BaseStorage.BaseStorage.__init__(self, file_name)
-
-        index, vindex, tindex, tvindex = self._newIndexes()
-        self._initIndex(index, vindex, tindex, tvindex)
-
-        # Now open the file
+        self._initIndex()
 
         self._file = None
         if not create:
@@ -291,14 +287,14 @@
             index, vindex, start, maxoid, ltid = r
             self._initIndex(index, vindex, tindex, tvindex)
             self._pos, self._oid, tid = read_index(
-                self._file, file_name, index, vindex, tindex, stop,
-                ltid=ltid, start=start, maxoid=maxoid,
+                self._file, file_name, self._index, self._vindex,
+                self._tindex, stop, ltid=ltid, start=start, maxoid=maxoid,
                 read_only=read_only,
                 )
         else:
             self._pos, self._oid, tid = read_index(
-                self._file, file_name, index, vindex, tindex, stop,

[-=- -=- -=- 576 lines omitted -=- -=- -=-]

+                l = u64(read(8))
+                if l != stl:
                     panic('%s has inconsistent transaction length at %s',
                           self._file.name, pos)
                 pos=tend+8
@@ -2340,8 +2327,8 @@
 
             # Read the (intentionally redundant) transaction length
             seek(pos)
-            h = read(8)
-            if h != stl:
+            l = u64(read(8))
+            if l != tl:
                 warn("%s redundant transaction length check failed at %s",
                      self._file.name, pos)
                 break
@@ -2371,10 +2358,7 @@
             # Read the data records for this transaction
             self._file.seek(pos)
             h = self._file.read(DATA_HDR_LEN)
-            oid, serial, sprev, stloc, vlen, splen = unpack(DATA_HDR, h)
-            prev = u64(sprev)
-            tloc = u64(stloc)
-            plen = u64(splen)
+            oid, serial, prev, tloc, vlen, plen = unpack(DATA_HDR, h)
             dlen = DATA_HDR_LEN + (plen or 8)
 
             if vlen:
@@ -2479,3 +2463,21 @@
              'description': d}
         d.update(e)
         return d
+
+class DataHeader:
+    """Header for a data record."""
+
+    __slots__ = "oid", "serial", "prev", "tloc", "vlen", "plen"
+
+    def __init__(self, oid, serial, prev, tloc, vlen, plen):
+        self.oid = oid
+        self.serial = serial
+        self.prev = prev
+        self.tloc = tloc
+        self.vlen = vlen
+        self.plen = plen
+
+    def fromString(cls, s):
+        return cls(*struct.unpack(DATA_HDR, s))
+        
+    fromString = classmethod(fromString)