[CalendarServer-changes] [4598] CalendarServer/branches/users/sagen/deployment-inherit-fds-4571/ twistedcaldav/directory/appleopendirectory.py

source_changes at macosforge.org source_changes at macosforge.org
Mon Oct 19 12:15:44 PDT 2009


Revision: 4598
          http://trac.macosforge.org/projects/calendarserver/changeset/4598
Author:   sagen at apple.com
Date:     2009-10-19 12:15:43 -0700 (Mon, 19 Oct 2009)
Log Message:
-----------
Protect against a substantial drop in od results (in case of a temporary od problem)

Modified Paths:
--------------
    CalendarServer/branches/users/sagen/deployment-inherit-fds-4571/twistedcaldav/directory/appleopendirectory.py

Modified: CalendarServer/branches/users/sagen/deployment-inherit-fds-4571/twistedcaldav/directory/appleopendirectory.py
===================================================================
--- CalendarServer/branches/users/sagen/deployment-inherit-fds-4571/twistedcaldav/directory/appleopendirectory.py	2009-10-19 19:09:30 UTC (rev 4597)
+++ CalendarServer/branches/users/sagen/deployment-inherit-fds-4571/twistedcaldav/directory/appleopendirectory.py	2009-10-19 19:15:43 UTC (rev 4598)
@@ -131,7 +131,7 @@
                 cacheDir.createDirectory()
 
             for recordType in self.recordTypes():
-                self.log_debug("Master fetching %s from directory" % (recordType,))
+                self.log_info("Master fetching %s from directory" % (recordType,))
                 cacheFile = cacheDir.child(recordType)
                 try:
                     results = self._queryDirectory(recordType)
@@ -140,17 +140,33 @@
                     continue
 
                 results.sort()
+                numNewResults = len(results)
                 pickled = pickle.dumps(results)
                 needsWrite = True
                 if cacheFile.exists():
                     prevPickled = cacheFile.getContent()
                     if prevPickled == pickled:
                         needsWrite = False
+                    else:
+                        prevResults = pickle.loads(prevPickled)
+                        numPrevResults = len(prevResults)
+                        if numPrevResults == 0:
+                            needsWrite = True
+                        else:
+                            if float(numNewResults) / numPrevResults < 0.5:
+                                # New results is less than half of what it used
+                                # to be -- this indicates we might not have
+                                # gotten back enough records from OD.  Don't
+                                # write out the file, but log an error.
+                                self.log_error("OD results for %s substantially less than last time: was %d, now %d." % (recordType, numPrevResults, numNewResults))
+                                needsWrite = False
+                                continue
+
                 if needsWrite:
-                    self.log_info("Saving cache file for %s" % (recordType,))
+                    self.log_info("Saving cache file for %s (%d items)" % (recordType, numNewResults))
                     cacheFile.setContent(pickled)
                 else:
-                    self.log_debug("%s info hasn't changed" % (recordType,))
+                    self.log_info("%s info hasn't changed" % (recordType,))
 
         def _refreshInThread(self):
             return deferToThread(_refresh, self)
@@ -647,7 +663,7 @@
             try:
                 storage = self._records[recordType]
                 if not forceUpdate and (lastModified <= storage["last modified"]):
-                    self.log_debug("Directory cache file for %s unchanged" % (recordType,))
+                    self.log_info("Directory cache file for %s unchanged" % (recordType,))
                     storage["status"] = "new" # mark this as not stale
                     self._delayedCalls.add(callLater(cacheTimeout, rot))
                     return
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20091019/bd501461/attachment.html>


More information about the calendarserver-changes mailing list