[Zope3-checkins] CVS: ZODB4/src/zodb/storage - file.py:1.8.4.1

Barry Warsaw barry@wooz.org
Mon, 10 Feb 2003 18:12:48 -0500


Update of /cvs-repository/ZODB4/src/zodb/storage
In directory cvs.zope.org:/tmp/cvs-serv5119/src/zodb/storage

Modified Files:
      Tag: opaque-pickles-branch
	file.py 
Log Message:
The start of opaque pickles (from the p.o.v. of the storages).  This
will eventually allow us to pass compressed pickles to the storage if
we want.

The approach basically changes store() so that the data argument is a
2-tuple of the pickle and the list of oids referenced in the pickle.
This is the first step in the changes, but currently, only Berkeley
storages natively store the refs included in the store() API call.

Changes here include:

- store(): split the data 2-tuple into the data and the ref oids, the
  latter which is currently thrown away.  Big XXX comment reminds us
  that we need to natively store these object references.

- get ZERO from zodb.interfaces, and use MAXTID for DNE.

- _read_index(): Use MAXTID from zodb.interfaces instead of '\377'*8


=== ZODB4/src/zodb/storage/file.py 1.8 => 1.8.4.1 ===
--- ZODB4/src/zodb/storage/file.py:1.8	Wed Feb  5 18:28:32 2003
+++ ZODB4/src/zodb/storage/file.py	Mon Feb 10 18:12:47 2003
@@ -153,10 +153,10 @@
 from zodb.serialize import findrefs
 from zodb.timestamp import TimeStamp, newTimeStamp, timeStampFromTime
 from zodb.lockfile import lock_file
-from zodb.utils import p64, u64, cp, z64
+from zodb.utils import p64, u64, cp
 from zodb.storage.fsindex import fsIndex
 from zodb.storage.interfaces import *
-from zodb.interfaces import ITransactionAttrs
+from zodb.interfaces import ITransactionAttrs, ZERO, MAXTID
 
 t32 = 1L << 32
 # the struct formats for the headers
@@ -224,8 +224,9 @@
 
     # subclasses must provide _file
 
-    def _read_index(self, index, vindex, tindex, stop='\377'*8,
-                    ltid=z64, start=None, maxoid=z64, recover=0, read_only=0):
+    def _read_index(self, index, vindex, tindex, stop=MAXTID,
+                    ltid=ZERO, start=None, maxoid=ZERO, 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
@@ -486,7 +487,7 @@
 class FileStorage(BaseStorage, FileStorageFormatter,
                   conflict.ConflictResolvingStorage):
     # default pack time is 0
-    _packt = z64
+    _packt = ZERO
 
     __implements__ = IStorage, IUndoStorage, IVersionStorage
 
@@ -507,7 +508,7 @@
                              "in read-only mode")
 
         if stop is None:
-            stop='\377'*8
+            stop=MAXTID
 
         self._file_name = file_name
         super(FileStorage, self).__init__(file_name)
@@ -828,6 +829,8 @@
         if transaction is not self._transaction:
             raise StorageTransactionError(self, transaction)
 
+        # XXX Kludge until FileStorage natively stores the object refs
+        data, refs = data
         self._lock_acquire()
         try:
             old = self._index.get(oid, 0)
@@ -980,7 +983,7 @@
                 else:
                     # Write a zero backpointer, which indicates an
                     # un-creation transaction.
-                    self._tfile.write(z64)
+                    self._tfile.write(ZERO)
             else:
                 self._tfile.write(data)
         finally:
@@ -1443,14 +1446,14 @@
             raise ReadOnlyError()
 
         stop = timeStampFromTime(t).raw()
-        if stop == z64:
+        if stop == ZERO:
             raise FileStorageError, 'Invalid pack time'
 
         # Record pack time so we don't undo while packing
         self._lock_acquire()
         try:
             # XXX _packt should just be a flag
-            if self._packt != z64:
+            if self._packt != ZERO:
                 # Already packing.
                 raise FileStorageError, 'Already packing'
             # when undo sees _packt == None, it raises an error that
@@ -1489,7 +1492,7 @@
                 self._commit_lock_release()
                 self._lock_release()
             self._lock_acquire()
-            self._packt = z64
+            self._packt = ZERO
             self._lock_release()
 
 
@@ -1561,7 +1564,7 @@
         return self._file.read(1) != ' ' # XXX or == "p"?
 
     def _pack_index(self, index):
-        rootl = [z64]
+        rootl = [ZERO]
         pindex = fsIndex()
         while rootl:
             oid = rootl.pop()
@@ -1610,7 +1613,7 @@
         nvindex = fsIndex()
 
         ofile = open(self._name + '.pack', 'w+b')
-        pv = z64
+        pv = ZERO
         offset = 0L  # the amount of space freed by packing
         pos = opos = self._metadata_size
         # Copy the metadata from the old file to the new one.
@@ -1770,7 +1773,7 @@
                                  h.vlen, plen))
                 if h.version:
                     if not pnv:
-                        ofile.write(z64)
+                        ofile.write(ZERO)
                     else:
                         if pnv < packpos:
                             # we need to point to the packed non-version rec
@@ -1850,7 +1853,7 @@
     vindex_get=vindex.get
 
     # Initialize,
-    pv=z64
+    pv=ZERO
     p1=opos
     p2=pos
     offset=p2-p1
@@ -1926,7 +1929,7 @@
             write(pack(DATA_HDR,
                        oid,serial,sprev,p64(otpos),vlen,splen))
             if vlen:
-                if not pnv: write(z64)
+                if not pnv: write(ZERO)
                 else:
                     if pnv >= p2: pnv=pnv-offset
                     elif pnv >= p1:
@@ -1992,8 +1995,8 @@
 
 
 
-def Xread_index(file, name, index, vindex, tindex, stop='\377'*8,
-               ltid=z64, start=4L, maxoid=z64, recover=0, read_only=0):
+def Xread_index(file, name, index, vindex, tindex, stop=MAXTID,
+               ltid=ZERO, start=4L, maxoid=ZERO, 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
@@ -2182,7 +2185,7 @@
 
 class FileIterator(FileStorageFormatter):
     """Iterate over the transactions in a FileStorage file."""
-    _ltid = z64
+    _ltid = ZERO
     _file = None
 
     __implements__ = IStorageIterator