[Zodb-checkins] SVN: ZODB/branches/hannosch-pickle-protocol2/src/ZODB/ Use the storage protocol for the indexes

Hanno Schlichting hannosch at hannosch.eu
Sat May 1 09:47:38 EDT 2010


Log message for revision 111824:
  Use the storage protocol for the indexes
  

Changed:
  U   ZODB/branches/hannosch-pickle-protocol2/src/ZODB/FileStorage/FileStorage.py
  U   ZODB/branches/hannosch-pickle-protocol2/src/ZODB/FileStorage/fspack.py
  U   ZODB/branches/hannosch-pickle-protocol2/src/ZODB/fsIndex.py

-=-
Modified: ZODB/branches/hannosch-pickle-protocol2/src/ZODB/FileStorage/FileStorage.py
===================================================================
--- ZODB/branches/hannosch-pickle-protocol2/src/ZODB/FileStorage/FileStorage.py	2010-05-01 13:47:00 UTC (rev 111823)
+++ ZODB/branches/hannosch-pickle-protocol2/src/ZODB/FileStorage/FileStorage.py	2010-05-01 13:47:37 UTC (rev 111824)
@@ -236,7 +236,7 @@
 
     def _newIndexes(self):
         # hook to use something other than builtin dict
-        return fsIndex(), {}
+        return fsIndex(pickle_protocol=self._pickle_protocol), {}
 
     _saved = 0
     def _save_index(self):
@@ -364,13 +364,13 @@
             # Convert dictionary indexes to fsIndexes *or* convert fsIndexes
             # which have a dict `_data` attribute to a new fsIndex (newer
             # fsIndexes have an OOBTree as `_data`).
-            newindex = fsIndex()
+            newindex = fsIndex(pickle_protocol=self._pickle_protocol)
             newindex.update(index)
             index = newindex
             if not self._is_read_only:
                 # Save the converted index.
                 f = open(index_name, 'wb')
-                p = Pickler(f, 1)
+                p = Pickler(f, self._pickle_protocol)
                 info['index'] = index
                 p.dump(info)
                 f.close()

Modified: ZODB/branches/hannosch-pickle-protocol2/src/ZODB/FileStorage/fspack.py
===================================================================
--- ZODB/branches/hannosch-pickle-protocol2/src/ZODB/FileStorage/fspack.py	2010-05-01 13:47:00 UTC (rev 111823)
+++ ZODB/branches/hannosch-pickle-protocol2/src/ZODB/FileStorage/fspack.py	2010-05-01 13:47:37 UTC (rev 111824)
@@ -146,17 +146,19 @@
 
 class GC(FileStorageFormatter):
 
-    def __init__(self, file, eof, packtime, gc, referencesf):
+    def __init__(self, file, eof, packtime, gc, referencesf,
+                 pickle_protocol=1):
         self._file = file
         self._name = file.name
         self.eof = eof
         self.packtime = packtime
         self.gc = gc
+        self._pickle_protocol = pickle_protocol
         # packpos: position of first txn header after pack time
         self.packpos = None
 
         # {oid -> current data record position}:
-        self.oid2curpos = ZODB.fsIndex.fsIndex()
+        self.oid2curpos = ZODB.fsIndex.fsIndex(pickle_protocol=pickle_protocol)
 
         # The set of reachable revisions of each object.
         #
@@ -167,7 +169,7 @@
         # second is a dictionary mapping objects to lists of
         # positions; it is used to handle the same number of objects
         # for which we must keep multiple revisions.
-        self.reachable = ZODB.fsIndex.fsIndex()
+        self.reachable = ZODB.fsIndex.fsIndex(pickle_protocol=pickle_protocol)
         self.reach_ex = {}
 
         # keep ltid for consistency checks during initial scan
@@ -341,6 +343,7 @@
     # progress after it).
     def __init__(self, storage, referencesf, stop, gc=True):
         self._storage = storage
+        self._pickle_protocol = getattr(storage, '_pickle_protocol', 1)
         if storage.blob_dir:
             self.pack_blobs = True
             self.blob_removed = open(
@@ -360,7 +363,8 @@
         self.locked = False
         self.file_end = storage.getSize()
 
-        self.gc = GC(self._file, self.file_end, self._stop, gc, referencesf)
+        self.gc = GC(self._file, self.file_end, self._stop, gc, referencesf,
+                     pickle_protocol=self._pickle_protocol)
 
         # The packer needs to acquire the parent's commit lock
         # during the copying stage, so the two sets of lock acquire
@@ -375,7 +379,8 @@
         # tindex: oid -> pos, for current txn
         # oid2tid: not used by the packer
 
-        self.index = ZODB.fsIndex.fsIndex()
+        self.index = ZODB.fsIndex.fsIndex(
+            pickle_protocol=self._pickle_protocol)
         self.tindex = {}
         self.oid2tid = {}
         self.toid2tid = {}

Modified: ZODB/branches/hannosch-pickle-protocol2/src/ZODB/fsIndex.py
===================================================================
--- ZODB/branches/hannosch-pickle-protocol2/src/ZODB/fsIndex.py	2010-05-01 13:47:00 UTC (rev 111823)
+++ ZODB/branches/hannosch-pickle-protocol2/src/ZODB/fsIndex.py	2010-05-01 13:47:37 UTC (rev 111824)
@@ -65,8 +65,9 @@
 
 class fsIndex(object):
 
-    def __init__(self, data=None):
+    def __init__(self, data=None, pickle_protocol=1):
         self._data = OOBTree()
+        self._pickle_protocol = pickle_protocol
         if data:
             self.update(data)
 
@@ -97,7 +98,7 @@
 
     def save(self, pos, fname):
         with open(fname, 'wb') as f:
-            pickler = cPickle.Pickler(f, 1)
+            pickler = cPickle.Pickler(f, self._pickle_protocol)
             pickler.fast = True
             pickler.dump(pos)
             for k, v in self._data.iteritems():



More information about the Zodb-checkins mailing list