[CalendarServer-changes] [6427] CalendarServer/trunk/txdav/base/datastore/subpostgres.py
source_changes at macosforge.org
source_changes at macosforge.org
Thu Oct 14 13:15:47 PDT 2010
Revision: 6427
http://trac.macosforge.org/projects/calendarserver/changeset/6427
Author: sagen at apple.com
Date: 2010-10-14 13:15:46 -0700 (Thu, 14 Oct 2010)
Log Message:
-----------
Rather than register another system event trigger for gracefully shutting down, enhance stopService to wait for db initialization to complete.
Modified Paths:
--------------
CalendarServer/trunk/txdav/base/datastore/subpostgres.py
Modified: CalendarServer/trunk/txdav/base/datastore/subpostgres.py
===================================================================
--- CalendarServer/trunk/txdav/base/datastore/subpostgres.py 2010-10-14 20:11:58 UTC (rev 6426)
+++ CalendarServer/trunk/txdav/base/datastore/subpostgres.py 2010-10-14 20:15:46 UTC (rev 6427)
@@ -245,13 +245,11 @@
self.resetSchema = resetSchema
# In order to delay a shutdown until database initialization has
- # completed, we register a before-shutdown callback. This callback
- # returns immediately if we're not in the critical code, and returns
- # a deferred if we are. That deferred gets fired once database init
- # is complete and shutdown can proceed.
+ # completed, our stopService( ) examines the delayedShutdown flag.
+ # If True, we wait on the shutdownDeferred to fire before proceeding.
+ # The deferred gets fired once database init is complete.
self.delayedShutdown = False # set to True when in critical code
self.shutdownDeferred = None # the actual deferred
- reactor.addSystemEventTrigger("before", "shutdown", self.shutdownCallback)
# Options from config
self.databaseName = databaseName
@@ -279,16 +277,6 @@
self.monitor = None
self.openConnections = []
- def shutdownCallback(self):
- """
- Callback registered for before-reactor-shutdown. Returns immediately
- if delayedShutdown is False. Returns a deferred if delayedShutdown
- is True.
- """
- if self.delayedShutdown:
- self.shutdownDeferred = Deferred()
- return self.shutdownDeferred
-
def activateDelayedShutdown(self):
"""
Call this when starting database initialization code to protect against
@@ -384,9 +372,10 @@
connection = self.produceConnection()
cursor = connection.cursor()
- self.subServiceFactory(self.produceConnection).setServiceParent(self)
+ if self.shutdownDeferred is None:
+ # Only continue startup if we've not begun shutdown
+ self.subServiceFactory(self.produceConnection).setServiceParent(self)
-
def pauseMonitor(self):
"""
Pause monitoring. This is a testing hook for when (if) we are
@@ -490,10 +479,16 @@
"""
Stop all child services, then stop the subprocess, if it's running.
"""
- d = MultiService.stopService(self)
+
+ if self.delayedShutdown:
+ # We're still in the process of initializing the database, so
+ # delay shutdown until the shutdownDeferred fires.
+ d = self.shutdownDeferred = Deferred()
+ d.addCallback(lambda ignored: MultiService.stopService(self))
+ else:
+ d = MultiService.stopService(self)
+
def superStopped(result):
- # Probably want to stop and wait for startup if that hasn't
- # completed yet...
monitor = _PostgresMonitor()
pg_ctl = which("pg_ctl")[0]
reactor.spawnProcess(monitor, pg_ctl,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20101014/ee29b201/attachment.html>
More information about the calendarserver-changes
mailing list