[Checkins] SVN: zc.zodbdgc/branches/jim-dev/src/zc/zodbdgc/__init__.py Try an append-only file rather than bsddb3 tables.

Jim Fulton jim at zope.com
Tue Aug 18 15:42:51 EDT 2009


Log message for revision 102917:
  Try an append-only file rather than bsddb3 tables.
  

Changed:
  U   zc.zodbdgc/branches/jim-dev/src/zc/zodbdgc/__init__.py

-=-
Modified: zc.zodbdgc/branches/jim-dev/src/zc/zodbdgc/__init__.py
===================================================================
--- zc.zodbdgc/branches/jim-dev/src/zc/zodbdgc/__init__.py	2009-08-18 15:17:49 UTC (rev 102916)
+++ zc.zodbdgc/branches/jim-dev/src/zc/zodbdgc/__init__.py	2009-08-18 19:42:50 UTC (rev 102917)
@@ -17,7 +17,6 @@
 import BTrees.OOBTree
 import BTrees.LLBTree
 import base64
-import bsddb3
 import cPickle
 import cStringIO
 import itertools
@@ -34,6 +33,7 @@
 import ZODB.blob
 import ZODB.config
 import ZODB.FileStorage
+import ZODB.fsIndex
 import ZODB.POSException
 import ZODB.TimeStamp
 
@@ -327,26 +327,20 @@
 class Bad:
 
     def __init__(self, names):
+        self._file = tempfile.TemporaryFile(dir='.', prefix='gcbad')
+        self.close = self._file.close
+        self._pos = 0
         self._dbs = {}
-        self._paths = []
         for name in names:
-            fd, path = tempfile.mkstemp(dir='.', prefix='db-'+name.strip()+'-')
-            os.close(fd)
-            self._dbs[name] = bsddb3.hashopen(path, cachesize=1<<24)
-            self._paths.append(path)
+            self._dbs[name] = ZODB.fsIndex.fsIndex()
 
-    def close(self):
-        for db in self._dbs.values():
-            db.close()
-        while self._paths:
-            os.remove(self._paths.pop())
-
     def remove(self, name, oid):
         db = self._dbs[name]
         if oid in db:
             del db[oid]
 
     def __nonzero__(self):
+        raise SystemError('wtf')
         return sum(map(bool, self._dbs.itervalues()))
 
     def has(self, name, oid):
@@ -359,25 +353,35 @@
                 for oid in self._dbs[name]:
                     yield name, oid
         else:
-            for oid, data in self._dbs[name].iteritems():
-                tid = marshal.loads(data)[0]
-                yield oid, tid
+            f = self._file
+            for oid, pos in self._dbs[name].iteritems():
+                f.seek(pos)
+                yield oid, marshal.load(f)[0]
 
     def insert(self, name, oid, tid, refs):
+        f = self._file
         db = self._dbs[name]
-        old = db.get(oid)
-        if old:
-            oldtid, oldrefs = marshal.loads(old)
+        pos = db.get(oid)
+        if pos is not None:
+            f.seek(pos)
+            oldtid, oldrefs = marshal.load(f)
             refs = set(oldrefs).union(refs)
             tid = max(tid, oldtid)
 
-        db[oid] = marshal.dumps((tid, list(refs)))
+        db[oid] = pos = self._pos
+        f.seek(pos)
+        marshal.dump((tid, list(refs)), f)
+        self._pos = f.tell()
 
     def pop(self, name, oid):
-        refs = self._dbs[name].pop(oid, ())
-        if refs:
-            return marshal.loads(refs)[1]
-        return ()
+        db = self._dbs[name]
+        pos = db.get(oid, None)
+        if pos is None:
+            return ()
+        del db[oid]
+        f = self._file
+        f.seek(pos)
+        return marshal.load(f)[1]
 
 
 def check(config, refdb=None):



More information about the Checkins mailing list