[Checkins] SVN: relstorage/branches/1.1/relstorage/relstorage.py Log more info on KeyError in load(). Also, don't bother caching the object tid just after getting it from the

Shane Hathaway shane at hathawaymix.org
Sat Jul 19 19:38:36 EDT 2008


Log message for revision 88624:
  Log more info on KeyError in load().  Also, don't bother caching the object tid just after getting it from the 
  cache.
  

Changed:
  U   relstorage/branches/1.1/relstorage/relstorage.py

-=-
Modified: relstorage/branches/1.1/relstorage/relstorage.py
===================================================================
--- relstorage/branches/1.1/relstorage/relstorage.py	2008-07-19 21:55:26 UTC (rev 88623)
+++ relstorage/branches/1.1/relstorage/relstorage.py	2008-07-19 23:38:34 UTC (rev 88624)
@@ -233,6 +233,34 @@
         """
         return None
 
+    def _log_keyerror(self, oid_int, reason):
+        """Log just before raising KeyError in load().
+
+        KeyErrors in load() are generally not supposed to happen,
+        so this is a good place to gather information.
+        """
+        cursor = self._load_cursor
+        adapter = self._adapter
+        msg = ["Storage KeyError on oid %d: %s" % (oid_int, reason)]
+        rows = adapter.iter_transactions(cursor)
+        row = None
+        for row in rows:
+            # just get the first row
+            break
+        if not row:
+            msg.append("No transactions exist")
+        else:
+            msg.append("Current transaction is %d" % row[0])
+
+        rows = adapter.iter_object_history(cursor, oid_int)
+        tids = []
+        for row in rows:
+            tids.append(row[0])
+            if len(tids) >= 10:
+                break
+        msg.append("Recent object tids: %s" % repr(tids))
+        log.warning('; '.join(msg))
+
     def load(self, oid, version):
         oid_int = u64(oid)
         cache = self._cache_client
@@ -252,10 +280,11 @@
                 if not cachekey or not tid_int:
                     tid_int = self._adapter.get_current_tid(
                         cursor, oid_int)
+                    if cachekey and tid_int is not None:
+                        cache.set(cachekey, tid_int)
                 if tid_int is None:
+                    self._log_keyerror(oid_int, "no tid found(1)")
                     raise KeyError(oid)
-                if cachekey:
-                    cache.set(cachekey, tid_int)
 
                 # get state from the cache or the database
                 cachekey = 'state:%d:%d' % (oid_int, tid_int)
@@ -275,9 +304,11 @@
             if not state:
                 # This can happen if something attempts to load
                 # an object whose creation has been undone.
+                self._log_keyerror(oid_int, "creation has been undone")
                 raise KeyError(oid)
             return state, p64(tid_int)
         else:
+            self._log_keyerror(oid_int, "no tid found(2)")
             raise KeyError(oid)
 
     def loadEx(self, oid, version):



More information about the Checkins mailing list