[Zodb-checkins] CVS: ZODB3/Tools - fsrefs.py:1.3

Jeremy Hylton jeremy@zope.com
Wed, 16 Oct 2002 16:48:04 -0400


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

Modified Files:
	fsrefs.py 
Log Message:
Also track objects in the storage that can't be loaded.

This change is an untested improvement.  If some object is in the
index but unloadable for some reason, report it along with the
traceback.  When possible, report what objects refer to the
un-loadable one.


=== ZODB3/Tools/fsrefs.py 1.2 => 1.3 ===
--- ZODB3/Tools/fsrefs.py:1.2	Wed Oct 16 14:38:41 2002
+++ ZODB3/Tools/fsrefs.py	Wed Oct 16 16:48:03 2002
@@ -29,6 +29,7 @@
 
 import cPickle
 import cStringIO
+import traceback
 import types
 
 def get_refs(pickle):
@@ -49,24 +50,38 @@
     ts = TimeStamp(serial)
     print "oid %s %s.%s" % (hex(u64(oid)), from_mod, from_class)
     print "last updated: %s, tid=%s" % (ts, hex(u64(serial)))
-    print "refers to unknown object%s:" % plural
-    for oid, info in missing:
+    print "refers to invalid object%s:" % plural
+    for oid, info, reason in missing:
         if isinstance(info, types.TupleType):
             description = "%s.%s" % info
         else:
             description = str(info)
-        print "\toid %s: %s" % (hex(u64(oid)), description)
+        print "\toid %s %s: %s" % (hex(u64(oid)), reason, description)
     print
 
 def main(path):
     fs = FileStorage(path, read_only=1)
+    noload = {}
     for oid in fs._index.keys():
-        data, serial = fs.load(oid, "")
+        try:
+            data, serial = fs.load(oid, "")
+        except:
+            print "oid %s failed to load" % hex(u64(oid))
+            traceback.print_exc()
+            noload[oid] = 1
+
+            # XXX If we get here after we've already loaded objects
+            # that refer to this one, we won't get error reports from
+            # them.  We could fix this by making two passes over the
+            # storage, but that seems like overkill.
+            
         refs = get_refs(data)
-        missing = []
+        missing = [] # contains 3-tuples of oid, klass-metadata, reason 
         for ref, klass in refs:
             if not fs._index.has_key(ref):
-                missing.append((ref, klass))
+                missing.append((ref, klass, "missing"))
+            if noload.has_key(ref):
+                missing.append((ref, klass, "failed to load"))
         if missing:
             report(oid, data, serial, fs, missing)