[CalendarServer-changes] [8992] CalendarServer/trunk/txdav
source_changes at macosforge.org
source_changes at macosforge.org
Fri Apr 6 08:47:58 PDT 2012
Revision: 8992
http://trac.macosforge.org/projects/calendarserver/changeset/8992
Author: cdaboo at apple.com
Date: 2012-04-06 08:47:58 -0700 (Fri, 06 Apr 2012)
Log Message:
-----------
Last set of tweaks to on-demand in separate txn.
Modified Paths:
--------------
CalendarServer/trunk/txdav/caldav/datastore/sql.py
CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py
CalendarServer/trunk/txdav/common/datastore/sql.py
CalendarServer/trunk/txdav/common/datastore/sql_legacy.py
Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/sql.py 2012-04-05 22:44:53 UTC (rev 8991)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py 2012-04-06 15:47:58 UTC (rev 8992)
@@ -754,7 +754,7 @@
@inlineCallbacks
def updateDatabase(self, component, expand_until=None, reCreate=False,
- inserting=False, useTxn=None):
+ inserting=False, txn=None):
"""
Update the database tables for the new data being written. Occasionally we might need to do an update to
time-range data via a separate transaction, so we allow that to be passed in. Note that in that case
@@ -766,7 +766,7 @@
"""
# Setup appropriate txn
- txn = useTxn if useTxn is not None else self._txn
+ txn = txn if txn is not None else self._txn
# Decide how far to expand based on the component
doInstanceIndexing = False
@@ -1024,15 +1024,15 @@
@inlineCallbacks
- def recurrenceMax(self, useTxn=None):
+ def recurrenceMax(self, txn=None):
"""
- Get the RECURRANCE_MAX value. Occasionally we might need to do an update to
- time-range data via a separate transaction, so we allow that to be passed in.
+ Get the RECURRANCE_MAX value from the database. Occasionally we might need to do an
+ update to time-range data via a separate transaction, so we allow that to be passed in.
@return: L{PyCalendarDateTime} result
"""
# Setup appropriate txn
- txn = useTxn if useTxn is not None else self._txn
+ txn = txn if txn is not None else self._txn
rMax = (
yield self._recurrenceMaxByIDQuery.on(txn,
Modified: CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py 2012-04-05 22:44:53 UTC (rev 8991)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py 2012-04-06 15:47:58 UTC (rev 8992)
@@ -1110,7 +1110,7 @@
def test_resourceLock(self):
"""
Test CommonObjectResource.lock to make sure it locks, raises on missing resource,
- and raises when locked and NOWAIT used.
+ and raises when locked and wait=False used.
"""
# Valid object
@@ -1120,11 +1120,11 @@
yield resource.lock()
self.assertTrue(resource._locked)
- # Setup a new transaction to verify the lock and also verify NOWAIT behavior
+ # Setup a new transaction to verify the lock and also verify wait behavior
newTxn = self._sqlCalendarStore.newTransaction()
newResource = yield self.calendarObjectUnderTest(txn=newTxn)
try:
- yield newResource.lock(nowait=True)
+ yield newResource.lock(wait=False)
except:
pass # OK
else:
@@ -1148,7 +1148,7 @@
yield self.calendarObjectUnderTest("2.ics", txn=newTxn)
try:
- yield resource.lock(nowait=True, useTxn=newTxn)
+ yield resource.lock(wait=False, useTxn=newTxn)
except:
pass # OK
else:
Modified: CalendarServer/trunk/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql.py 2012-04-05 22:44:53 UTC (rev 8991)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py 2012-04-06 15:47:58 UTC (rev 8992)
@@ -2919,24 +2919,25 @@
@inlineCallbacks
- def lock(self, nowait=False, useTxn=None):
+ def lock(self, wait=True, txn=None):
"""
- Attempt to obtain a row lock on the object resource. Lock will remain until
+ Attempt to obtain a row lock on the object resource. 'wait' determines whether the DB call will
+ block on any existing lock held by someone else. Lock will remain until
transaction is complete, or fail if resource is missing, or it is already locked
- and NOWAIT is used. Occasionally we need to lock via a separate transaction so we
+ and wait=False is used. Occasionally we need to lock via a separate transaction so we
pass that in too.
- @param nowait: whether or not to use NOWAIT option
- @type nowait: C{bool}
- @param useTxn: alternatiuve transaction to use
- @type useTxn: L{CommonStoreTransaction}
+ @param wait: whether or not to wait on someone else's lock
+ @type wait: C{bool}
+ @param txn: alternative transaction to use
+ @type txn: L{CommonStoreTransaction}
@raise: L{NoSuchObjectResourceError} if resource does not exist, other L{Exception}
if already locked and NOWAIT is used.
"""
- txn = useTxn if useTxn is not None else self._txn
- yield self._selectForUpdateQuery(nowait).on(txn, NoSuchObjectResourceError, resourceID=self._resourceID)
+ txn = txn if txn is not None else self._txn
+ yield self._selectForUpdateQuery(not wait).on(txn, NoSuchObjectResourceError, resourceID=self._resourceID)
self._locked = True
Modified: CalendarServer/trunk/txdav/common/datastore/sql_legacy.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql_legacy.py 2012-04-05 22:44:53 UTC (rev 8991)
+++ CalendarServer/trunk/txdav/common/datastore/sql_legacy.py 2012-04-06 15:47:58 UTC (rev 8992)
@@ -1158,11 +1158,11 @@
obj = yield self.calendar.calendarObjectWithName(name)
# Use a new transaction to do this update quickly without locking the row for too long. However, the original
- # transaction may have the row locked, so use NOWAIT and if that fails, fakll back to using the original txn.
+ # transaction may have the row locked, so use wait=False and if that fails, fall back to using the original txn.
newTxn = obj.transaction().store().newTransaction()
try:
- yield obj.lock(nowait=True, useTxn=newTxn)
+ yield obj.lock(wait=False, txn=newTxn)
except NoSuchObjectResourceError:
yield newTxn.commit()
returnValue(None)
@@ -1175,14 +1175,14 @@
if newTxn is None:
rmax = None
else:
- rmax = (yield obj.recurrenceMax(useTxn=newTxn))
+ rmax = (yield obj.recurrenceMax(txn=newTxn))
if rmax is None or rmax < expand_until:
yield obj.updateDatabase(
(yield obj.component()),
expand_until=expand_until,
reCreate=True,
- useTxn=newTxn,
+ txn=newTxn,
)
finally:
if newTxn is not None:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120406/832d345b/attachment.html>
More information about the calendarserver-changes
mailing list