[CalendarServer-changes] [3992] CalendarServer/branches/users/wsanchez/deployment.mo-cache/ twistedcaldav/memcacheprops.py

source_changes at macosforge.org source_changes at macosforge.org
Sun Apr 12 13:27:01 PDT 2009


Revision: 3992
          http://trac.macosforge.org/projects/calendarserver/changeset/3992
Author:   wsanchez at apple.com
Date:     2009-04-12 13:27:01 -0700 (Sun, 12 Apr 2009)
Log Message:
-----------
More cache logic fixes

Modified Paths:
--------------
    CalendarServer/branches/users/wsanchez/deployment.mo-cache/twistedcaldav/memcacheprops.py

Modified: CalendarServer/branches/users/wsanchez/deployment.mo-cache/twistedcaldav/memcacheprops.py
===================================================================
--- CalendarServer/branches/users/wsanchez/deployment.mo-cache/twistedcaldav/memcacheprops.py	2009-04-12 20:25:40 UTC (rev 3991)
+++ CalendarServer/branches/users/wsanchez/deployment.mo-cache/twistedcaldav/memcacheprops.py	2009-04-12 20:27:01 UTC (rev 3992)
@@ -86,6 +86,23 @@
             self._propertyCache = self._loadCache()
         return self._propertyCache
 
+    def childCache(self, child):
+        path = child.fp.path
+        key = self._keyForPath(path)
+        propertyCache = self.propertyCache()
+
+        try:
+            childCache, token = propertyCache["key"]
+        except KeyError:
+            self.log_debug("No child property cache for %s" % (child,))
+            childCache, token = ({}, None)
+
+            #message = "No child property cache for %s" % (child,)
+            #log.error(message)
+            #raise AssertionError(message)
+
+        return propertyCache, key, childCache, token
+
     def _keyForPath(self, path):
         key = "|".join((
             self.__class__.__name__,
@@ -117,6 +134,17 @@
 
         result = client.gets_multi((key for key, name in keys))
 
+        if self.logger.willLogAtLevel("debug"):
+            if abortIfMissing:
+                missing = "missing "
+            else:
+                missing = ""
+            self.log_debug("Loaded keys for %schildren of %s: %s" % (
+                missing,
+                self.collection,
+                [name for key, name in keys],
+            ))
+
         missing = tuple((
             name for key, name in keys
             if key not in result
@@ -134,7 +162,7 @@
         return result
 
     def _storeCache(self, cache):
-        self.log_error("Storing cache for %s" % (self.collection,))
+        self.log_debug("Storing cache for %s" % (self.collection,))
 
         values = dict((
             (self._keyForPath(path), props)
@@ -171,13 +199,8 @@
         return cache
 
     def setProperty(self, child, property):
-        path = child.fp.path
-        key = self._keyForPath(path)
-        propertyCache = self.propertyCache()
-        childCache, token = propertyCache.get(key, (None, None))
+        propertyCache, key, childCache, token = self.childCache(child)
 
-        assert childCache is not None, "No child cache?"
-
         if childCache.get(property.qname(), None) == property:
             # No changes
             return
@@ -189,7 +212,8 @@
             result = client.set(key, childCache, time=self.cacheTimeout, token=token)
             if not result:
                 delattr(self, "_propertyCache")
-                raise MemcacheError("Unable to set property")
+                raise MemcacheError("Unable to set property %s on %s"
+                                    % (property.sname(), child))
 
             loaded = self._loadCache(childNames=(child.fp.basename(),))
             propertyCache.update(loaded.iteritems())
@@ -206,16 +230,11 @@
         if client is not None:
             result = client.delete(key)
             if not result:
-                raise MemcacheError("Unable to delete property")
+                raise MemcacheError("Unable to flush cache on %s" % (child,))
 
     def deleteProperty(self, child, qname):
-        path = child.fp.path
-        key = self._keyForPath(path)
-        propertyCache = self.propertyCache()
-        childCache, token = propertyCache.get(key, (None, None))
+        propertyCache, key, childCache, token = self.childCache(child)
 
-        assert childCache is not None, "No child cache?"
-
         del childCache[qname]
 
         client = self.memcacheClient()
@@ -223,7 +242,8 @@
             result = client.set(key, childCache, time=self.cacheTimeout, token=token)
             if not result:
                 delattr(self, "_propertyCache")
-                raise MemcacheError("Unable to delete property")
+                raise MemcacheError("Unable to delete property {%s}%s on %s"
+                                    % (qname[0], qname[1], child))
 
             loaded = self._loadCache(childNames=(child.fp.basename(),))
             propertyCache.update(loaded.iteritems())
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20090412/188ef799/attachment-0001.html>


More information about the calendarserver-changes mailing list