[CalendarServer-changes] [6732] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Wed Jan 12 21:48:19 PST 2011
Revision: 6732
http://trac.macosforge.org/projects/calendarserver/changeset/6732
Author: glyph at apple.com
Date: 2011-01-12 21:48:12 -0800 (Wed, 12 Jan 2011)
Log Message:
-----------
Turn off shared connection pooling (by default), and instead create a pool per slave process; also, log connection-failure tracebacks.
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tap/caldav.py
CalendarServer/trunk/calendarserver/tap/util.py
CalendarServer/trunk/twistedcaldav/stdconfig.py
CalendarServer/trunk/txdav/base/datastore/asyncsqlpool.py
Modified: CalendarServer/trunk/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/caldav.py 2011-01-11 22:25:49 UTC (rev 6731)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py 2011-01-13 05:48:12 UTC (rev 6732)
@@ -72,11 +72,9 @@
from twistedcaldav.upgrade import upgradeData
from calendarserver.tap.util import pgServiceFromConfig
+
from txdav.base.datastore.asyncsqlpool import ConnectionPool
-
from txdav.base.datastore.asyncsqlpool import ConnectionPoolConnection
-from txdav.base.datastore.dbapiclient import DBAPIConnector
-from txdav.base.datastore.dbapiclient import postgresPreflight
try:
from twistedcaldav.authkerb import NegotiateCredentialFactory
@@ -91,6 +89,7 @@
from calendarserver.tap.util import ConnectionWithPeer
from calendarserver.tap.util import storeFromConfig
from calendarserver.tap.util import transactionFactoryFromFD
+from calendarserver.tap.util import pgConnectorFromConfig
from calendarserver.tools.util import checkDirectory
try:
@@ -627,16 +626,33 @@
L{makeService_Combined}, which does the work of actually handling
CalDAV and CardDAV requests.
"""
+ pool = None
if config.DBAMPFD:
txnFactory = transactionFactoryFromFD(int(config.DBAMPFD))
elif not config.UseDatabase:
txnFactory = None
+ elif not config.SharedConnectionPool:
+ if config.DBType == '':
+ # get a PostgresService to tell us what the local connection
+ # info is, but *don't* start it (that would start one postgres
+ # master per slave, resulting in all kinds of mayhem...)
+ connectionFactory = pgServiceFromConfig(
+ config, None).produceConnection
+ elif config.DBType == 'postgres':
+ connectionFactory = pgConnectorFromConfig(config)
+ else:
+ raise UsageError("unknown DB type: %r" % (config.DBType,))
+ pool = ConnectionPool(connectionFactory)
+ txnFactory = pool.connection
else:
raise UsageError(
"trying to use DB in slave, but no connection info from parent"
)
store = storeFromConfig(config, txnFactory)
- return self.requestProcessingService(options, store)
+ result = self.requestProcessingService(options, store)
+ if pool is not None:
+ pool.setServiceParent(result)
+ return result
def requestProcessingService(self, options, store):
@@ -911,11 +927,9 @@
return pgserv
elif config.DBType == 'postgres':
# Connect to a postgres database that is already running.
- import pgdb
return self.subServiceFactoryFactory(createMainService,
uid=overrideUID, gid=overrideGID)(
- DBAPIConnector(
- pgdb, postgresPreflight, config.DSN).connect)
+ pgConnectorFromConfig(config))
else:
raise UsageError("Unknown database type %r" (config.DBType,))
else:
@@ -1083,7 +1097,8 @@
# filesystem to the database (if that's necessary, and there is
# filesystem data in need of upgrading).
def spawnerSvcCreator(pool, store):
- if pool is not None:
+ if pool is not None and config.SharedConnectionPool:
+ self.log_warn("Using Shared Connection Pool")
dispenser = ConnectionDispenser(pool)
else:
dispenser = None
Modified: CalendarServer/trunk/calendarserver/tap/util.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/util.py 2011-01-11 22:25:49 UTC (rev 6731)
+++ CalendarServer/trunk/calendarserver/tap/util.py 2011-01-13 05:48:12 UTC (rev 6732)
@@ -67,7 +67,11 @@
NegotiateCredentialFactory # pacify pyflakes
except ImportError:
NegotiateCredentialFactory = None
+
from txdav.base.datastore.asyncsqlpool import ConnectionPoolClient
+from txdav.base.datastore.dbapiclient import DBAPIConnector
+from txdav.base.datastore.dbapiclient import postgresPreflight
+from txdav.base.datastore.subpostgres import PostgresService
from calendarserver.accesslog import DirectoryLogWrapperResource
from calendarserver.provision.root import RootResource
@@ -77,7 +81,6 @@
from txdav.common.datastore.sql import CommonDataStore as CommonSQLDataStore
from txdav.common.datastore.file import CommonDataStore as CommonFileDataStore
from txdav.common.datastore.sql import v1_schema
-from txdav.base.datastore.subpostgres import PostgresService
from twext.python.filepath import CachingFilePath
from urllib import quote
@@ -119,6 +122,16 @@
)
+
+def pgConnectorFromConfig(config):
+ """
+ Create a postgres DB-API connector from the given configuration.
+ """
+ import pgdb
+ return DBAPIConnector(pgdb, postgresPreflight, config.DSN).connect
+
+
+
class ConnectionWithPeer(Connection):
connected = True
@@ -143,7 +156,6 @@
return protocol.newTransaction
-# txnFacSub(int(config.DBAMPFD))
def storeFromConfig(config, txnFactory):
"""
Modified: CalendarServer/trunk/twistedcaldav/stdconfig.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/stdconfig.py 2011-01-11 22:25:49 UTC (rev 6731)
+++ CalendarServer/trunk/twistedcaldav/stdconfig.py 2011-01-13 05:48:12 UTC (rev 6732)
@@ -172,6 +172,10 @@
# as an AMP connection over a UNIX socket; see
# txdav.base.datastore.asyncsqlpool.
+ "SharedConnectionPool" : False, # Use a shared database connection pool in
+ # the master process, rather than having
+ # each client make its connections directly.
+
#
# Types of service provided
#
Modified: CalendarServer/trunk/txdav/base/datastore/asyncsqlpool.py
===================================================================
--- CalendarServer/trunk/txdav/base/datastore/asyncsqlpool.py 2011-01-11 22:25:49 UTC (rev 6731)
+++ CalendarServer/trunk/txdav/base/datastore/asyncsqlpool.py 2011-01-13 05:48:12 UTC (rev 6732)
@@ -43,6 +43,7 @@
from twisted.python.components import proxyForInterface
+
class BaseSqlTxn(object):
"""
L{IAsyncTransaction} implementation based on a L{ThreadHolder} in the
@@ -56,8 +57,10 @@
2.0 connection.
"""
self._completed = False
+ self._cursor = None
self._holder = ThreadHolder(reactor)
self._holder.start()
+
def initCursor():
# support threadlevel=1; we can't necessarily cursor() in a
# different thread than we do transactions in.
@@ -71,7 +74,7 @@
# Note: no locking necessary here; since this gets submitted first, all
# subsequent submitted work-units will be in line behind it and the
# cursor will already have been initialized.
- self._holder.submit(initCursor)
+ self._holder.submit(initCursor).addErrback(log.err)
def _reallyExecSQL(self, sql, args=None, raiseOnZeroRowCount=None):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110112/1bffd383/attachment.html>
More information about the calendarserver-changes
mailing list