[CalendarServer-changes] [8172] CalendarServer/branches/users/glyph/shared-pool-take2/twext/ enterprise

source_changes at macosforge.org source_changes at macosforge.org
Mon Oct 10 08:05:31 PDT 2011


Revision: 8172
          http://trac.macosforge.org/projects/calendarserver/changeset/8172
Author:   glyph at apple.com
Date:     2011-10-10 08:05:31 -0700 (Mon, 10 Oct 2011)
Log Message:
-----------
these commands really shouldn't encounter any errors - we should fix all the ones we encounter.  but, in case they do, they should never cause the shared pool connection to get dropped as a result.

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/shared-pool-take2/twext/enterprise/adbapi2.py
    CalendarServer/branches/users/glyph/shared-pool-take2/twext/enterprise/test/test_adbapi2.py

Modified: CalendarServer/branches/users/glyph/shared-pool-take2/twext/enterprise/adbapi2.py
===================================================================
--- CalendarServer/branches/users/glyph/shared-pool-take2/twext/enterprise/adbapi2.py	2011-10-10 15:05:19 UTC (rev 8171)
+++ CalendarServer/branches/users/glyph/shared-pool-take2/twext/enterprise/adbapi2.py	2011-10-10 15:05:31 UTC (rev 8172)
@@ -1050,12 +1050,42 @@
 
 
 
+class FailsafeException(Exception):
+    """
+    Exception raised by all responders.
+    """
 
+
+
+quashErrors = {
+    FailsafeException: "SOMETHING_UNKNOWN"
+}
+
+
+
+def failsafeResponder(command):
+    def wrap(inner):
+        @inlineCallbacks
+        def innerinner(*a, **k):
+            try:
+                val = yield inner(*a, **k)
+            except:
+                log.err(Failure(),
+                        "shared database connection pool encountered error")
+                raise FailsafeException()
+            else:
+                returnValue(val)
+        return command.responder(innerinner)
+    return wrap
+
+
+
 class StartTxn(Command):
     """
     Start a transaction, identified with an ID generated by the client.
     """
     arguments = txnarg()
+    errors = quashErrors
 
 
 
@@ -1067,6 +1097,7 @@
                  ('queryID', String()),
                  ('args', Pickle()),
                  ('blockID', String())] + txnarg()
+    errors = quashErrors
 
 
 
@@ -1075,6 +1106,7 @@
     Create a new SQL command block.
     """
     arguments = [("blockID", String())] + txnarg()
+    errors = quashErrors
 
 
 
@@ -1083,6 +1115,7 @@
     Create a new SQL command block.
     """
     arguments = [("blockID", String())] + txnarg()
+    errors = quashErrors
 
 
 
@@ -1094,6 +1127,7 @@
 
     arguments = [('queryID', String()),
                  ('row', Pickle())]
+    errors = quashErrors
 
 
 
@@ -1105,16 +1139,19 @@
     arguments = [('queryID', String()),
                  ('norows', Boolean()),
                  ('derived', Pickle())]
+    errors = quashErrors
 
 
 
 class Commit(Command):
     arguments = txnarg()
+    errors = quashErrors
 
 
 
 class Abort(Command):
     arguments = txnarg()
+    errors = quashErrors
 
 
 
@@ -1141,6 +1178,10 @@
         self._blocks = {}
 
 
+    def stopReceivingBoxes(self, why):
+        log.msg("(S) Stopped receiving boxes: " + why.getTraceback())
+
+
     def unhandledError(self, failure):
         """
         An unhandled error has occurred.  Since we can't really classify errors
@@ -1149,25 +1190,25 @@
         log.err(failure, "Shared connection pool server encountered an error.")
 
 
-    @StartTxn.responder
+    @failsafeResponder(StartTxn)
     def start(self, transactionID):
         self._txns[transactionID] = self.pool.connection()
         return {}
 
 
-    @StartBlock.responder
+    @failsafeResponder(StartBlock)
     def startBlock(self, transactionID, blockID):
         self._blocks[blockID] = self._txns[transactionID].commandBlock()
         return {}
 
 
-    @EndBlock.responder
+    @failsafeResponder(EndBlock)
     def endBlock(self, transactionID, blockID):
         self._blocks[blockID].end()
         return {}
 
 
-    @ExecSQL.responder
+    @failsafeResponder(ExecSQL)
     @inlineCallbacks
     def receivedSQL(self, transactionID, queryID, sql, args, blockID):
         derived = None
@@ -1202,7 +1243,7 @@
         return thunk(txn).addCallback(lambda ignored: {})
 
 
-    @Commit.responder
+    @failsafeResponder(Commit)
     def commit(self, transactionID):
         """
         Successfully complete the given transaction.
@@ -1212,7 +1253,7 @@
         return self._complete(transactionID, commitme)
 
 
-    @Abort.responder
+    @failsafeResponder(Abort)
     def abort(self, transactionID):
         """
         Roll back the given transaction.
@@ -1246,6 +1287,10 @@
         log.err(failure, "Shared connection pool client encountered an error.")
 
 
+    def stopReceivingBoxes(self, why):
+        log.msg("(C) Stopped receiving boxes: " + why.getTraceback())
+
+
     def newTransaction(self):
         """
         Create a new networked provider of L{IAsyncTransaction}.
@@ -1262,13 +1307,13 @@
         return txn
 
 
-    @Row.responder
+    @failsafeResponder(Row)
     def row(self, queryID, row):
         self._queries[queryID].row(row)
         return {}
 
 
-    @QueryComplete.responder
+    @failsafeResponder(QueryComplete)
     def complete(self, queryID, norows, derived):
         self._queries.pop(queryID).done(norows, derived)
         return {}

Modified: CalendarServer/branches/users/glyph/shared-pool-take2/twext/enterprise/test/test_adbapi2.py
===================================================================
--- CalendarServer/branches/users/glyph/shared-pool-take2/twext/enterprise/test/test_adbapi2.py	2011-10-10 15:05:19 UTC (rev 8171)
+++ CalendarServer/branches/users/glyph/shared-pool-take2/twext/enterprise/test/test_adbapi2.py	2011-10-10 15:05:31 UTC (rev 8172)
@@ -25,8 +25,6 @@
 
 from twisted.python.threadpool import ThreadPool
 
-from twisted.protocols.amp import UnknownRemoteError
-
 from twisted.trial.unittest import TestCase
 
 from twisted.internet.defer import execute
@@ -44,6 +42,7 @@
 from twext.enterprise.ienterprise import IAsyncTransaction
 from twext.enterprise.ienterprise import POSTGRES_DIALECT
 from twext.enterprise.ienterprise import ICommandBlock
+from twext.enterprise.adbapi2 import FailsafeException
 from twext.enterprise.adbapi2 import ConnectionPool
 
 
@@ -1388,7 +1387,7 @@
         L{UnknownRemoteError}.
         """
         self.flushLoggedErrors(err)
-        return UnknownRemoteError
+        return FailsafeException
 
 
     def resultOf(self, it):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20111010/b035709a/attachment-0001.html>


More information about the calendarserver-changes mailing list