<!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>[12091] CalendarServer/trunk/twistedcaldav</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/12091">12091</a></dd>
<dt>Author</dt> <dd>wsanchez@apple.com</dd>
<dt>Date</dt> <dd>2013-12-13 16:19:41 -0800 (Fri, 13 Dec 2013)</dd>
</dl>
<h3>Log Message</h3>
<pre>Use twisted.protocols.memcache instead of twext.protocols.memcache.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktwistedcaldavmemcachepoolpy">CalendarServer/trunk/twistedcaldav/memcachepool.py</a></li>
<li><a href="#CalendarServertrunktwistedcaldavtesttest_memcachelockpy">CalendarServer/trunk/twistedcaldav/test/test_memcachelock.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunktwistedcaldavmemcachepoolpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/memcachepool.py (12090 => 12091)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/memcachepool.py        2013-12-14 00:18:20 UTC (rev 12090)
+++ CalendarServer/trunk/twistedcaldav/memcachepool.py        2013-12-14 00:19:41 UTC (rev 12091)
</span><span class="lines">@@ -18,13 +18,14 @@
</span><span class="cx">
</span><span class="cx"> from twisted.internet.defer import Deferred, fail
</span><span class="cx"> from twisted.internet.protocol import ReconnectingClientFactory
</span><ins>+from twisted.protocols.memcache import MemCacheProtocol, NoSuchCommand
</ins><span class="cx">
</span><ins>+from twext.python.log import Logger
</ins><span class="cx"> from twext.internet.gaiendpoint import GAIEndpoint
</span><span class="cx"> from twext.internet.adaptendpoint import connect
</span><span class="cx">
</span><del>-from twext.python.log import Logger
-from twext.protocols.memcache import MemCacheProtocol, NoSuchCommand
</del><span class="cx">
</span><ins>+
</ins><span class="cx"> class PooledMemCacheProtocol(MemCacheProtocol):
</span><span class="cx"> """
</span><span class="cx"> A MemCacheProtocol that will notify a connectionPool that it is ready
</span><span class="lines">@@ -161,7 +162,9 @@
</span><span class="cx">
</span><span class="cx"> self.shutdown_deferred = None
</span><span class="cx"> self.shutdown_requested = False
</span><del>- reactor.addSystemEventTrigger('before', 'shutdown', self._shutdownCallback)
</del><ins>+ reactor.addSystemEventTrigger(
+ 'before', 'shutdown', self._shutdownCallback
+ )
</ins><span class="cx">
</span><span class="cx"> self._busyClients = set([])
</span><span class="cx"> self._freeClients = set([])
</span><span class="lines">@@ -191,8 +194,9 @@
</span><span class="cx">
</span><span class="cx"> @return: A L{Deferred} that fires with the L{IProtocol} instance.
</span><span class="cx"> """
</span><del>- self.log.debug("Initiating new client connection to: %r" % (
- self._endpoint,))
</del><ins>+ self.log.debug(
+ "Initiating new client connection to: %r" % (self._endpoint,)
+ )
</ins><span class="cx"> self._logClientStats()
</span><span class="cx">
</span><span class="cx"> self._pendingConnects += 1
</span><span class="lines">@@ -239,9 +243,12 @@
</span><span class="cx"> Upon memcache error, log the failed request along with the error
</span><span class="cx"> message and free the client.
</span><span class="cx"> """
</span><del>- self.log.error("Memcache error: %s; request: %s %s" %
- (failure.value, command,
- " ".join(args)[:self.REQUEST_LOGGING_SIZE],))
</del><ins>+ self.log.error(
+ "Memcache error: %s; request: %s %s" % (
+ failure.value, command,
+ " ".join(args)[:self.REQUEST_LOGGING_SIZE],
+ )
+ )
</ins><span class="cx"> self.clientFree(client)
</span><span class="cx">
</span><span class="cx"> self.clientBusy(client)
</span><span class="lines">@@ -276,11 +283,14 @@
</span><span class="cx"> d = self._performRequestOnClient(
</span><span class="cx"> client, command, *args, **kwargs)
</span><span class="cx">
</span><del>- elif len(self._busyClients) + self._pendingConnects >= self._maxClients:
</del><ins>+ elif (
+ len(self._busyClients) + self._pendingConnects >= self._maxClients
+ ):
</ins><span class="cx"> d = Deferred()
</span><span class="cx"> self._commands.append((d, command, args, kwargs))
</span><del>- self.log.debug("Command queued: %s, %r, %r" % (
- command, args, kwargs))
</del><ins>+ self.log.debug(
+ "Command queued: %s, %r, %r" % (command, args, kwargs)
+ )
</ins><span class="cx"> self._logClientStats()
</span><span class="cx">
</span><span class="cx"> else:
</span><span class="lines">@@ -292,12 +302,14 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> def _logClientStats(self):
</span><del>- self.log.debug("Clients #free: %d, #busy: %d, "
- "#pending: %d, #queued: %d" % (
</del><ins>+ self.log.debug(
+ "Clients #free: %d, #busy: %d, #pending: %d, #queued: %d" % (
</ins><span class="cx"> len(self._freeClients),
</span><span class="cx"> len(self._busyClients),
</span><span class="cx"> self._pendingConnects,
</span><del>- len(self._commands)))
</del><ins>+ len(self._commands),
+ )
+ )
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def clientGone(self, client):
</span><span class="lines">@@ -349,8 +361,10 @@
</span><span class="cx"> if len(self._commands) > 0:
</span><span class="cx"> d, command, args, kwargs = self._commands.pop(0)
</span><span class="cx">
</span><del>- self.log.debug("Performing Queued Command: %s, %r, %r" % (
- command, args, kwargs))
</del><ins>+ self.log.debug(
+ "Performing Queued Command: %s, %r, %r"
+ % (command, args, kwargs)
+ )
</ins><span class="cx"> self._logClientStats()
</span><span class="cx">
</span><span class="cx"> _ign_d = self.performRequest(
</span><span class="lines">@@ -425,6 +439,8 @@
</span><span class="cx"> _memCachePools = {} # Maps a name to a pool object
</span><span class="cx"> _memCachePoolHandler = {} # Maps a handler id to a named pool
</span><span class="cx">
</span><ins>+
+
</ins><span class="cx"> def installPools(pools, maxClients=5, reactor=None):
</span><span class="cx"> if reactor is None:
</span><span class="cx"> from twisted.internet import reactor
</span><span class="lines">@@ -440,7 +456,9 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span><del>-def _installPool(name, handleTypes, serverEndpoint, maxClients=5, reactor=None):
</del><ins>+def _installPool(
+ name, handleTypes, serverEndpoint, maxClients=5, reactor=None
+):
</ins><span class="cx"> pool = MemCachePool(serverEndpoint, maxClients=maxClients, reactor=None)
</span><span class="cx"> _memCachePools[name] = pool
</span><span class="cx">
</span></span></pre></div>
<a id="CalendarServertrunktwistedcaldavtesttest_memcachelockpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/test/test_memcachelock.py (12090 => 12091)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/test/test_memcachelock.py        2013-12-14 00:18:20 UTC (rev 12090)
+++ CalendarServer/trunk/twistedcaldav/test/test_memcachelock.py        2013-12-14 00:19:41 UTC (rev 12091)
</span><span class="lines">@@ -5,16 +5,17 @@
</span><span class="cx"> Test the memcache client protocol.
</span><span class="cx"> """
</span><span class="cx">
</span><del>-from twext.protocols.memcache import MemCacheProtocol
-
</del><span class="cx"> from twisted.test.proto_helpers import StringTransportWithDisconnection
</span><span class="cx"> from twisted.internet.task import Clock
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks
</span><ins>+from twisted.protocols.memcache import MemCacheProtocol
</ins><span class="cx">
</span><span class="cx"> from twistedcaldav.memcachelock import MemcacheLock, MemcacheLockTimeoutError
</span><span class="cx">
</span><span class="cx"> from twistedcaldav.test.util import TestCase
</span><span class="cx">
</span><ins>+
+
</ins><span class="cx"> class MemCacheTestCase(TestCase):
</span><span class="cx"> """
</span><span class="cx"> Test client protocol class L{MemCacheProtocol}.
</span><span class="lines">@@ -22,22 +23,32 @@
</span><span class="cx">
</span><span class="cx"> class FakedMemcacheLock(MemcacheLock):
</span><span class="cx">
</span><del>- def __init__(self, faked, namespace, locktoken, timeout=5.0, retry_interval=0.1, expire_time=0):
</del><ins>+ def __init__(
+ self, faked, namespace, locktoken,
+ timeout=5.0, retry_interval=0.1, expire_time=0
+ ):
</ins><span class="cx"> """
</span><del>-
</del><span class="cx"> @param namespace: a unique namespace for this lock's tokens
</span><span class="cx"> @type namespace: C{str}
</span><ins>+
</ins><span class="cx"> @param locktoken: the name of the locktoken
</span><span class="cx"> @type locktoken: C{str}
</span><del>- @param timeout: the maximum time in seconds that the lock should block
</del><ins>+
+ @param timeout: the maximum time in seconds that the lock should
+ block
</ins><span class="cx"> @type timeout: C{float}
</span><ins>+
</ins><span class="cx"> @param retry_interval: the interval to retry acquiring the lock
</span><span class="cx"> @type retry_interval: C{float}
</span><del>- @param expiryTime: the time in seconds for the lock to expire. Zero: no expiration.
</del><ins>+
+ @param expiryTime: the time in seconds for the lock to expire.
+ Zero: no expiration.
</ins><span class="cx"> @type expiryTime: C{float}
</span><span class="cx"> """
</span><span class="cx">
</span><del>- super(MemCacheTestCase.FakedMemcacheLock, self).__init__(namespace, locktoken, timeout, retry_interval, expire_time)
</del><ins>+ super(MemCacheTestCase.FakedMemcacheLock, self).__init__(
+ namespace, locktoken, timeout, retry_interval, expire_time
+ )
</ins><span class="cx"> self.faked = faked
</span><span class="cx">
</span><span class="cx"> def _getMemcacheProtocol(self):
</span><span class="lines">@@ -90,11 +101,16 @@
</span><span class="cx"> called back with the value and the flag associated with the given key
</span><span class="cx"> if the server returns a successful result.
</span><span class="cx"> """
</span><del>- lock = MemCacheTestCase.FakedMemcacheLock(self.proto, "lock", "locking")
</del><ins>+ lock = MemCacheTestCase.FakedMemcacheLock(
+ self.proto, "lock", "locking"
+ )
</ins><span class="cx"> return self._test(
</span><span class="cx"> lock.get("foo"),
</span><span class="cx"> "get lock:foo-acbd18db4cc2f85cedef654fccc4a4d8\r\n",
</span><del>- "VALUE lock:foo-acbd18db4cc2f85cedef654fccc4a4d8 0 3\r\nbar\r\nEND\r\n",
</del><ins>+ (
+ "VALUE lock:foo-acbd18db4cc2f85cedef654fccc4a4d8 0 3\r\n"
+ "bar\r\nEND\r\n"
+ ),
</ins><span class="cx"> "bar"
</span><span class="cx"> )
</span><span class="cx">
</span><span class="lines">@@ -105,7 +121,9 @@
</span><span class="cx"> called back with the value and the flag associated with the given key
</span><span class="cx"> if the server returns a successful result.
</span><span class="cx"> """
</span><del>- lock = MemCacheTestCase.FakedMemcacheLock(self.proto, "lock", "locking")
</del><ins>+ lock = MemCacheTestCase.FakedMemcacheLock(
+ self.proto, "lock", "locking"
+ )
</ins><span class="cx"> return self._test(
</span><span class="cx"> lock.set("foo", "bar"),
</span><span class="cx"> "set lock:foo-acbd18db4cc2f85cedef654fccc4a4d8 0 0 3\r\nbar\r\n",
</span><span class="lines">@@ -121,7 +139,9 @@
</span><span class="cx"> called back with the value and the flag associated with the given key
</span><span class="cx"> if the server returns a successful result.
</span><span class="cx"> """
</span><del>- lock = MemCacheTestCase.FakedMemcacheLock(self.proto, "lock", "locking")
</del><ins>+ lock = MemCacheTestCase.FakedMemcacheLock(
+ self.proto, "lock", "locking"
+ )
</ins><span class="cx"> yield self._test(
</span><span class="cx"> lock.acquire(),
</span><span class="cx"> "add lock:locking-559159aa00cc525bfe5c4b34cf16cccb 0 0 1\r\n1\r\n",
</span><span class="lines">@@ -138,7 +158,9 @@
</span><span class="cx"> called back with the value and the flag associated with the given key
</span><span class="cx"> if the server returns a successful result.
</span><span class="cx"> """
</span><del>- lock = MemCacheTestCase.FakedMemcacheLock(self.proto, "lock", "locking", timeout=0)
</del><ins>+ lock = MemCacheTestCase.FakedMemcacheLock(
+ self.proto, "lock", "locking", timeout=0
+ )
</ins><span class="cx"> yield self._test(
</span><span class="cx"> lock.acquire(),
</span><span class="cx"> "add lock:locking-559159aa00cc525bfe5c4b34cf16cccb 0 0 1\r\n1\r\n",
</span><span class="lines">@@ -155,11 +177,17 @@
</span><span class="cx"> called back with the value and the flag associated with the given key
</span><span class="cx"> if the server returns a successful result.
</span><span class="cx"> """
</span><del>- lock = MemCacheTestCase.FakedMemcacheLock(self.proto, "lock", "locking", timeout=0)
</del><ins>+ lock = MemCacheTestCase.FakedMemcacheLock(
+ self.proto, "lock", "locking", timeout=0
+ )
</ins><span class="cx"> try:
</span><span class="cx"> yield self._test(
</span><span class="cx"> lock.acquire(),
</span><del>- "add lock:locking-559159aa00cc525bfe5c4b34cf16cccb 0 0 1\r\n1\r\n",
</del><ins>+ (
+ "add lock:"
+ "locking-559159aa00cc525bfe5c4b34cf16cccb 0 0 1\r\n"
+ "1\r\n"
+ ),
</ins><span class="cx"> "NOT_STORED\r\n",
</span><span class="cx"> True
</span><span class="cx"> )
</span><span class="lines">@@ -179,7 +207,9 @@
</span><span class="cx"> called back with the value and the flag associated with the given key
</span><span class="cx"> if the server returns a successful result.
</span><span class="cx"> """
</span><del>- lock = MemCacheTestCase.FakedMemcacheLock(self.proto, "lock", "locking")
</del><ins>+ lock = MemCacheTestCase.FakedMemcacheLock(
+ self.proto, "lock", "locking"
+ )
</ins><span class="cx"> yield self._test(
</span><span class="cx"> lock.acquire(),
</span><span class="cx"> "add lock:locking-559159aa00cc525bfe5c4b34cf16cccb 0 0 1\r\n1\r\n",
</span><span class="lines">@@ -203,7 +233,9 @@
</span><span class="cx"> called back with the value and the flag associated with the given key
</span><span class="cx"> if the server returns a successful result.
</span><span class="cx"> """
</span><del>- lock = MemCacheTestCase.FakedMemcacheLock(self.proto, "lock", "locking")
</del><ins>+ lock = MemCacheTestCase.FakedMemcacheLock(
+ self.proto, "lock", "locking"
+ )
</ins><span class="cx"> yield self._test(
</span><span class="cx"> lock.acquire(),
</span><span class="cx"> "add lock:locking-559159aa00cc525bfe5c4b34cf16cccb 0 0 1\r\n1\r\n",
</span><span class="lines">@@ -225,7 +257,9 @@
</span><span class="cx"> called back with the value and the flag associated with the given key
</span><span class="cx"> if the server returns a successful result.
</span><span class="cx"> """
</span><del>- lock = MemCacheTestCase.FakedMemcacheLock(self.proto, "lock", u"locking")
</del><ins>+ lock = MemCacheTestCase.FakedMemcacheLock(
+ self.proto, "lock", u"locking"
+ )
</ins><span class="cx"> yield self._test(
</span><span class="cx"> lock.acquire(),
</span><span class="cx"> "add lock:locking-559159aa00cc525bfe5c4b34cf16cccb 0 0 1\r\n1\r\n",
</span><span class="lines">@@ -253,7 +287,9 @@
</span><span class="cx"> self.fail("AssertionError not raised")
</span><span class="cx">
</span><span class="cx"> try:
</span><del>- lock = MemCacheTestCase.FakedMemcacheLock(self.proto, "lock", ("abc",))
</del><ins>+ lock = MemCacheTestCase.FakedMemcacheLock(
+ self.proto, "lock", ("abc",)
+ )
</ins><span class="cx"> yield lock.acquire()
</span><span class="cx"> self.fail("AssertionError not raised")
</span><span class="cx"> except AssertionError:
</span></span></pre>
</div>
</div>
</body>
</html>