[CalendarServer-changes] [11648] CalendarServer/trunk/calendarserver

source_changes at macosforge.org source_changes at macosforge.org
Wed Aug 28 21:46:05 PDT 2013


Revision: 11648
          http://trac.calendarserver.org//changeset/11648
Author:   sagen at apple.com
Date:     2013-08-28 21:46:05 -0700 (Wed, 28 Aug 2013)
Log Message:
-----------
The agent now resets the proxy DB memcacher in case memcached was started or stopped

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tap/caldav.py
    CalendarServer/trunk/calendarserver/tools/gateway.py
    CalendarServer/trunk/calendarserver/tools/util.py

Modified: CalendarServer/trunk/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/caldav.py	2013-08-28 20:45:29 UTC (rev 11647)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py	2013-08-29 04:46:05 UTC (rev 11648)
@@ -63,8 +63,9 @@
 from twext.enterprise.ienterprise import POSTGRES_DIALECT
 from twext.enterprise.ienterprise import ORACLE_DIALECT
 from twext.enterprise.adbapi2 import ConnectionPool
+from twext.enterprise.queue import NonPerformingQueuer
+from twext.enterprise.queue import PeerConnectionPool
 from twext.enterprise.queue import WorkerFactory as QueueWorkerFactory
-from twext.enterprise.queue import PeerConnectionPool
 
 from txdav.common.datastore.sql_tables import schema
 from txdav.common.datastore.upgrade.sql.upgrade import (
@@ -1266,8 +1267,9 @@
         Create an agent service which listens for configuration requests
         """
 
-        # Don't use memcached -- calendar server might take it away at any
-        # moment
+        # Don't use memcached initially -- calendar server might take it away at
+        # any moment.  However, when we run a command through the gateway, it
+        # will conditionally set ClientEnabled at that time.
         def agentPostUpdateHook(configDict, reloading=False):
             configDict.Memcached.Pools.Default.ClientEnabled = False
 
@@ -1285,6 +1287,8 @@
                 dataStoreWatcher = DirectoryChangeListener(reactor,
                     config.DataRoot, DataStoreMonitor(reactor, storageService))
                 dataStoreWatcher.startListening()
+            if store is not None:
+                store.queuer = NonPerformingQueuer()
             return makeAgentService(store)
 
         uid, gid = getSystemIDs(config.UserName, config.GroupName)

Modified: CalendarServer/trunk/calendarserver/tools/gateway.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/gateway.py	2013-08-28 20:45:29 UTC (rev 11647)
+++ CalendarServer/trunk/calendarserver/tools/gateway.py	2013-08-29 04:46:05 UTC (rev 11648)
@@ -30,7 +30,7 @@
 
 from calendarserver.tools.util import (
     principalForPrincipalID, proxySubprincipal, addProxy, removeProxy,
-    ProxyError, ProxyWarning
+    ProxyError, ProxyWarning, autoDisableMemcached
 )
 from calendarserver.tools.principals import getProxies, setProxies, updateRecord
 from calendarserver.tools.purge import WorkerService, PurgeOldEventsService, DEFAULT_BATCH_SIZE, DEFAULT_RETAIN_DAYS
@@ -188,6 +188,22 @@
 
     @inlineCallbacks
     def run(self):
+
+        # This method can be called as the result of an agent request.  We
+        # check to see if memcached is there for each call because the server
+        # could have stopped/started since the last time.
+
+        for pool in config.Memcached.Pools.itervalues():
+            pool.ClientEnabled = True
+        autoDisableMemcached(config)
+
+        from twistedcaldav.directory import calendaruserproxy
+        if calendaruserproxy.ProxyDBService is not None:
+            # Reset the proxy db memcacher because memcached may have come or
+            # gone since the last time through here.
+            # TODO: figure out a better way to do this
+            calendaruserproxy.ProxyDBService._memcacher._memcacheProtocol = None
+
         try:
             for command in self.commands:
                 commandName = command['command']

Modified: CalendarServer/trunk/calendarserver/tools/util.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/util.py	2013-08-28 20:45:29 UTC (rev 11647)
+++ CalendarServer/trunk/calendarserver/tools/util.py	2013-08-29 04:46:05 UTC (rev 11648)
@@ -235,23 +235,21 @@
 
 def autoDisableMemcached(config):
     """
-    If memcached is not running, set config.Memcached.ClientEnabled to False
+    Set ClientEnabled to False for each pool whose memcached is not running
     """
 
-    if not config.Memcached.Pools.Default.ClientEnabled:
-        return
+    for pool in config.Memcached.Pools.itervalues():
+        if pool.ClientEnabled:
+            try:
+                s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+                s.connect((pool.BindAddress, pool.Port))
+                s.close()
 
-    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+            except socket.error:
+                pool.ClientEnabled = False
 
-    try:
-        s.connect((config.Memcached.Pools.Default.BindAddress, config.Memcached.Pools.Default.Port))
-        s.close()
 
-    except socket.error:
-        config.Memcached.Pools.Default.ClientEnabled = False
 
-
-
 def setupMemcached(config):
     #
     # Connect to memcached
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130828/8b4bb418/attachment.html>


More information about the calendarserver-changes mailing list