[CalendarServer-changes] [6528] CalendarServer/branches/users/glyph/sharedpool

source_changes at macosforge.org source_changes at macosforge.org
Mon Nov 1 14:24:18 PDT 2010


Revision: 6528
          http://trac.macosforge.org/projects/calendarserver/changeset/6528
Author:   glyph at apple.com
Date:     2010-11-01 14:24:15 -0700 (Mon, 01 Nov 2010)
Log Message:
-----------
fix minor bugs, a few clean-ups of unused attributes

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/sharedpool/calendarserver/tap/caldav.py
    CalendarServer/branches/users/glyph/sharedpool/calendarserver/tap/util.py
    CalendarServer/branches/users/glyph/sharedpool/txdav/base/datastore/asyncsqlpool.py
    CalendarServer/branches/users/glyph/sharedpool/txdav/idav.py

Modified: CalendarServer/branches/users/glyph/sharedpool/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/branches/users/glyph/sharedpool/calendarserver/tap/caldav.py	2010-11-01 21:23:50 UTC (rev 6527)
+++ CalendarServer/branches/users/glyph/sharedpool/calendarserver/tap/caldav.py	2010-11-01 21:24:15 UTC (rev 6528)
@@ -76,7 +76,6 @@
 
 from txdav.base.datastore.asyncsqlpool import ConnectionPoolConnection
 
-from calendarserver.tap.util import ConnectionWithPeer
 try:
     from twistedcaldav.authkerb import NegotiateCredentialFactory
     NegotiateCredentialFactory  # pacify pyflakes
@@ -87,6 +86,7 @@
 from calendarserver.accesslog import AMPLoggingFactory
 from calendarserver.accesslog import RotatingFileAccessLoggingObserver
 from calendarserver.tap.util import getRootResource, computeProcessCount
+from calendarserver.tap.util import ConnectionWithPeer
 from calendarserver.tools.util import checkDirectory
 
 try:
@@ -1062,6 +1062,7 @@
         protocol = ConnectionPoolConnection(self.pool)
         transport = ConnectionWithPeer(s, protocol)
         protocol.makeConnection(transport)
+        transport.startReading()
         return c
 
 
@@ -1233,12 +1234,6 @@
     L{Deferred} which fires only when all processes have shut down, to allow
     for a clean service shutdown.
 
-    @ivar _extraFDs: a mapping from process names to extra file-descriptor
-        maps.  (By default, all processes will have the standard stdio mapping,
-        so all file descriptors here should be >2.)  This is updated during
-        L{DelayedStartupProcessMonitor.startService}, by inspecting the result
-        of L{TwistdSlaveProcess.getFileDescriptors}.
-
     @ivar reactor: an L{IReactorProcess} for spawning processes, defaulting to
         the global reactor.
 
@@ -1263,7 +1258,6 @@
         self.timeStarted = {}
         self.murder = {}
         self.restart = {}
-        self._extraFDs = {}
         self.stopping = False
         if config.MultiProcess.StaggeredStartup.Enabled:
             self.delayInterval = config.MultiProcess.StaggeredStartup.Interval

