[Zodb-checkins] CVS: ZODB3/Tools - checkbtrees.py:1.1.2.2

Tim Peters tim.one at comcast.net
Tue Sep 2 17:33:50 EDT 2003


Update of /cvs-repository/ZODB3/Tools
In directory cvs.zope.org:/tmp/cvs-serv14143/Tools

Modified Files:
      Tag: ZODB3-3_1-branch
	checkbtrees.py 
Log Message:
Remember the oid of every persistent object seen so far, to stop
unbounded searching in the presence of cycles (reported by Paul Winkler
on zodb-dev).

Also run each BTree found through BTrees.check.check().  That routine
didn't exist at the time checkbtrees.py was written, and finds kinds of
damage the BTrees._check() method can't find.


=== ZODB3/Tools/checkbtrees.py 1.1.2.1 => 1.1.2.2 ===
--- ZODB3/Tools/checkbtrees.py:1.1.2.1	Wed Aug 27 15:23:46 2003
+++ ZODB3/Tools/checkbtrees.py	Tue Sep  2 16:33:49 2003
@@ -3,18 +3,33 @@
 
 usage: checkbtrees.py data.fs
 
-Try to find all the BTrees in a Data.fs and call their _check() methods.
+Try to find all the BTrees in a Data.fs, call their _check() methods,
+and run them through BTrees.check.check().
 """
 
 from types import IntType
 
 import ZODB
 from ZODB.FileStorage import FileStorage
+from BTrees.check import check
+
+# Set of oids we've already visited.  Since the object structure is
+# a general graph, this is needed to prevent unbounded paths in the
+# presence of cycles.  It's also helpful in eliminating redundant
+# checking when a BTree is pointed to by many objects.
+oids_seen = {}
+
+# Append (obj, path) to L if and only if obj is a persistent object
+# and we haven't seen it before.
+def add_if_new_persistent(L, obj, path):
+    global oids_seen
 
-def add_if_persistent(L, obj, path):
     getattr(obj, '_', None) # unghostify
     if hasattr(obj, '_p_oid'):
-        L.append((obj, path))
+        oid = obj._p_oid
+        if not oids_seen.has_key(oid):
+            L.append((obj, path))
+            oids_seen[oid] = 1
 
 def get_subobjects(obj):
     getattr(obj, '_', None) # unghostify
@@ -54,7 +69,7 @@
     cn = ZODB.DB(fs).open()
     rt = cn.root()
     todo = []
-    add_if_persistent(todo, rt, '')
+    add_if_new_persistent(todo, rt, '')
 
     found = 0
     while todo:
@@ -75,6 +90,13 @@
                     print msg
                     print "*" * 60
 
+                try:
+                    check(obj)
+                except AssertionError, msg:
+                    print "*" * 60
+                    print msg
+                    print "*" * 60
+
         if found % 100 == 0:
             cn.cacheMinimize()
 
@@ -84,7 +106,7 @@
                 newpath = "%s%s" % (path, k)
             else:
                 newpath = "%s.%s" % (path, k)
-            add_if_persistent(todo, v, newpath)
+            add_if_new_persistent(todo, v, newpath)
 
     print "total", len(fs._index), "found", found
 




More information about the Zodb-checkins mailing list