[CalendarServer-changes] [6956] CalendarServer/branches/users/glyph/dalify/txdav/common/datastore/ sql.py
source_changes at macosforge.org
source_changes at macosforge.org
Wed Feb 16 06:30:32 PST 2011
Revision: 6956
http://trac.macosforge.org/projects/calendarserver/changeset/6956
Author: glyph at apple.com
Date: 2011-02-16 06:30:32 -0800 (Wed, 16 Feb 2011)
Log Message:
-----------
dalify pre-lock quota query
Modified Paths:
--------------
CalendarServer/branches/users/glyph/dalify/txdav/common/datastore/sql.py
Modified: CalendarServer/branches/users/glyph/dalify/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/glyph/dalify/txdav/common/datastore/sql.py 2011-02-16 14:30:20 UTC (rev 6955)
+++ CalendarServer/branches/users/glyph/dalify/txdav/common/datastore/sql.py 2011-02-16 14:30:32 UTC (rev 6956)
@@ -835,20 +835,24 @@
returnValue(self._quotaUsedBytes)
+ @classproperty
+ def _preLockResourceIDQuery(self):
+ meta = self._homeMetaDataSchema
+ return Select(From=meta,
+ Where=meta.RESOURCE_ID==Parameter("resourceID"),
+ ForUpdate=True)
+
+
@inlineCallbacks
def adjustQuotaUsedBytes(self, delta):
"""
- Adjust quota used. We need to get a lock on the row first so that the adjustment
- is done atomically. It is import to do the 'select ... for update' because a race also
- exists in the 'update ... x = x + 1' case as seen via unit tests.
+ Adjust quota used. We need to get a lock on the row first so that the
+ adjustment is done atomically. It is import to do the 'select ... for
+ update' because a race also exists in the 'update ... x = x + 1' case as
+ seen via unit tests.
"""
- yield self._txn.execSQL("""
- select * from %(name)s
- where %(column_RESOURCE_ID)s = %%s
- for update
- """ % self._homeMetaDataTable,
- [self._resourceID]
- )
+ yield self._preLockResourceIDQuery.on(self._txn,
+ resourceID=self._resourceID)
self._quotaUsedBytes = (yield self._txn.execSQL("""
update %(name)s
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110216/240f8a29/attachment.html>
More information about the calendarserver-changes
mailing list