Modified: CalendarServer/branches/users/glyph/sharedpool/calendarserver/tap/util.py
===================================================================
--- CalendarServer/branches/users/glyph/sharedpool/calendarserver/tap/util.py	2010-11-01 21:23:50 UTC (rev 6527)
+++ CalendarServer/branches/users/glyph/sharedpool/calendarserver/tap/util.py	2010-11-01 21:24:15 UTC (rev 6528)
@@ -14,6 +14,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 ##
+
+"""
+Utilities for assembling the service and resource hierarchy.
+"""
+
 __all__ = [
     "getRootResource",
     "FakeRequest",
@@ -84,6 +89,20 @@
 def pgServiceFromConfig(config, subServiceFactory, uid=None, gid=None):
     """
     Construct a L{PostgresService} from a given configuration and subservice.
+
+    @param config: the configuration to derive postgres configuration
+        parameters from.
+
+    @param subServiceFactory: A factory for the service to start once the
+        L{PostgresService} has been initialized.
+
+    @param uid: The user-ID to run the PostgreSQL server as.
+
+    @param gid: The group-ID to run the PostgreSQL server as.
+
+    @return: a service which can start postgres.
+
+    @rtype: L{PostgresService}
     """
     dbRoot = CachingFilePath(config.DatabaseRoot)
     # Construct a PostgresService exactly as the parent would, so that we
@@ -102,11 +121,14 @@
 
 
 class ConnectionWithPeer(Connection):
+
+    connected = True
+
     def getPeer(self):
-        return "<local>"
+        return "<peer: %r %r>" % (self.socket.fileno(), id(self))
 
     def getHost(self):
-        return "<local>"
+        return "<host: %r %r>" % (self.socket.fileno(), id(self))
 
 def storeFromConfig(config, serviceParent, notifierFactory=None):
     """
@@ -121,11 +143,12 @@
         else:
             # TODO: something to do with loseConnection here, maybe?  I don't
             # think it actually needs to be shut down, though.
-            skt = fromfd(AF_UNIX, SOCK_STREAM, config.DBAMPFD)
+            skt = fromfd(int(config.DBAMPFD), AF_UNIX, SOCK_STREAM)
             os.close(config.DBAMPFD)
             protocol = ConnectionPoolClient()
             transport = ConnectionWithPeer(skt, protocol)
             protocol.makeConnection(transport)
+            transport.startReading()
             txnFactory = protocol.newTransaction
         dataStore = CommonSQLDataStore(
             txnFactory, notifierFactory,

Modified: CalendarServer/branches/users/glyph/sharedpool/txdav/base/datastore/asyncsqlpool.py
===================================================================
--- CalendarServer/branches/users/glyph/sharedpool/txdav/base/datastore/asyncsqlpool.py	2010-11-01 21:23:50 UTC (rev 6527)
+++ CalendarServer/branches/users/glyph/sharedpool/txdav/base/datastore/asyncsqlpool.py	2010-11-01 21:24:15 UTC (rev 6528)
@@ -71,7 +71,9 @@
         self._holder.submit(initCursor)
 
 
-    def _reallyExecSQL(self, sql, args=[], raiseOnZeroRowCount=None):
+    def _reallyExecSQL(self, sql, args=None, raiseOnZeroRowCount=None):
+        if args is None:
+            args = []
         self._cursor.execute(sql, args)
         if raiseOnZeroRowCount is not None and self._cursor.rowcount == 0:
             raise raiseOnZeroRowCount()
@@ -175,17 +177,18 @@
     def commit(self):
         if self._complete:
             raise AlreadyFinishedError()
+        self._complete = True
         return self._repoolAfter(super(PooledSqlTxn, self).commit())
 
 
     def abort(self):
         if self._complete:
             raise AlreadyFinishedError()
+        self._complete = True
         return self._repoolAfter(super(PooledSqlTxn, self).abort())
 
 
     def _repoolAfter(self, d):
-        self._complete = True
         def repool(result):
             self._pool.reclaim(self)
             return result
@@ -352,6 +355,7 @@
         """
         super(ConnectionPoolConnection, self).__init__()
         self.pool = pool
+        self._txns = {}
 
 
     @StartTxn.responder
@@ -414,9 +418,9 @@
 
     def newTransaction(self):
         txnid = str(self._nextID())
+        self.callRemote(StartTxn, transactionID=txnid)
         txn = Transaction(client=self, transactionID=txnid)
         self._txns[txnid] = txn
-        self.callRemote(StartTxn, transactionID=txnid)
         return txn
 
 
@@ -428,7 +432,7 @@
 
     @QueryComplete.responder
     def complete(self, queryID, norows):
-        self.queries.pop(queryID).done(norows)
+        self._queries.pop(queryID).done(norows)
         return {}
 
 
@@ -474,29 +478,35 @@
         Initialize a transaction with a L{ConnectionPoolClient} and a unique
         transaction identifier.
         """
-        self.client = client
-        self.transactionID = transactionID
+        self._client = client
+        self._transactionID = transactionID
+        self._completed = False
 
 
-    def execSQL(self, sql, args, raiseOnZeroRowCount=None):
-        queryID = self.client._nextID()
-        d = Deferred()
-        self.client._queries[queryID] = _Query(raiseOnZeroRowCount)
-        self.client.callRemote(ExecSQL, queryID=queryID, sql=sql, args=args)
-        return d
+    def execSQL(self, sql, args=None, raiseOnZeroRowCount=None):
+        if args is None:
+            args = []
+        queryID = str(self._client._nextID())
+        query = self._client._queries[queryID] = _Query(raiseOnZeroRowCount)
+        self._client.callRemote(ExecSQL, queryID=queryID, sql=sql, args=args,
+                                transactionID=self._transactionID)
+        return query.deferred
 
 
-    def complete(self, command):
-        return self.client.callRemote(
-            command, transactionID=self.transactionID
+    def _complete(self, command):
+        if self._completed:
+            raise AlreadyFinishedError()
+        self._completed = True
+        return self._client.callRemote(
+            command, transactionID=self._transactionID
             ).addCallback(lambda x: None)
 
 
     def commit(self):
-        return self.complete(Commit)
+        return self._complete(Commit)
 
 
     def abort(self):
-        return self.complete(Abort)
+        return self._complete(Abort)
 
 

Modified: CalendarServer/branches/users/glyph/sharedpool/txdav/idav.py
===================================================================
--- CalendarServer/branches/users/glyph/sharedpool/txdav/idav.py	2010-11-01 21:23:50 UTC (rev 6527)
+++ CalendarServer/branches/users/glyph/sharedpool/txdav/idav.py	2010-11-01 21:24:15 UTC (rev 6528)
@@ -180,7 +180,7 @@
     it is assumed to have been started.
     """
 
-    def execSQL(sql, args, raiseOnZeroRowCount=None):
+    def execSQL(sql, args=(), raiseOnZeroRowCount=None):
         """
         Execute some SQL.
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20101101/ce9c0c2c/attachment-0001.html>


More information about the calendarserver-changes mailing list