[CalendarServer-changes] [15465] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Tue Mar 1 11:40:29 PST 2016


Revision: 15465
          http://trac.calendarserver.org//changeset/15465
Author:   cdaboo at apple.com
Date:     2016-03-01 11:40:29 -0800 (Tue, 01 Mar 2016)
Log Message:
-----------
Add TxnTimeoutSeconds options to config.Postgres settings.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tap/util.py
    CalendarServer/trunk/twistedcaldav/stdconfig.py
    CalendarServer/trunk/txdav/base/datastore/dbapiclient.py
    CalendarServer/trunk/txdav/base/datastore/subpostgres.py

Modified: CalendarServer/trunk/calendarserver/tap/util.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/util.py	2016-02-15 19:56:54 UTC (rev 15464)
+++ CalendarServer/trunk/calendarserver/tap/util.py	2016-03-01 19:40:29 UTC (rev 15465)
@@ -151,6 +151,7 @@
         socketDir=config.Postgres.SocketDirectory,
         socketName=config.Postgres.SocketName,
         listenAddresses=config.Postgres.ListenAddresses,
+        txnTimeoutSeconds=config.Postgres.TxnTimeoutSeconds,
         sharedBuffers=config.Postgres.SharedBuffers,
         maxConnections=config.Postgres.MaxConnections,
         options=config.Postgres.Options,

Modified: CalendarServer/trunk/twistedcaldav/stdconfig.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/stdconfig.py	2016-02-15 19:56:54 UTC (rev 15464)
+++ CalendarServer/trunk/twistedcaldav/stdconfig.py	2016-03-01 19:40:29 UTC (rev 15465)
@@ -1017,6 +1017,7 @@
         "SocketDirectory": "",
         "SocketName": "",
         "ListenAddresses": [],
+        "TxnTimeoutSeconds": 30, # Time out transactions
         "SharedBuffers": 0, # BuffersToConnectionsRatio * MaxConnections
                             # Note: don't set this, it will be computed dynamically
                             # See _updateMultiProcess( ) below for details

Modified: CalendarServer/trunk/txdav/base/datastore/dbapiclient.py
===================================================================
--- CalendarServer/trunk/txdav/base/datastore/dbapiclient.py	2016-02-15 19:56:54 UTC (rev 15464)
+++ CalendarServer/trunk/txdav/base/datastore/dbapiclient.py	2016-03-01 19:40:29 UTC (rev 15465)
@@ -199,7 +199,7 @@
     are then used to create the actual parameters for each module.
     """
 
-    def __init__(self, endpoint=None, user=None, password=None, database=None):
+    def __init__(self, endpoint=None, user=None, password=None, database=None, **kwargs):
         """
         @param endpoint: endpoint string describing the connection
         @type endpoint: L{str}
@@ -250,7 +250,7 @@
     def connect(self, label="<unlabeled>"):
         connection = self.dbModule.connect(*self.connectArgs, **self.connectKw)
         w = self.wrapper(connection, label)
-        self.preflight(w)
+        self.preflight(w, **self.connectKw)
         return w
 
 
@@ -289,6 +289,8 @@
         dbkwargs = {}
         if params.port:
             dbkwargs["host"] = "{}:{}".format(params.host, params.port)
+        if "txnTimeoutSeconds" in kwargs:
+            dbkwargs["txnTimeoutSeconds"] = kwargs["txnTimeoutSeconds"]
         return DBAPIConnector(postgres, postgresPreflight, dsn, **dbkwargs)
 
 
@@ -322,6 +324,8 @@
             dbkwargs["host"] = params.host
             if params.port:
                 dbkwargs["port"] = int(params.port)
+        if "txnTimeoutSeconds" in kwargs:
+            dbkwargs["txnTimeoutSeconds"] = kwargs["txnTimeoutSeconds"]
         return DBAPIConnector(dbmodule, pg8000Preflight, **dbkwargs)
 
 
@@ -358,7 +362,7 @@
 
 
 
-def oraclePreflight(connection):
+def oraclePreflight(connection, **kwargs):
     """
     Pre-flight function for Oracle connections: set the timestamp format to be
     something closely resembling our default assumption from Postgres.
@@ -377,7 +381,7 @@
 
 
 
-def postgresPreflight(connection):
+def postgresPreflight(connection, **kwargs):
     """
     Pre-flight function for PostgreSQL connections: enable standard conforming
     strings, and set a non-infinite statement timeout.
@@ -390,14 +394,14 @@
     # vulnerable to certain types of SQL injection.
     c.execute("set standard_conforming_strings=on")
 
-    # Abort any second that takes more than 30 seconds (30000ms) to
+    # Abort any second that takes more than 30 seconds (default) to
     # execute. This is necessary as a temporary workaround since it's
     # hypothetically possible that different database operations could
     # block each other, while executing SQL in the same process (in the
     # same thread, since SQL executes in the main thread now).  It's
     # preferable to see some exceptions while we're in this state than to
     # have the entire worker process hang.
-    c.execute("set statement_timeout=30000")
+    c.execute("set statement_timeout={}".format(kwargs.get("txnTimeoutSeconds", 30) * 1000))
 
     # pgdb (as per DB-API 2.0) automatically puts the connection into a
     # 'executing a transaction' state when _any_ statement is executed on
@@ -409,14 +413,14 @@
 
 
 
-def pg8000Preflight(connection):
+def pg8000Preflight(connection, **kwargs):
     """
     Pre-flight function for pg8000/PostgreSQL connections: setup type mappings
     in addition to the normal postgres preflight.
     """
 
     # Do the base PostgreSQL preflight
-    postgresPreflight(connection)
+    postgresPreflight(connection, **kwargs)
 
     # Patch pg8000 behavior to match what we need wrt text processing
     def my_text_out(v):

Modified: CalendarServer/trunk/txdav/base/datastore/subpostgres.py
===================================================================
--- CalendarServer/trunk/txdav/base/datastore/subpostgres.py	2016-02-15 19:56:54 UTC (rev 15464)
+++ CalendarServer/trunk/txdav/base/datastore/subpostgres.py	2016-03-01 19:40:29 UTC (rev 15465)
@@ -182,8 +182,11 @@
         logDirectory="",
         socketDir="",
         socketName="",
-        listenAddresses=[], sharedBuffers=30,
-        maxConnections=20, options=[],
+        listenAddresses=[],
+        txnTimeoutSeconds=30,
+        sharedBuffers=30,
+        maxConnections=20,
+        options=[],
         testMode=False,
         uid=None, gid=None,
         spawnedDBUser="caldav",
@@ -259,6 +262,8 @@
             self.port = None
             self.listenAddresses = []
 
+        self.txnTimeoutSeconds = txnTimeoutSeconds
+
         self.testMode = testMode
         self.sharedBuffers = max(sharedBuffers if not testMode else 16, 16)
         self.maxConnections = maxConnections if not testMode else 8
@@ -342,6 +347,7 @@
             kwargs["user"] = self.spawnedDBUser
         elif self.uid is not None:
             kwargs["user"] = pwd.getpwuid(self.uid).pw_name
+        kwargs["txnTimeoutSeconds"] = self.txnTimeoutSeconds
 
         return DBAPIConnector.connectorFor("postgres", **kwargs)
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20160301/9717f909/attachment.html>


More information about the calendarserver-changes mailing list