<!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>[14229] 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/14229">14229</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2014-12-17 12:15:04 -0800 (Wed, 17 Dec 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Wrap each leaf directory service with its own cache so that when a leaf service needs to do further record lookups, those are also cached</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcalendarservertaputilpy">CalendarServer/trunk/calendarserver/tap/util.py</a></li>
<li><a href="#CalendarServertrunkcalendarservertoolsdashboardpy">CalendarServer/trunk/calendarserver/tools/dashboard.py</a></li>
<li><a href="#CalendarServertrunkcalendarservertoolstestgatewaycaldavdplist">CalendarServer/trunk/calendarserver/tools/test/gateway/caldavd.plist</a></li>
<li><a href="#CalendarServertrunkcalendarservertoolstesttest_gatewaypy">CalendarServer/trunk/calendarserver/tools/test/test_gateway.py</a></li>
<li><a href="#CalendarServertrunkrequirementsstabletxt">CalendarServer/trunk/requirements-stable.txt</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoretestutilpy">CalendarServer/trunk/txdav/common/datastore/test/util.py</a></li>
<li><a href="#CalendarServertrunktxdavwhoaugmentpy">CalendarServer/trunk/txdav/who/augment.py</a></li>
<li><a href="#CalendarServertrunktxdavwhocachepy">CalendarServer/trunk/txdav/who/cache.py</a></li>
<li><a href="#CalendarServertrunktxdavwhotesttest_utilpy">CalendarServer/trunk/txdav/who/test/test_util.py</a></li>
<li><a href="#CalendarServertrunktxdavwhoutilpy">CalendarServer/trunk/txdav/who/util.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 (14228 => 14229)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tap/util.py        2014-12-17 20:06:03 UTC (rev 14228)
+++ CalendarServer/trunk/calendarserver/tap/util.py        2014-12-17 20:15:04 UTC (rev 14229)
</span><span class="lines">@@ -234,11 +234,11 @@
</span><span class="cx"> def storeFromConfigWithoutDPS(config, txnFactory):
</span><span class="cx"> store = storeFromConfig(config, txnFactory, None)
</span><span class="cx"> directory = directoryFromConfig(config, store)
</span><del>- if config.DirectoryProxy.InProcessCachingSeconds:
- directory = CachingDirectoryService(
- directory,
- expireSeconds=config.DirectoryProxy.InProcessCachingSeconds
- )
</del><ins>+ # if config.DirectoryProxy.InProcessCachingSeconds:
+ # directory = CachingDirectoryService(
+ # directory,
+ # expireSeconds=config.DirectoryProxy.InProcessCachingSeconds
+ # )
</ins><span class="cx"> store.setDirectoryService(directory)
</span><span class="cx"> return store
</span><span class="cx">
</span><span class="lines">@@ -262,11 +262,11 @@
</span><span class="cx"> def storeFromConfigWithDPSServer(config, txnFactory):
</span><span class="cx"> store = storeFromConfig(config, txnFactory, None)
</span><span class="cx"> directory = directoryFromConfig(config, store)
</span><del>- if config.DirectoryProxy.InSidecarCachingSeconds:
- directory = CachingDirectoryService(
- directory,
- expireSeconds=config.DirectoryProxy.InSidecarCachingSeconds
- )
</del><ins>+ # if config.DirectoryProxy.InSidecarCachingSeconds:
+ # directory = CachingDirectoryService(
+ # directory,
+ # expireSeconds=config.DirectoryProxy.InSidecarCachingSeconds
+ # )
</ins><span class="cx"> store.setDirectoryService(directory)
</span><span class="cx"> return store
</span><span class="cx">
</span></span></pre></div>
<a id="CalendarServertrunkcalendarservertoolsdashboardpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tools/dashboard.py (14228 => 14229)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tools/dashboard.py        2014-12-17 20:06:03 UTC (rev 14228)
+++ CalendarServer/trunk/calendarserver/tools/dashboard.py        2014-12-17 20:15:04 UTC (rev 14229)
</span><span class="lines">@@ -1055,7 +1055,7 @@
</span><span class="cx"> if methodName.endswith("-hit"):
</span><span class="cx"> overallCountRatio += count
</span><span class="cx"> overallCountCached += count
</span><del>- if "-" not in methodName:
</del><ins>+ if methodName.endswith("-miss") or methodName.endswith("-expired"):
</ins><span class="cx"> overallCountRatio += count
</span><span class="cx"> overallCountUncached += count
</span><span class="cx"> overallTimeSpent += timeSpent
</span></span></pre></div>
<a id="CalendarServertrunkcalendarservertoolstestgatewaycaldavdplist"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tools/test/gateway/caldavd.plist (14228 => 14229)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tools/test/gateway/caldavd.plist        2014-12-17 20:06:03 UTC (rev 14228)
+++ CalendarServer/trunk/calendarserver/tools/test/gateway/caldavd.plist        2014-12-17 20:15:04 UTC (rev 14229)
</span><span class="lines">@@ -763,6 +763,14 @@
</span><span class="cx"> <key>SharedConnectionPool</key>
</span><span class="cx"> <true/>
</span><span class="cx">
</span><ins>+ <key>DirectoryProxy</key>
+ <dict>
+ <key>InProcessCachingSeconds</key>
+ <integer>0</integer>
+ <key>InSidecarCachingSeconds</key>
+ <integer>0</integer>
+ </dict>
+
</ins><span class="cx"> <!--
</span><span class="cx"> Twisted
</span><span class="cx"> -->
</span></span></pre></div>
<a id="CalendarServertrunkcalendarservertoolstesttest_gatewaypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tools/test/test_gateway.py (14228 => 14229)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tools/test/test_gateway.py        2014-12-17 20:06:03 UTC (rev 14228)
+++ CalendarServer/trunk/calendarserver/tools/test/test_gateway.py        2014-12-17 20:15:04 UTC (rev 14229)
</span><span class="lines">@@ -182,8 +182,8 @@
</span><span class="cx">
</span><span class="cx"> def _flush(self):
</span><span class="cx"> # Flush both XML directories
</span><del>- self.directory._directory.services[0].flush()
</del><span class="cx"> self.directory._directory.services[1].flush()
</span><ins>+ self.directory._directory.services[2].flush()
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span></span></pre></div>
<a id="CalendarServertrunkrequirementsstabletxt"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/requirements-stable.txt (14228 => 14229)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/requirements-stable.txt        2014-12-17 20:06:03 UTC (rev 14228)
+++ CalendarServer/trunk/requirements-stable.txt        2014-12-17 20:15:04 UTC (rev 14229)
</span><span class="lines">@@ -5,7 +5,7 @@
</span><span class="cx"> # For CalendarServer development, don't try to get these projects from PyPI; use svn.
</span><span class="cx">
</span><span class="cx"> -e .
</span><del>--e svn+http://svn.calendarserver.org/repository/calendarserver/twext/trunk@14226#egg=twextpy
</del><ins>+-e svn+http://svn.calendarserver.org/repository/calendarserver/twext/trunk@14228#egg=twextpy
</ins><span class="cx"> -e svn+http://svn.calendarserver.org/repository/calendarserver/PyKerberos/trunk@13420#egg=kerberos
</span><span class="cx"> -e svn+http://svn.calendarserver.org/repository/calendarserver/PyCalendar/trunk@14224#egg=pycalendar
</span><span class="cx">
</span></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoretestutilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/test/util.py (14228 => 14229)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/test/util.py        2014-12-17 20:06:03 UTC (rev 14228)
+++ CalendarServer/trunk/txdav/common/datastore/test/util.py        2014-12-17 20:15:04 UTC (rev 14229)
</span><span class="lines">@@ -623,7 +623,7 @@
</span><span class="cx">
</span><span class="cx"> def buildTestDirectory(
</span><span class="cx"> store, dataRoot, accounts=None, resources=None, augments=None, proxies=None,
</span><del>- serversDB=None
</del><ins>+ serversDB=None, cacheSeconds=0
</ins><span class="cx"> ):
</span><span class="cx"> """
</span><span class="cx"> @param store: the store for the directory to use
</span><span class="lines">@@ -711,7 +711,7 @@
</span><span class="cx"> )
</span><span class="cx"> directory = buildDirectory(
</span><span class="cx"> store, dataRoot, servicesInfo, augmentServiceInfo, wikiServiceInfo,
</span><del>- serversDB
</del><ins>+ serversDB, cacheSeconds
</ins><span class="cx"> )
</span><span class="cx">
</span><span class="cx"> store.setDirectoryService(directory)
</span><span class="lines">@@ -733,7 +733,7 @@
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def buildStoreAndDirectory(
</span><span class="cx"> self, accounts=None, resources=None, augments=None, proxies=None,
</span><del>- extraUids=None, serversDB=None
</del><ins>+ extraUids=None, serversDB=None, cacheSeconds=0
</ins><span class="cx"> ):
</span><span class="cx">
</span><span class="cx"> self.serverRoot = self.mktemp()
</span><span class="lines">@@ -752,7 +752,7 @@
</span><span class="cx"> self.store, config.DataRoot,
</span><span class="cx"> accounts=accounts, resources=resources,
</span><span class="cx"> augments=augments, proxies=proxies,
</span><del>- serversDB=serversDB
</del><ins>+ serversDB=serversDB, cacheSeconds=cacheSeconds
</ins><span class="cx"> )
</span><span class="cx"> if extraUids:
</span><span class="cx"> for uid in extraUids:
</span></span></pre></div>
<a id="CalendarServertrunktxdavwhoaugmentpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/who/augment.py (14228 => 14229)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/who/augment.py        2014-12-17 20:06:03 UTC (rev 14228)
+++ CalendarServer/trunk/txdav/who/augment.py        2014-12-17 20:15:04 UTC (rev 14229)
</span><span class="lines">@@ -110,12 +110,9 @@
</span><span class="cx"> self._store = store
</span><span class="cx"> self._augmentDB = augmentDB
</span><span class="cx">
</span><del>- # Look for an LDAP DS with extra info to expose to the dashboard
</del><ins>+ # An LDAP DS has extra info to expose via the dashboard
+ # This is assigned in buildDirectory()
</ins><span class="cx"> self._ldapDS = None
</span><del>- for ds in self._directory._services:
- if hasattr(ds, "poolStats"):
- self._ldapDS = ds
- break
</del><span class="cx">
</span><span class="cx">
</span><span class="cx"> @classmethod
</span><span class="lines">@@ -457,10 +454,12 @@
</span><span class="cx"> # print("Augmented fields", fields)
</span><span class="cx">
</span><span class="cx"> # Clone to a new record with the augmented fields
</span><del>- returnValue(AugmentedDirectoryRecord(self, record, fields))
</del><ins>+ augmentedRecord = AugmentedDirectoryRecord(self, record, fields)
</ins><span class="cx">
</span><ins>+ returnValue(augmentedRecord)
</ins><span class="cx">
</span><span class="cx">
</span><ins>+
</ins><span class="cx"> class AugmentedDirectoryRecord(DirectoryRecord, CalendarDirectoryRecordMixin):
</span><span class="cx"> """
</span><span class="cx"> Augmented directory record.
</span></span></pre></div>
<a id="CalendarServertrunktxdavwhocachepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/who/cache.py (14228 => 14229)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/who/cache.py        2014-12-17 20:06:03 UTC (rev 14228)
+++ CalendarServer/trunk/txdav/who/cache.py        2014-12-17 20:15:04 UTC (rev 14229)
</span><span class="lines">@@ -82,21 +82,40 @@
</span><span class="cx"> def __init__(self, directory, expireSeconds=30):
</span><span class="cx"> BaseDirectoryService.__init__(self, directory.realmName)
</span><span class="cx"> self._directory = directory
</span><del>- self.serversDB = directory.serversDB
- self._directoryTiming = hasattr(self._directory, "_addTiming")
</del><ins>+
+ # Patch the wrapped directory service's recordWithXXX to instead
+ # use this cache
+
+ directory._wrapped_recordWithUID = directory.recordWithUID
+ directory.recordWithUID = self.recordWithUID
+
+ directory._wrapped_recordWithGUID = directory.recordWithGUID
+ directory.recordWithGUID = self.recordWithGUID
+
+ directory._wrapped_recordWithShortName = directory.recordWithShortName
+ directory.recordWithShortName = self.recordWithShortName
+
+ directory._wrapped_recordsWithEmailAddress = directory.recordsWithEmailAddress
+ directory.recordsWithEmailAddress = self.recordsWithEmailAddress
+
</ins><span class="cx"> self._expireSeconds = expireSeconds
</span><span class="cx"> self.resetCache()
</span><span class="cx">
</span><del>-# from txdav.who.augment import AugmentedDirectoryService
-# if isinstance(self._directory, AugmentedDirectoryService):
-# for ds in self._directory._directory.services:
-# if hasattr(ds, "setMasterDirectory"):
-# ds.setMasterDirectory(self)
</del><span class="cx">
</span><span class="cx">
</span><ins>+ def setTimingMethod(self, f):
+ """
+ Replace the default no-op timing method
+ """
+ self._addTiming = f
+
+
</ins><span class="cx"> def _addTiming(self, key, duration):
</span><del>- if self._directoryTiming:
- self._directory._addTiming(key, duration)
</del><ins>+ """
+ Timing won't get recorded by default -- you must call setTimingMethod
+ with a callable that takes a key such as a method name, and a duration.
+ """
+ pass
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def resetCache(self):
</span><span class="lines">@@ -160,6 +179,40 @@
</span><span class="cx"> pass
</span><span class="cx">
</span><span class="cx">
</span><ins>+ def purgeRecord(self, record):
+ """
+ Remove a record from all indices in the cache
+
+ @param record: the directory record
+ """
+
+ if record.uid in self._cache[IndexType.uid]:
+ del self._cache[IndexType.uid][record.uid]
+
+ try:
+ if record.guid in self._cache[IndexType.guid]:
+ del self._cache[IndexType.guid][record.guid]
+ except AttributeError:
+ pass
+
+ try:
+ typeName = record.recordType.name
+ for name in record.shortNames:
+ key = (typeName, name)
+ if key in self._cache[IndexType.shortName]:
+ del self._cache[IndexType.shortName][key]
+ except AttributeError:
+ pass
+
+ try:
+ for emailAddress in record.emailAddresses:
+ if emailAddress in self._cache[IndexType.emailAddress]:
+ del self._cache[IndexType.emailAddress][emailAddress]
+ except AttributeError:
+ pass
+
+
+
</ins><span class="cx"> def purgeExpiredRecords(self):
</span><span class="cx"> """
</span><span class="cx"> Scans the cache for expired records and deletes them
</span><span class="lines">@@ -175,6 +228,7 @@
</span><span class="cx"> del self._cache[indexType][key]
</span><span class="cx">
</span><span class="cx">
</span><ins>+
</ins><span class="cx"> def lookupRecord(self, indexType, key, name):
</span><span class="cx"> """
</span><span class="cx"> Looks for a record in the specified index, under the specified key.
</span><span class="lines">@@ -213,7 +267,7 @@
</span><span class="cx"> key=key
</span><span class="cx"> )
</span><span class="cx"> # This record has expired
</span><del>- del self._cache[indexType][key]
</del><ins>+ self.purgeRecord(record)
</ins><span class="cx"> self._addTiming("{}-expired".format(name), 0)
</span><span class="cx"> return None
</span><span class="cx">
</span><span class="lines">@@ -244,7 +298,7 @@
</span><span class="cx"> # First check our cache
</span><span class="cx"> record = self.lookupRecord(IndexType.uid, uid, "recordWithUID")
</span><span class="cx"> if record is None:
</span><del>- record = yield self._directory.recordWithUID(
</del><ins>+ record = yield self._directory._wrapped_recordWithUID(
</ins><span class="cx"> uid, timeoutSeconds=timeoutSeconds
</span><span class="cx"> )
</span><span class="cx"> if record is not None:
</span><span class="lines">@@ -263,7 +317,7 @@
</span><span class="cx"> # First check our cache
</span><span class="cx"> record = self.lookupRecord(IndexType.guid, guid, "recordWithGUID")
</span><span class="cx"> if record is None:
</span><del>- record = yield self._directory.recordWithGUID(
</del><ins>+ record = yield self._directory._wrapped_recordWithGUID(
</ins><span class="cx"> guid, timeoutSeconds=timeoutSeconds
</span><span class="cx"> )
</span><span class="cx"> if record is not None:
</span><span class="lines">@@ -286,7 +340,7 @@
</span><span class="cx"> "recordWithShortName"
</span><span class="cx"> )
</span><span class="cx"> if record is None:
</span><del>- record = yield self._directory.recordWithShortName(
</del><ins>+ record = yield self._directory._wrapped_recordWithShortName(
</ins><span class="cx"> recordType, shortName, timeoutSeconds=timeoutSeconds
</span><span class="cx"> )
</span><span class="cx"> if record is not None:
</span><span class="lines">@@ -311,7 +365,7 @@
</span><span class="cx"> "recordsWithEmailAddress"
</span><span class="cx"> )
</span><span class="cx"> if record is None:
</span><del>- records = yield self._directory.recordsWithEmailAddress(
</del><ins>+ records = yield self._directory._wrapped_recordsWithEmailAddress(
</ins><span class="cx"> emailAddress,
</span><span class="cx"> limitResults=limitResults, timeoutSeconds=timeoutSeconds
</span><span class="cx"> )
</span><span class="lines">@@ -352,12 +406,12 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> def recordsFromExpression(
</span><del>- self, expression, recordTypes=None,
</del><ins>+ self, expression, recordTypes=None, records=None,
</ins><span class="cx"> limitResults=None, timeoutSeconds=None
</span><span class="cx"> ):
</span><span class="cx"> # Defer to the directory service we're caching
</span><span class="cx"> return self._directory.recordsFromExpression(
</span><del>- expression, recordTypes=recordTypes,
</del><ins>+ expression, recordTypes=recordTypes, records=records,
</ins><span class="cx"> limitResults=limitResults, timeoutSeconds=timeoutSeconds
</span><span class="cx"> )
</span><span class="cx">
</span></span></pre></div>
<a id="CalendarServertrunktxdavwhotesttest_utilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/who/test/test_util.py (14228 => 14229)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/who/test/test_util.py        2014-12-17 20:06:03 UTC (rev 14228)
+++ CalendarServer/trunk/txdav/who/test/test_util.py        2014-12-17 20:15:04 UTC (rev 14229)
</span><span class="lines">@@ -30,6 +30,7 @@
</span><span class="cx"> from twistedcaldav.config import ConfigDict
</span><span class="cx"> from twistedcaldav.stdconfig import config as stdconfig
</span><span class="cx"> from txdav.who.augment import AugmentedDirectoryService
</span><ins>+from txdav.who.cache import CachingDirectoryService
</ins><span class="cx"> from txdav.who.delegates import (
</span><span class="cx"> DirectoryService as DelegateDirectoryService,
</span><span class="cx"> RecordType as DelegateRecordType
</span><span class="lines">@@ -44,6 +45,7 @@
</span><span class="cx">
</span><span class="cx"> hasattr(stdconfig, "Servers") # Quell pyflakes
</span><span class="cx">
</span><ins>+
</ins><span class="cx"> class StubStore(object):
</span><span class="cx"> pass
</span><span class="cx">
</span><span class="lines">@@ -108,6 +110,11 @@
</span><span class="cx"> "Servers": {
</span><span class="cx"> "Enabled": False,
</span><span class="cx"> },
</span><ins>+ "DirectoryProxy": {
+ "SocketPath": "directory-proxy.sock",
+ "InProcessCachingSeconds": 60,
+ "InSidecarCachingSeconds": 120,
+ },
</ins><span class="cx"> }
</span><span class="cx"> )
</span><span class="cx">
</span><span class="lines">@@ -125,17 +132,34 @@
</span><span class="cx"> self.assertTrue(isinstance(service._directory, AggregateDirectoryService))
</span><span class="cx"> self.assertEquals(len(service._directory.services), 4)
</span><span class="cx"> self.assertTrue(
</span><del>- isinstance(service._directory.services[0], XMLDirectoryService)
</del><ins>+ isinstance(service._directory.services[0], DelegateDirectoryService)
</ins><span class="cx"> )
</span><span class="cx"> self.assertEquals(
</span><span class="cx"> set(service._directory.services[0].recordTypes()),
</span><ins>+ set(
+ [
+ DelegateRecordType.readDelegateGroup,
+ DelegateRecordType.writeDelegateGroup,
+ DelegateRecordType.readDelegatorGroup,
+ DelegateRecordType.writeDelegatorGroup,
+ ]
+ )
+ )
+ self.assertTrue(
+ isinstance(service._directory.services[1], CachingDirectoryService)
+ )
+ self.assertTrue(
+ isinstance(service._directory.services[1]._directory, XMLDirectoryService)
+ )
+ self.assertEquals(
+ set(service._directory.services[1]._directory.recordTypes()),
</ins><span class="cx"> set([RecordType.user, RecordType.group])
</span><span class="cx"> )
</span><span class="cx"> self.assertTrue(
</span><del>- isinstance(service._directory.services[1], XMLDirectoryService)
</del><ins>+ isinstance(service._directory.services[2]._directory, XMLDirectoryService)
</ins><span class="cx"> )
</span><span class="cx"> self.assertEquals(
</span><del>- set(service._directory.services[1].recordTypes()),
</del><ins>+ set(service._directory.services[2]._directory.recordTypes()),
</ins><span class="cx"> set(
</span><span class="cx"> [
</span><span class="cx"> CalRecordType.location,
</span><span class="lines">@@ -145,20 +169,6 @@
</span><span class="cx"> )
</span><span class="cx"> )
</span><span class="cx"> self.assertTrue(
</span><del>- isinstance(service._directory.services[2], DelegateDirectoryService)
- )
- self.assertEquals(
- set(service._directory.services[2].recordTypes()),
- set(
- [
- DelegateRecordType.readDelegateGroup,
- DelegateRecordType.writeDelegateGroup,
- DelegateRecordType.readDelegatorGroup,
- DelegateRecordType.writeDelegatorGroup,
- ]
- )
- )
- self.assertTrue(
</del><span class="cx"> isinstance(service._directory.services[3], WikiDirectoryService)
</span><span class="cx"> )
</span><span class="cx"> self.assertEquals(
</span></span></pre></div>
<a id="CalendarServertrunktxdavwhoutilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/who/util.py (14228 => 14229)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/who/util.py        2014-12-17 20:06:03 UTC (rev 14228)
+++ CalendarServer/trunk/txdav/who/util.py        2014-12-17 20:15:04 UTC (rev 14229)
</span><span class="lines">@@ -32,6 +32,7 @@
</span><span class="cx"> from twisted.python.reflect import namedClass
</span><span class="cx"> from twistedcaldav.config import fullServerPath
</span><span class="cx"> from txdav.who.augment import AugmentedDirectoryService
</span><ins>+from txdav.who.cache import CachingDirectoryService
</ins><span class="cx"> from txdav.who.delegates import DirectoryService as DelegateDirectoryService
</span><span class="cx"> from txdav.who.idirectory import (
</span><span class="cx"> RecordType as CalRecordType,
</span><span class="lines">@@ -72,14 +73,15 @@
</span><span class="cx"> [config.DirectoryService, config.ResourceService],
</span><span class="cx"> config.AugmentService,
</span><span class="cx"> config.Authentication.Wiki,
</span><del>- serversDB=serversDB
</del><ins>+ serversDB=serversDB,
+ cachingSeconds=config.DirectoryProxy.InSidecarCachingSeconds
</ins><span class="cx"> )
</span><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> def buildDirectory(
</span><span class="cx"> store, dataRoot, servicesInfo, augmentServiceInfo, wikiServiceInfo,
</span><del>- serversDB=None
</del><ins>+ serversDB=None, cachingSeconds=0
</ins><span class="cx"> ):
</span><span class="cx"> """
</span><span class="cx"> Return a directory without using a config object; suitable for tests
</span><span class="lines">@@ -97,6 +99,8 @@
</span><span class="cx"> """
</span><span class="cx">
</span><span class="cx"> aggregatedServices = []
</span><ins>+ cachingServices = []
+ ldapService = None # LDAP DS has extra stats (see augment.py)
</ins><span class="cx">
</span><span class="cx"> for serviceValue in servicesInfo:
</span><span class="cx">
</span><span class="lines">@@ -106,6 +110,7 @@
</span><span class="cx"> directoryType = serviceValue.type.lower()
</span><span class="cx"> params = serviceValue.params
</span><span class="cx">
</span><ins>+
</ins><span class="cx"> if "xml" in directoryType:
</span><span class="cx"> xmlFile = params.xmlFile
</span><span class="cx"> xmlFile = fullServerPath(dataRoot, xmlFile)
</span><span class="lines">@@ -179,6 +184,7 @@
</span><span class="cx"> CalRecordType.address: extraFilters.get("addresses", ""),
</span><span class="cx"> }
</span><span class="cx"> )
</span><ins>+ ldapService = directory
</ins><span class="cx">
</span><span class="cx"> elif "inmemory" in directoryType:
</span><span class="cx"> from txdav.who.test.support import CalendarInMemoryDirectoryService
</span><span class="lines">@@ -215,6 +221,14 @@
</span><span class="cx"> (directory.fieldName, CalFieldName)
</span><span class="cx"> )
</span><span class="cx"> fieldNames.append(directory.fieldName)
</span><ins>+
+ if cachingSeconds:
+ directory = CachingDirectoryService(
+ directory,
+ expireSeconds=cachingSeconds
+ )
+ cachingServices.append(directory)
+
</ins><span class="cx"> aggregatedServices.append(directory)
</span><span class="cx">
</span><span class="cx"> #
</span><span class="lines">@@ -254,7 +268,9 @@
</span><span class="cx"> userDirectory.realmName,
</span><span class="cx"> store
</span><span class="cx"> )
</span><del>- aggregatedServices.append(delegateDirectory)
</del><ins>+ # (put at front of list so we don't try to ask the actual DS services
+ # about the delegate-related principals, for performance)
+ aggregatedServices.insert(0, delegateDirectory)
</ins><span class="cx">
</span><span class="cx"> # Wiki service
</span><span class="cx"> if wikiServiceInfo.Enabled:
</span><span class="lines">@@ -284,6 +300,14 @@
</span><span class="cx"> # FIXME: is there a better pattern to use here?
</span><span class="cx"> delegateDirectory.setMasterDirectory(augmented)
</span><span class="cx">
</span><ins>+ # Tell each caching service what method to use when reporting
+ # times and cache stats
+ for cachingService in cachingServices:
+ cachingService.setTimingMethod(augmented._addTiming)
+
+ # LDAP has additional stats to report
+ augmented._ldapDS = ldapService
+
</ins><span class="cx"> except Exception as e:
</span><span class="cx"> log.error("Could not create directory service", error=e)
</span><span class="cx"> raise
</span></span></pre>
</div>
</div>
</body>
</html>