[CalendarServer-changes] [8391] CalendarServer/branches/users/glyph/parallel-upgrade/calendarserver/ tap/caldav.py

source_changes at macosforge.org source_changes at macosforge.org
Sat Dec 3 00:39:03 PST 2011


Revision: 8391
          http://trac.macosforge.org/projects/calendarserver/changeset/8391
Author:   glyph at apple.com
Date:     2011-12-03 00:39:03 -0800 (Sat, 03 Dec 2011)
Log Message:
-----------
minor refactor; move subServiceFactoryFactory as a nested function into storageService, since it should never ever be used outside that context

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/parallel-upgrade/calendarserver/tap/caldav.py

Modified: CalendarServer/branches/users/glyph/parallel-upgrade/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/branches/users/glyph/parallel-upgrade/calendarserver/tap/caldav.py	2011-12-03 08:38:54 UTC (rev 8390)
+++ CalendarServer/branches/users/glyph/parallel-upgrade/calendarserver/tap/caldav.py	2011-12-03 08:39:03 UTC (rev 8391)
@@ -907,6 +907,37 @@
 
         @rtype: L{IService}
         """
+        def createSubServiceFactory(dialect=POSTGRES_DIALECT,
+                                    paramstyle='pyformat'):
+            def subServiceFactory(connectionFactory):
+                ms = MultiService()
+                cp = ConnectionPool(connectionFactory, dialect=dialect,
+                                    paramstyle=paramstyle,
+                                    maxConnections=config.MaxDBConnectionsPerPool)
+                cp.setServiceParent(ms)
+                store = storeFromConfig(config, cp.connection)
+                mainService = createMainService(cp, store)
+                upgradeSvc = UpgradeFileSystemFormatService(
+                    config,
+                    UpgradeDatabaseSchemaService.wrapService(
+                        UpgradeDatabaseDataService.wrapService(
+                            UpgradeToDatabaseService.wrapService(
+                                CachingFilePath(config.DocumentRoot),
+                                PostDBImportService(config, store, mainService),
+                                store, uid=uid, gid=gid,
+                                spawner=ConfiguredChildSpawner(
+                                    self, ConnectionDispenser(cp)
+                                ),
+                                parallel=config.MultiProcess.ProcessCount
+                            ),
+                            store, uid=uid, gid=gid
+                        ),
+                        store, uid=uid, gid=gid
+                    )
+                )
+                upgradeSvc.setServiceParent(ms)
+                return ms
+            return subServiceFactory
 
         # FIXME: this is replicating the logic of getDBPool(), except for the
         # part where the pgServiceFromConfig service is actually started here,
@@ -927,22 +958,19 @@
                 # to it.
                 pgserv = pgServiceFromConfig(
                     config,
-                    self.subServiceFactoryFactory(createMainService,
-                        uid=overrideUID, gid=overrideGID),
+                    createSubServiceFactory(),
                     uid=overrideUID, gid=overrideGID
                 )
                 return pgserv
             elif config.DBType == 'postgres':
                 # Connect to a postgres database that is already running.
-                return self.subServiceFactoryFactory(createMainService,
-                    uid=overrideUID, gid=overrideGID)(
-                            pgConnectorFromConfig(config))
+                return createSubServiceFactory()(pgConnectorFromConfig(config))
             elif config.DBType == 'oracle':
                 # Connect to an Oracle database that is already running.
-                return self.subServiceFactoryFactory(createMainService,
-                    uid=overrideUID, gid=overrideGID,
-                    dialect=ORACLE_DIALECT, paramstyle='numeric')(
-                            oracleConnectorFromConfig(config))
+                return createSubServiceFactory(dialect=ORACLE_DIALECT,
+                                               paramstyle='numeric')(
+                    oracleConnectorFromConfig(config)
+                )
             else:
                 raise UsageError("Unknown database type %r" (config.DBType,))
         else:
@@ -950,40 +978,6 @@
             return createMainService(None, store)
 
 
-    def subServiceFactoryFactory(self, createMainService, uid=None, gid=None,
-                                 dialect=POSTGRES_DIALECT,
-                                 paramstyle='pyformat'):
-        def subServiceFactory(connectionFactory):
-            ms = MultiService()
-            cp = ConnectionPool(connectionFactory, dialect=dialect,
-                                paramstyle=paramstyle,
-                                maxConnections=config.MaxDBConnectionsPerPool)
-            cp.setServiceParent(ms)
-            store = storeFromConfig(config, cp.connection)
-            mainService = createMainService(cp, store)
-            upgradeSvc = UpgradeFileSystemFormatService(
-                config,
-                UpgradeDatabaseSchemaService.wrapService(
-                    UpgradeDatabaseDataService.wrapService(
-                        UpgradeToDatabaseService.wrapService(
-                            CachingFilePath(config.DocumentRoot),
-                            PostDBImportService(config, store, mainService),
-                            store, uid=uid, gid=gid,
-                            spawner=ConfiguredChildSpawner(
-                                self, ConnectionDispenser(cp)
-                            ),
-                            parallel=config.MultiProcess.ProcessCount
-                        ),
-                        store, uid=uid, gid=gid
-                    ),
-                    store, uid=uid, gid=gid
-                )
-            )
-            upgradeSvc.setServiceParent(ms)
-            return ms
-        return subServiceFactory
-
-
     def makeService_Combined(self, options):
         """
         Create a master service to coordinate a multi-process configuration,
@@ -1365,7 +1359,8 @@
         # to be correct.
         ("processCount", Integer()),
 
-        ## only needed for request processing
+        ## only needed for request processing, and we're not using this
+        ## facility for that work (yet)
         # ("inheritFDs", ListOf(Integer())),
         # ("inheritSSLFDs", ListOf(Integer())),
         # ("metaFD", String(optional=True)),
@@ -1375,6 +1370,7 @@
     ]
 
 
+
 class ChildConfigurator(AMP):
     """
     Protocol which can configure a child process.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20111203/69a3aa1c/attachment-0001.html>


More information about the calendarserver-changes mailing list