[CalendarServer-changes] [12262] CalendarServer/trunk/txdav
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 12 11:24:15 PDT 2014
Revision: 12262
http://trac.calendarserver.org//changeset/12262
Author: cdaboo at apple.com
Date: 2014-01-07 14:21:28 -0800 (Tue, 07 Jan 2014)
Log Message:
-----------
Trigger an event split, if allowed, when a txn timeout occurs during setComponent().
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/test/test_sql.py
Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/sql.py 2014-01-07 22:12:04 UTC (rev 12261)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py 2014-01-07 22:21:28 UTC (rev 12262)
@@ -46,6 +46,7 @@
from twisted.internet.defer import inlineCallbacks, returnValue, succeed
from twisted.python import hashlib
+from twisted.python.failure import Failure
from twistedcaldav import caldavxml, customxml, ical
from twistedcaldav.config import config
@@ -2331,6 +2332,12 @@
internal_request=is_internal,
))
+ # Set an attribute on this object to indicate that it is valid to check for an event split. We need to do this here so that if a timeout
+ # occurs whilst doing implicit processing (most likely because the event is too big) we are able to subsequently detect that it is OK
+ # to split and then try that.
+ if internal_state not in (ComponentUpdateState.SPLIT_OWNER, ComponentUpdateState.SPLIT_ATTENDEE,) and scheduler.state == "organizer":
+ self.okToSplit = True
+
if do_implicit_action and not is_internal:
# Cannot do implicit in sharee's shared calendar
@@ -2445,6 +2452,7 @@
raise UIDExistsElsewhereError("UID already exists in different calendar: %s." % (elsewhere.calendar().name(),))
+ @inlineCallbacks
def setComponent(self, component, inserting=False, smart_merge=False):
"""
Public api for storing a component. This will do full data validation checks on the specified component.
@@ -2457,9 +2465,19 @@
component = self._componentClass.fromString(component)
except InvalidICalendarDataError as e:
raise InvalidComponentForStoreError(str(e))
- return self._setComponentInternal(component, inserting, ComponentUpdateState.NORMAL, smart_merge)
+ try:
+ yield self._setComponentInternal(component, inserting, ComponentUpdateState.NORMAL, smart_merge)
+ except Exception as e:
+ ex = Failure()
+ # If the failure is due to a txn timeout and we have the special attribute indicating it is OK to
+ # attempt a split, then try splitting only when doing an update.
+ if self._txn.timedout and hasattr(self, "okToSplit") and not inserting:
+ yield self.timeoutSplit()
+ ex.raiseException()
+
+
@inlineCallbacks
def _setComponentInternal(self, component, inserting=False, internal_state=ComponentUpdateState.NORMAL, smart_merge=False, split_details=None):
"""
@@ -3674,16 +3692,19 @@
@inlineCallbacks
- def checkSplit(self):
+ def checkSplit(self, txn=None):
"""
- Determine if the calendar data needs to be split, and enqueue a split work item if needed.
+ Determine if the calendar data needs to be split, and enqueue a split work item if needed. Note we may
+ need to do this in some other transaction.
"""
if config.Scheduling.Options.Splitting.Enabled:
will = (yield self.willSplit())
if will:
notBefore = datetime.datetime.utcnow() + datetime.timedelta(seconds=config.Scheduling.Options.Splitting.Delay)
- work = (yield self._txn.enqueue(CalendarObject.CalendarObjectSplitterWork, resourceID=self._resourceID, notBefore=notBefore))
+ if txn is None:
+ txn = self._txn
+ work = (yield txn.enqueue(CalendarObject.CalendarObjectSplitterWork, resourceID=self._resourceID, notBefore=notBefore))
# _workItems is used during unit testing only, to track the created work
if not hasattr(self, "_workItems"):
@@ -3704,6 +3725,21 @@
@inlineCallbacks
+ def timeoutSplit(self):
+ """
+ A txn timeout occurred. Check to see if it is possible to split this event and if so schedule that to occur
+ as the timeout might be the result of the resource being too large and doing a split here will allow a
+ subsequent operation to succeed since the split can reduce the size.
+ """
+
+ # Can only do if cached data exists
+ if self._cachedComponent:
+ txn = self.transaction().store().newTransaction("Timeout checkSplit")
+ yield self.checkSplit(txn=txn)
+ yield txn.commit()
+
+
+ @inlineCallbacks
def split(self, onlyThis=False, rid=None, olderUID=None):
"""
Split this and all matching UID calendar objects as per L{iCalSplitter}.
Modified: CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py 2014-01-07 22:12:04 UTC (rev 12261)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py 2014-01-07 22:21:28 UTC (rev 12262)
@@ -24,6 +24,7 @@
from twext.enterprise.dal.syntax import Select, Parameter, Insert, Delete, \
Update
+from twext.enterprise.ienterprise import AlreadyFinishedError
from txweb2 import responsecode
from txweb2.http_headers import MimeType
@@ -32,7 +33,7 @@
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks, returnValue, DeferredList, \
succeed
-from twisted.internet.task import deferLater
+from twisted.internet.task import deferLater, Clock
from twisted.trial import unittest
from twistedcaldav import caldavxml, ical
@@ -47,6 +48,7 @@
from txdav.caldav.datastore.scheduling.caldav.scheduler import CalDAVScheduler
from txdav.caldav.datastore.scheduling.cuaddress import RemoteCalendarUser, \
LocalCalendarUser
+from txdav.caldav.datastore.scheduling.implicit import ImplicitScheduler
from txdav.caldav.datastore.scheduling.itip import iTIPRequestStatus
from txdav.caldav.datastore.scheduling.processing import ImplicitProcessor
from txdav.caldav.datastore.scheduling.scheduler import ScheduleResponseQueue
@@ -56,7 +58,8 @@
from txdav.caldav.datastore.test.util import buildCalendarStore
from txdav.caldav.datastore.util import _migrateCalendar, migrateHome
from txdav.caldav.icalendarstore import ComponentUpdateState, InvalidDefaultCalendar
-from txdav.common.datastore.sql import ECALENDARTYPE, CommonObjectResource
+from txdav.common.datastore.sql import ECALENDARTYPE, CommonObjectResource, \
+ CommonStoreTransactionMonitor
from txdav.common.datastore.sql_tables import schema, _BIND_MODE_DIRECT, \
_BIND_STATUS_ACCEPTED
from txdav.common.datastore.test.util import populateCalendarsFrom, \
@@ -5144,3 +5147,426 @@
self.assertEqual(details[1][0], "urn:uuid:user01")
self.assertEqual(details[1][1], ("mailto:cuser01 at example.org",))
self.assertEqual(normalize_iCalStr(details[1][2]), normalize_iCalStr(data_past_external) % relsubs, "Failed past: %s\n%s" % (title, diff_iCalStrs(details[1][2], data_past_external % relsubs),))
+
+
+ @inlineCallbacks
+ def test_calendarObjectSplit_timeout(self):
+ """
+ Test that splitting of calendar objects works.
+ """
+ data_init = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:%(now_back30)s
+DURATION:PT2H
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01 at example.com
+ATTENDEE:mailto:user02 at example.com
+DTSTAMP:20051222T210507Z
+ORGANIZER:mailto:user01 at example.com
+RRULE:FREQ=DAILY
+SUMMARY:1234567890123456789012345678901234567890
+ 1234567890123456789012345678901234567890
+ 1234567890123456789012345678901234567890
+ 1234567890123456789012345678901234567890
+END:VEVENT
+BEGIN:VEVENT
+UID:12345-67890
+RECURRENCE-ID:%(now_back25)s
+DTSTART:%(now_back25)s
+DURATION:PT1H
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01 at example.com
+ATTENDEE:mailto:user02 at example.com
+DTSTAMP:20051222T210507Z
+ORGANIZER:mailto:user01 at example.com
+END:VEVENT
+BEGIN:VEVENT
+UID:12345-67890
+RECURRENCE-ID:%(now_back24)s
+DTSTART:%(now_back24)s
+DURATION:PT1H
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01 at example.com
+ATTENDEE:mailto:user02 at example.com
+DTSTAMP:20051222T210507Z
+ORGANIZER:mailto:user01 at example.com
+END:VEVENT
+BEGIN:VEVENT
+UID:12345-67890
+RECURRENCE-ID:%(now_fwd10)s
+DTSTART:%(now_fwd10)s
+DURATION:PT1H
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01 at example.com
+ATTENDEE:mailto:user02 at example.com
+DTSTAMP:20051222T210507Z
+ORGANIZER:mailto:user01 at example.com
+END:VEVENT
+END:VCALENDAR
+"""
+
+ data = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:%(now_back30)s
+DURATION:PT1H
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01 at example.com
+ATTENDEE:mailto:user02 at example.com
+DTSTAMP:20051222T210507Z
+ORGANIZER:mailto:user01 at example.com
+RRULE:FREQ=DAILY
+SUMMARY:1234567890123456789012345678901234567890
+ 1234567890123456789012345678901234567890
+ 1234567890123456789012345678901234567890
+ 1234567890123456789012345678901234567890
+END:VEVENT
+BEGIN:VEVENT
+UID:12345-67890
+RECURRENCE-ID:%(now_back25)s
+DTSTART:%(now_back25)s
+DURATION:PT1H
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01 at example.com
+ATTENDEE:mailto:user02 at example.com
+DTSTAMP:20051222T210507Z
+ORGANIZER:mailto:user01 at example.com
+END:VEVENT
+BEGIN:VEVENT
+UID:12345-67890
+RECURRENCE-ID:%(now_back24)s
+DTSTART:%(now_back24)s
+DURATION:PT1H
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01 at example.com
+ATTENDEE:mailto:user02 at example.com
+DTSTAMP:20051222T210507Z
+ORGANIZER:mailto:user01 at example.com
+END:VEVENT
+BEGIN:VEVENT
+UID:12345-67890
+RECURRENCE-ID:%(now_fwd10)s
+DTSTART:%(now_fwd10)s
+DURATION:PT1H
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:user01 at example.com
+ATTENDEE:mailto:user02 at example.com
+DTSTAMP:20051222T210507Z
+ORGANIZER:mailto:user01 at example.com
+END:VEVENT
+END:VCALENDAR
+"""
+
+ data_future = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:%(now_back14)s
+DURATION:PT2H
+ATTENDEE;CN=User 01;EMAIL=user01 at example.com;PARTSTAT=ACCEPTED:urn:uuid:user01
+ATTENDEE;CN=User 02;EMAIL=user02 at example.com;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:uuid:user02
+DTSTAMP:20051222T210507Z
+ORGANIZER;CN=User 01;EMAIL=user01 at example.com:urn:uuid:user01
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+RRULE:FREQ=DAILY
+SEQUENCE:1
+SUMMARY:1234567890123456789012345678901234567890
+ 1234567890123456789012345678901234567890
+ 1234567890123456789012345678901234567890
+ 1234567890123456789012345678901234567890
+END:VEVENT
+BEGIN:VEVENT
+UID:12345-67890
+RECURRENCE-ID:%(now_fwd10)s
+DTSTART:%(now_fwd10)s
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01 at example.com;PARTSTAT=ACCEPTED:urn:uuid:user01
+ATTENDEE;CN=User 02;EMAIL=user02 at example.com;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:uuid:user02
+DTSTAMP:20051222T210507Z
+ORGANIZER;CN=User 01;EMAIL=user01 at example.com:urn:uuid:user01
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+SEQUENCE:1
+END:VEVENT
+END:VCALENDAR
+"""
+
+ data_past = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:%(relID)s
+DTSTART:%(now_back30)s
+DURATION:PT2H
+ATTENDEE;CN=User 01;EMAIL=user01 at example.com;PARTSTAT=ACCEPTED:urn:uuid:user01
+ATTENDEE;CN=User 02;EMAIL=user02 at example.com;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:uuid:user02
+DTSTAMP:20051222T210507Z
+ORGANIZER;CN=User 01;EMAIL=user01 at example.com:urn:uuid:user01
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+RRULE:FREQ=DAILY;UNTIL=%(now_back14_1)s
+SEQUENCE:1
+SUMMARY:1234567890123456789012345678901234567890
+ 1234567890123456789012345678901234567890
+ 1234567890123456789012345678901234567890
+ 1234567890123456789012345678901234567890
+END:VEVENT
+BEGIN:VEVENT
+UID:%(relID)s
+RECURRENCE-ID:%(now_back25)s
+DTSTART:%(now_back25)s
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01 at example.com;PARTSTAT=ACCEPTED:urn:uuid:user01
+ATTENDEE;CN=User 02;EMAIL=user02 at example.com;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:uuid:user02
+DTSTAMP:20051222T210507Z
+ORGANIZER;CN=User 01;EMAIL=user01 at example.com:urn:uuid:user01
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+SEQUENCE:1
+END:VEVENT
+BEGIN:VEVENT
+UID:%(relID)s
+RECURRENCE-ID:%(now_back24)s
+DTSTART:%(now_back24)s
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01 at example.com;PARTSTAT=ACCEPTED:urn:uuid:user01
+ATTENDEE;CN=User 02;EMAIL=user02 at example.com;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:uuid:user02
+DTSTAMP:20051222T210507Z
+ORGANIZER;CN=User 01;EMAIL=user01 at example.com:urn:uuid:user01
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+SEQUENCE:1
+END:VEVENT
+END:VCALENDAR
+"""
+
+ data_future2 = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:%(now_back14)s
+DURATION:PT2H
+ATTENDEE;CN=User 01;EMAIL=user01 at example.com;PARTSTAT=ACCEPTED:urn:uuid:user01
+ATTENDEE;CN=User 02;EMAIL=user02 at example.com;RSVP=TRUE:urn:uuid:user02
+DTSTAMP:20051222T210507Z
+ORGANIZER;CN=User 01;EMAIL=user01 at example.com:urn:uuid:user01
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+RRULE:FREQ=DAILY
+SEQUENCE:1
+SUMMARY:1234567890123456789012345678901234567890
+ 1234567890123456789012345678901234567890
+ 1234567890123456789012345678901234567890
+ 1234567890123456789012345678901234567890
+END:VEVENT
+BEGIN:VEVENT
+UID:12345-67890
+RECURRENCE-ID:%(now_fwd10)s
+DTSTART:%(now_fwd10)s
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01 at example.com;PARTSTAT=ACCEPTED:urn:uuid:user01
+ATTENDEE;CN=User 02;EMAIL=user02 at example.com;RSVP=TRUE:urn:uuid:user02
+DTSTAMP:20051222T210507Z
+ORGANIZER;CN=User 01;EMAIL=user01 at example.com:urn:uuid:user01
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+SEQUENCE:1
+END:VEVENT
+BEGIN:X-CALENDARSERVER-PERUSER
+UID:12345-67890
+X-CALENDARSERVER-PERUSER-UID:user02
+BEGIN:X-CALENDARSERVER-PERINSTANCE
+TRANSP:TRANSPARENT
+END:X-CALENDARSERVER-PERINSTANCE
+END:X-CALENDARSERVER-PERUSER
+END:VCALENDAR
+"""
+
+ data_past2 = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:%(relID)s
+DTSTART:%(now_back30)s
+DURATION:PT2H
+ATTENDEE;CN=User 01;EMAIL=user01 at example.com;PARTSTAT=ACCEPTED:urn:uuid:user01
+ATTENDEE;CN=User 02;EMAIL=user02 at example.com;RSVP=TRUE:urn:uuid:user02
+DTSTAMP:20051222T210507Z
+ORGANIZER;CN=User 01;EMAIL=user01 at example.com:urn:uuid:user01
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+RRULE:FREQ=DAILY;UNTIL=%(now_back14_1)s
+SEQUENCE:1
+SUMMARY:1234567890123456789012345678901234567890
+ 1234567890123456789012345678901234567890
+ 1234567890123456789012345678901234567890
+ 1234567890123456789012345678901234567890
+END:VEVENT
+BEGIN:VEVENT
+UID:%(relID)s
+RECURRENCE-ID:%(now_back25)s
+DTSTART:%(now_back25)s
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01 at example.com;PARTSTAT=ACCEPTED:urn:uuid:user01
+ATTENDEE;CN=User 02;EMAIL=user02 at example.com;RSVP=TRUE:urn:uuid:user02
+DTSTAMP:20051222T210507Z
+ORGANIZER;CN=User 01;EMAIL=user01 at example.com:urn:uuid:user01
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+SEQUENCE:1
+END:VEVENT
+BEGIN:VEVENT
+UID:%(relID)s
+RECURRENCE-ID:%(now_back24)s
+DTSTART:%(now_back24)s
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01 at example.com;PARTSTAT=ACCEPTED:urn:uuid:user01
+ATTENDEE;CN=User 02;EMAIL=user02 at example.com;RSVP=TRUE:urn:uuid:user02
+DTSTAMP:20051222T210507Z
+ORGANIZER;CN=User 01;EMAIL=user01 at example.com:urn:uuid:user01
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+SEQUENCE:1
+END:VEVENT
+BEGIN:X-CALENDARSERVER-PERUSER
+UID:%(relID)s
+X-CALENDARSERVER-PERUSER-UID:user02
+BEGIN:X-CALENDARSERVER-PERINSTANCE
+TRANSP:TRANSPARENT
+END:X-CALENDARSERVER-PERINSTANCE
+END:X-CALENDARSERVER-PERUSER
+END:VCALENDAR
+"""
+
+ data_inbox2 = """BEGIN:VCALENDAR
+VERSION:2.0
+METHOD:REQUEST
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:%(now_back14)s
+DURATION:PT2H
+ATTENDEE;CN=User 01;EMAIL=user01 at example.com;PARTSTAT=ACCEPTED:urn:uuid:user01
+ATTENDEE;CN=User 02;EMAIL=user02 at example.com;RSVP=TRUE:urn:uuid:user02
+DTSTAMP:20051222T210507Z
+ORGANIZER;CN=User 01;EMAIL=user01 at example.com:urn:uuid:user01
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+RRULE:FREQ=DAILY
+SEQUENCE:1
+SUMMARY:1234567890123456789012345678901234567890
+ 1234567890123456789012345678901234567890
+ 1234567890123456789012345678901234567890
+ 1234567890123456789012345678901234567890
+END:VEVENT
+BEGIN:VEVENT
+UID:12345-67890
+RECURRENCE-ID:%(now_fwd10)s
+DTSTART:%(now_fwd10)s
+DURATION:PT1H
+ATTENDEE;CN=User 01;EMAIL=user01 at example.com;PARTSTAT=ACCEPTED:urn:uuid:user01
+ATTENDEE;CN=User 02;EMAIL=user02 at example.com;RSVP=TRUE:urn:uuid:user02
+DTSTAMP:20051222T210507Z
+ORGANIZER;CN=User 01;EMAIL=user01 at example.com:urn:uuid:user01
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+SEQUENCE:1
+END:VEVENT
+END:VCALENDAR
+"""
+
+ # Create one event without active split
+ self.patch(config.Scheduling.Options.Splitting, "Enabled", False)
+ calendar = yield self.calendarUnderTest(name="calendar", home="user01")
+ component = Component.fromString(data_init % self.subs)
+ cobj = yield calendar.createCalendarObjectWithName("data1.ics", component)
+ self.assertFalse(hasattr(cobj, "_workItems"))
+ yield self.commit()
+
+ w = schema.CALENDAR_OBJECT_SPLITTER_WORK
+ rows = yield Select(
+ [w.RESOURCE_ID, ],
+ From=w
+ ).on(self.transactionUnderTest())
+ self.assertEqual(len(rows), 0)
+ yield self.abort()
+
+ # Turn on splitting
+ self.patch(config.Scheduling.Options.Splitting, "Enabled", True)
+ self.patch(config.Scheduling.Options.Splitting, "Size", 1024)
+ self.patch(config.Scheduling.Options.Splitting, "PastDays", 14)
+ self.patch(config.Scheduling.Options.Splitting, "Delay", 2)
+
+ # Setup timeouts
+ c = Clock()
+ self.patch(CommonStoreTransactionMonitor, "callLater", c.callLater)
+
+ # Patch config to turn on transaction timeouts then rebuild the store
+ self.patch(self.storeUnderTest(), "timeoutTransactions", 1)
+ cobj = yield self.calendarObjectUnderTest(name="data1.ics", calendar_name="calendar", home="user01")
+
+ self.assertFalse(self.transactionUnderTest().timedout)
+
+ oldScheduling = ImplicitScheduler.doImplicitScheduling
+ def newScheduling(self, do_smart_merge=False, split_details=None):
+ c.advance(2)
+ return oldScheduling(self, do_smart_merge, split_details)
+ self.patch(ImplicitScheduler, "doImplicitScheduling", newScheduling)
+
+ component = Component.fromString(data % self.subs)
+ yield self.failUnlessFailure(cobj.setComponent(component), AlreadyFinishedError)
+ self.assertTrue(self.transactionUnderTest().timedout)
+ work = cobj._workItems[0]
+
+ # Clear out timed out state
+ self.lastTransaction = None
+ self.patch(self.storeUnderTest(), "timeoutTransactions", 0)
+
+ w = schema.CALENDAR_OBJECT_SPLITTER_WORK
+ rows = yield Select(
+ [w.RESOURCE_ID, ],
+ From=w
+ ).on(self.transactionUnderTest())
+ self.assertEqual(len(rows), 1)
+ self.assertEqual(rows[0][0], cobj._resourceID)
+ yield self.abort()
+
+ # Wait for it to complete
+ yield work.whenExecuted()
+
+ rows = yield Select(
+ [w.RESOURCE_ID, ],
+ From=w
+ ).on(self.transactionUnderTest())
+ self.assertEqual(len(rows), 0)
+ yield self.abort()
+
+ # Get the existing and new object data
+ cobj1 = yield self.calendarObjectUnderTest(name="data1.ics", calendar_name="calendar", home="user01")
+ self.assertTrue(cobj1.isScheduleObject)
+ ical1 = yield cobj1.component()
+ newUID = ical1.masterComponent().propertyValue("RELATED-TO")
+
+ cobj2 = yield self.calendarObjectUnderTest(name="%s.ics" % (newUID,), calendar_name="calendar", home="user01")
+ self.assertTrue(cobj2 is not None)
+ self.assertTrue(cobj2.isScheduleObject)
+
+ ical_future = yield cobj1.component()
+ ical_past = yield cobj2.component()
+
+ # Verify user01 data
+ title = "user01"
+ relsubs = dict(self.subs)
+ relsubs["relID"] = newUID
+ self.assertEqual(normalize_iCalStr(ical_future), normalize_iCalStr(data_future) % relsubs, "Failed future: %s" % (title,))
+ self.assertEqual(normalize_iCalStr(ical_past), normalize_iCalStr(data_past) % relsubs, "Failed past: %s" % (title,))
+
+ # Get user02 data
+ cal = yield self.calendarUnderTest(name="calendar", home="user02")
+ cobjs = yield cal.calendarObjects()
+ self.assertEqual(len(cobjs), 2)
+ for cobj in cobjs:
+ ical = yield cobj.component()
+ if ical.resourceUID() == "12345-67890":
+ ical_future = ical
+ else:
+ ical_past = ical
+
+ cal = yield self.calendarUnderTest(name="inbox", home="user02")
+ cobjs = yield cal.calendarObjects()
+ self.assertEqual(len(cobjs), 1)
+ ical_inbox = yield cobjs[0].component()
+
+ # Verify user02 data
+ title = "user02"
+ self.assertEqual(normalize_iCalStr(ical_future), normalize_iCalStr(data_future2) % relsubs, "Failed future: %s" % (title,))
+ self.assertEqual(normalize_iCalStr(ical_past), normalize_iCalStr(data_past2) % relsubs, "Failed past: %s" % (title,))
+ self.assertEqual(normalize_iCalStr(ical_inbox), normalize_iCalStr(data_inbox2) % relsubs, "Failed inbox: %s" % (title,))
Modified: CalendarServer/trunk/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql.py 2014-01-07 22:12:04 UTC (rev 12261)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py 2014-01-07 22:21:28 UTC (rev 12262)
@@ -454,7 +454,7 @@
if self.delayedLog:
self.delayedLog.cancel()
self.delayedLog = None
- self.txn.abort()
+ self.txn.timeout()
if self.timeoutSeconds:
self.delayedTimeout = self.callLater(self.timeoutSeconds, _forceAbort)
@@ -512,6 +512,7 @@
self.statementCount = 0
self.iudCount = 0
self.currentStatement = None
+ self.timedout = False
self.logItems = {}
@@ -1083,6 +1084,14 @@
return self._sqlTxn.abort()
+ def timeout(self):
+ """
+ Abort the transaction due to time out.
+ """
+ self.timedout = True
+ return self.abort()
+
+
def statsReport(self):
"""
Print the stats report and record log items
Modified: CalendarServer/trunk/txdav/common/datastore/test/test_sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/test/test_sql.py 2014-01-07 22:12:04 UTC (rev 12261)
+++ CalendarServer/trunk/txdav/common/datastore/test/test_sql.py 2014-01-07 22:21:28 UTC (rev 12262)
@@ -128,10 +128,12 @@
self.patch(log, "error", counter)
txn = self.transactionUnderTest()
+ self.assertFalse(txn.timedout)
c.advance(2)
self.assertNotEqual(ctr[0], 0)
self.assertTrue(txn._sqlTxn._completed)
+ self.assertTrue(txn.timedout)
def test_logWaitsAndTxnTimeout(self):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/cbd12ac9/attachment.html>
More information about the calendarserver-changes
mailing list