[CalendarServer-changes] [6520] CalendarServer/branches/users/glyph/sharedpool/calendarserver/tap
source_changes at macosforge.org
source_changes at macosforge.org
Mon Nov 1 14:21:04 PDT 2010
Revision: 6520
http://trac.macosforge.org/projects/calendarserver/changeset/6520
Author: glyph at apple.com
Date: 2010-11-01 14:21:00 -0700 (Mon, 01 Nov 2010)
Log Message:
-----------
sql connection dispenser
Modified Paths:
--------------
CalendarServer/branches/users/glyph/sharedpool/calendarserver/tap/caldav.py
CalendarServer/branches/users/glyph/sharedpool/calendarserver/tap/util.py
Modified: CalendarServer/branches/users/glyph/sharedpool/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/branches/users/glyph/sharedpool/calendarserver/tap/caldav.py 2010-11-01 21:20:40 UTC (rev 6519)
+++ CalendarServer/branches/users/glyph/sharedpool/calendarserver/tap/caldav.py 2010-11-01 21:21:00 UTC (rev 6520)
@@ -43,6 +43,7 @@
from twisted.internet.defer import gatherResults
from twisted.internet import reactor
from twisted.internet.reactor import addSystemEventTrigger
+from twisted.internet.tcp import Connection
from twisted.internet.process import ProcessExitedAlready
from twisted.internet.protocol import Protocol, Factory
from twisted.application.internet import TCPServer, UNIXServer
@@ -69,8 +70,13 @@
from twistedcaldav.mail import IMIPReplyInboxResource
from twistedcaldav.stdconfig import DEFAULT_CONFIG, DEFAULT_CONFIG_FILE
from twistedcaldav.upgrade import upgradeData
+from txdav.base.datastore.subpostgres import PostgresService
from calendarserver.tap.util import pgServiceFromConfig
+from txdav.base.datastore.asyncsqlpool import ConnectionPool
+
+from txdav.base.datastore.asyncsqlpool import ConnectionPoolConnection
+
try:
from twistedcaldav.authkerb import NegotiateCredentialFactory
NegotiateCredentialFactory # pacify pyflakes
@@ -805,8 +811,16 @@
monitor = DelayedStartupProcessMonitor()
s.processMonitor = monitor
- self.storageService(monitor, uid, gid).setServiceParent(s)
+ ssvc = self.storageService(monitor, uid, gid)
+ ssvc.setServiceParent(s)
+ if isinstance(ssvc, PostgresService):
+ # TODO: better way of doing this conditional. Look at the config
+ # again, possibly?
+ dispenser = ConnectionDispenser(ssvc.produceConnection)
+ else:
+ dispenser = None
+
parentEnv = {
"PATH": os.environ.get("PATH", ""),
"PYTHONPATH": os.environ.get("PYTHONPATH", ""),
@@ -895,6 +909,8 @@
else:
extraArgs = dict(inheritFDs=inheritFDs,
inheritSSLFDs=inheritSSLFDs)
+ if dispenser is not None:
+ extraArgs.update(ampSQLDispenser=dispenser)
process = TwistdSlaveProcess(
sys.argv[0],
self.tapname,
@@ -1027,6 +1043,25 @@
+class ConnectionDispenser(object):
+
+ def __init__(self, connectionFactory):
+ self.pool = ConnectionPool(connectionFactory)
+
+
+ def dispense(self):
+ """
+ Dispense a file descriptor, already connected to a server, for a
+ client.
+ """
+ c, s = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
+ protocol = ConnectionPoolConnection(self.pool)
+ transport = Connection(s, protocol)
+ protocol.makeConnection(transport)
+ return c
+
+
+
class TwistdSlaveProcess(object):
"""
A L{TwistdSlaveProcess} is information about how to start a slave process
@@ -1060,16 +1095,15 @@
@type metaSocket: L{socket.socket}
- @ivar ampDBSocket: an AF_UNIX/SOCK_STREAM socket that is to be inherited by
- subprocesses and used for sending AMP SQL commands back to its parent.
-
- @type ampDBSocket: L{socket.socket}
+ @ivar ampSQLDispenser: a factory for AF_UNIX/SOCK_STREAM sockets that are
+ to be inherited by subprocesses and used for sending AMP SQL commands
+ back to its parent.
"""
prefix = "caldav"
def __init__(self, twistd, tapname, configFile, id, interfaces,
inheritFDs=None, inheritSSLFDs=None, metaSocket=None,
- ampDBSocket=None):
+ ampSQLDispenser=None):
self.twistd = twistd
@@ -1087,8 +1121,9 @@
self.inheritSSLFDs = emptyIfNone(inheritSSLFDs)
self.metaSocket = metaSocket
self.interfaces = interfaces
- self.ampDBSocket = ampDBSocket
+ self.ampSQLDispenser = ampSQLDispenser
+
def getName(self):
return '%s-%s' % (self.prefix, self.id)
@@ -1100,9 +1135,11 @@
"""
fds = {}
extraFDs = []
- for it in [self.metaSocket, self.ampDBSocket]:
- if it is not None:
- extraFDs.append(it.fileno())
+ if self.metaSocket is not None:
+ extraFDs.append(self.metaSocket.fileno())
+ if self.ampSQLDispenser is not None:
+ skt = self.ampSQLDispenser()
+ extraFDs.append(skt.fileno())
for fd in self.inheritSSLFDs + self.inheritFDs + extraFDs:
fds[fd] = fd
return fds
Modified: CalendarServer/branches/users/glyph/sharedpool/calendarserver/tap/util.py
===================================================================
--- CalendarServer/branches/users/glyph/sharedpool/calendarserver/tap/util.py 2010-11-01 21:20:40 UTC (rev 6519)
+++ CalendarServer/branches/users/glyph/sharedpool/calendarserver/tap/util.py 2010-11-01 21:21:00 UTC (rev 6520)
@@ -22,7 +22,7 @@
import errno
import os
from time import sleep
-from socket import fromfd
+from socket import fromfd, AF_UNIX, SOCK_STREAM
from twext.python.filepath import CachingFilePath as FilePath
from twext.python.log import Logger
@@ -115,7 +115,8 @@
else:
# TODO: something to do with loseConnection here, maybe? I don't
# think it actually needs to be shut down, though.
- skt = fromfd(config.DBAMPFD)
+ skt = fromfd(AF_UNIX, SOCK_STREAM, config.DBAMPFD)
+ os.close(config.DBAMPFD)
protocol = ConnectionPoolClient()
transport = Connection(skt, protocol) # XXX may need subclass for
# getPeer and getHost
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20101101/04065930/attachment-0001.html>
More information about the calendarserver-changes
mailing list