<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[15465] CalendarServer/trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/15465">15465</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2016-03-01 11:40:29 -0800 (Tue, 01 Mar 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add TxnTimeoutSeconds options to config.Postgres settings.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcalendarservertaputilpy">CalendarServer/trunk/calendarserver/tap/util.py</a></li>
<li><a href="#CalendarServertrunktwistedcaldavstdconfigpy">CalendarServer/trunk/twistedcaldav/stdconfig.py</a></li>
<li><a href="#CalendarServertrunktxdavbasedatastoredbapiclientpy">CalendarServer/trunk/txdav/base/datastore/dbapiclient.py</a></li>
<li><a href="#CalendarServertrunktxdavbasedatastoresubpostgrespy">CalendarServer/trunk/txdav/base/datastore/subpostgres.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkcalendarservertaputilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tap/util.py (15464 => 15465)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -151,6 +151,7 @@
</span><span class="cx"> socketDir=config.Postgres.SocketDirectory,
</span><span class="cx"> socketName=config.Postgres.SocketName,
</span><span class="cx"> listenAddresses=config.Postgres.ListenAddresses,
</span><ins>+ txnTimeoutSeconds=config.Postgres.TxnTimeoutSeconds,
</ins><span class="cx"> sharedBuffers=config.Postgres.SharedBuffers,
</span><span class="cx"> maxConnections=config.Postgres.MaxConnections,
</span><span class="cx"> options=config.Postgres.Options,
</span></span></pre></div>
<a id="CalendarServertrunktwistedcaldavstdconfigpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/stdconfig.py (15464 => 15465)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1017,6 +1017,7 @@
</span><span class="cx"> "SocketDirectory": "",
</span><span class="cx"> "SocketName": "",
</span><span class="cx"> "ListenAddresses": [],
</span><ins>+ "TxnTimeoutSeconds": 30, # Time out transactions
</ins><span class="cx"> "SharedBuffers": 0, # BuffersToConnectionsRatio * MaxConnections
</span><span class="cx"> # Note: don't set this, it will be computed dynamically
</span><span class="cx"> # See _updateMultiProcess( ) below for details
</span></span></pre></div>
<a id="CalendarServertrunktxdavbasedatastoredbapiclientpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/base/datastore/dbapiclient.py (15464 => 15465)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -199,7 +199,7 @@
</span><span class="cx"> are then used to create the actual parameters for each module.
</span><span class="cx"> """
</span><span class="cx">
</span><del>- def __init__(self, endpoint=None, user=None, password=None, database=None):
</del><ins>+ def __init__(self, endpoint=None, user=None, password=None, database=None, **kwargs):
</ins><span class="cx"> """
</span><span class="cx"> @param endpoint: endpoint string describing the connection
</span><span class="cx"> @type endpoint: L{str}
</span><span class="lines">@@ -250,7 +250,7 @@
</span><span class="cx"> def connect(self, label="<unlabeled>"):
</span><span class="cx"> connection = self.dbModule.connect(*self.connectArgs, **self.connectKw)
</span><span class="cx"> w = self.wrapper(connection, label)
</span><del>- self.preflight(w)
</del><ins>+ self.preflight(w, **self.connectKw)
</ins><span class="cx"> return w
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -289,6 +289,8 @@
</span><span class="cx"> dbkwargs = {}
</span><span class="cx"> if params.port:
</span><span class="cx"> dbkwargs["host"] = "{}:{}".format(params.host, params.port)
</span><ins>+ if "txnTimeoutSeconds" in kwargs:
+ dbkwargs["txnTimeoutSeconds"] = kwargs["txnTimeoutSeconds"]
</ins><span class="cx"> return DBAPIConnector(postgres, postgresPreflight, dsn, **dbkwargs)
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -322,6 +324,8 @@
</span><span class="cx"> dbkwargs["host"] = params.host
</span><span class="cx"> if params.port:
</span><span class="cx"> dbkwargs["port"] = int(params.port)
</span><ins>+ if "txnTimeoutSeconds" in kwargs:
+ dbkwargs["txnTimeoutSeconds"] = kwargs["txnTimeoutSeconds"]
</ins><span class="cx"> return DBAPIConnector(dbmodule, pg8000Preflight, **dbkwargs)
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -358,7 +362,7 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span><del>-def oraclePreflight(connection):
</del><ins>+def oraclePreflight(connection, **kwargs):
</ins><span class="cx"> """
</span><span class="cx"> Pre-flight function for Oracle connections: set the timestamp format to be
</span><span class="cx"> something closely resembling our default assumption from Postgres.
</span><span class="lines">@@ -377,7 +381,7 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span><del>-def postgresPreflight(connection):
</del><ins>+def postgresPreflight(connection, **kwargs):
</ins><span class="cx"> """
</span><span class="cx"> Pre-flight function for PostgreSQL connections: enable standard conforming
</span><span class="cx"> strings, and set a non-infinite statement timeout.
</span><span class="lines">@@ -390,14 +394,14 @@
</span><span class="cx"> # vulnerable to certain types of SQL injection.
</span><span class="cx"> c.execute("set standard_conforming_strings=on")
</span><span class="cx">
</span><del>- # Abort any second that takes more than 30 seconds (30000ms) to
</del><ins>+ # Abort any second that takes more than 30 seconds (default) to
</ins><span class="cx"> # execute. This is necessary as a temporary workaround since it's
</span><span class="cx"> # hypothetically possible that different database operations could
</span><span class="cx"> # block each other, while executing SQL in the same process (in the
</span><span class="cx"> # same thread, since SQL executes in the main thread now). It's
</span><span class="cx"> # preferable to see some exceptions while we're in this state than to
</span><span class="cx"> # have the entire worker process hang.
</span><del>- c.execute("set statement_timeout=30000")
</del><ins>+ c.execute("set statement_timeout={}".format(kwargs.get("txnTimeoutSeconds", 30) * 1000))
</ins><span class="cx">
</span><span class="cx"> # pgdb (as per DB-API 2.0) automatically puts the connection into a
</span><span class="cx"> # 'executing a transaction' state when _any_ statement is executed on
</span><span class="lines">@@ -409,14 +413,14 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span><del>-def pg8000Preflight(connection):
</del><ins>+def pg8000Preflight(connection, **kwargs):
</ins><span class="cx"> """
</span><span class="cx"> Pre-flight function for pg8000/PostgreSQL connections: setup type mappings
</span><span class="cx"> in addition to the normal postgres preflight.
</span><span class="cx"> """
</span><span class="cx">
</span><span class="cx"> # Do the base PostgreSQL preflight
</span><del>- postgresPreflight(connection)
</del><ins>+ postgresPreflight(connection, **kwargs)
</ins><span class="cx">
</span><span class="cx"> # Patch pg8000 behavior to match what we need wrt text processing
</span><span class="cx"> def my_text_out(v):
</span></span></pre></div>
<a id="CalendarServertrunktxdavbasedatastoresubpostgrespy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/base/datastore/subpostgres.py (15464 => 15465)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -182,8 +182,11 @@
</span><span class="cx"> logDirectory="",
</span><span class="cx"> socketDir="",
</span><span class="cx"> socketName="",
</span><del>- listenAddresses=[], sharedBuffers=30,
- maxConnections=20, options=[],
</del><ins>+ listenAddresses=[],
+ txnTimeoutSeconds=30,
+ sharedBuffers=30,
+ maxConnections=20,
+ options=[],
</ins><span class="cx"> testMode=False,
</span><span class="cx"> uid=None, gid=None,
</span><span class="cx"> spawnedDBUser="caldav",
</span><span class="lines">@@ -259,6 +262,8 @@
</span><span class="cx"> self.port = None
</span><span class="cx"> self.listenAddresses = []
</span><span class="cx">
</span><ins>+ self.txnTimeoutSeconds = txnTimeoutSeconds
+
</ins><span class="cx"> self.testMode = testMode
</span><span class="cx"> self.sharedBuffers = max(sharedBuffers if not testMode else 16, 16)
</span><span class="cx"> self.maxConnections = maxConnections if not testMode else 8
</span><span class="lines">@@ -342,6 +347,7 @@
</span><span class="cx"> kwargs["user"] = self.spawnedDBUser
</span><span class="cx"> elif self.uid is not None:
</span><span class="cx"> kwargs["user"] = pwd.getpwuid(self.uid).pw_name
</span><ins>+ kwargs["txnTimeoutSeconds"] = self.txnTimeoutSeconds
</ins><span class="cx">
</span><span class="cx"> return DBAPIConnector.connectorFor("postgres", **kwargs)
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>