[CalendarServer-changes] [5689] CalendarServer/branches/new-store

source_changes at macosforge.org source_changes at macosforge.org
Fri Jun 4 15:12:18 PDT 2010


Revision: 5689
          http://trac.macosforge.org/projects/calendarserver/changeset/5689
Author:   glyph at apple.com
Date:     2010-06-04 15:12:16 -0700 (Fri, 04 Jun 2010)
Log Message:
-----------
treat properties more consistently

Modified Paths:
--------------
    CalendarServer/branches/new-store/txcaldav/calendarstore/file.py
    CalendarServer/branches/new-store/txdav/propertystore/xattr.py

Modified: CalendarServer/branches/new-store/txcaldav/calendarstore/file.py
===================================================================
--- CalendarServer/branches/new-store/txcaldav/calendarstore/file.py	2010-06-04 22:10:00 UTC (rev 5688)
+++ CalendarServer/branches/new-store/txcaldav/calendarstore/file.py	2010-06-04 22:12:16 UTC (rev 5689)
@@ -14,6 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 ##
+
 """
 File calendar store.
 """
@@ -25,13 +26,14 @@
     "CalendarObject",
 ]
 
+from uuid import uuid4
 from errno import EEXIST, ENOENT
 
 from zope.interface import implements
 
 from twisted.python.util import FancyEqMixin
 
-from twisted.internet.defer import inlineCallbacks
+from twisted.internet.defer import succeed
 
 from twext.python.log import LoggingMixIn
 from twext.python.vcomponent import VComponent
@@ -54,9 +56,9 @@
 from txcaldav.icalendarstore import InternalDataStoreError
 
 from twistedcaldav.caldavxml import ScheduleCalendarTransp, Transparent
+from twistedcaldav.customxml import GETCTag
 
 from twistedcaldav.index import Index as OldIndex
-from twistedcaldav.memcachelock import MemcacheLock, MemcacheLockTimeoutError
 
 def _isValidName(name):
     """
@@ -321,12 +323,12 @@
 
         # Calendars are initially transparent to freebusy.  FIXME: freebusy
         # needs more structured support than this.
-        props[PN(ScheduleCalendarTransp.sname())] = Transparent()
+        props[PN(ScheduleCalendarTransp.sname())] = ScheduleCalendarTransp(
+            Transparent())
         # FIXME: there's no need for 'flush' to be a public method of the
         # property store any more.  It should just be transactional like
         # everything else; the API here would better be expressed as
         # c.properties().participateInTxn(txn)
-        self._transaction.addOperation(c.properties().flush)
         # FIXME: return c # maybe ?
 
     def removeCalendarWithName(self, name):
@@ -366,11 +368,14 @@
 
             return undo
 
-
+    # @_cached
     def properties(self):
         # FIXME: needs tests for actual functionality
         # FIXME: needs to be cached
-        return PropertyStore(self._path)
+        # FIXME: transaction tests
+        props = PropertyStore(self._path)
+        self._transaction.addOperation(props.flush)
+        return props
 
 
 
@@ -498,31 +503,24 @@
     def syncToken(self):
         raise NotImplementedError()
 
-    @inlineCallbacks
     def _updateSyncToken(self, reset=False):
-        return
+        # FIXME: add locking a-la CalDAVFile.bumpSyncToken
+        # FIXME: tests for desired concurrency properties
+        ctag = PropertyName.fromString(GETCTag.sname())
+        props = self.properties()
+        token = props.get(ctag)
+        if token is None or reset:
+            caluuid = uuid4()
+            revision = 1
+        else:
+            caluuid, revision = token.split("#", 1)
+            revision = int(revision) + 1
+        token = "%s#%d" % (caluuid, revision)
+        props[ctag] = GETCTag(token)
+        # FIXME: no direct tests for commit
+        succeed(token)
 
-        lock = MemcacheLock("Calendar", self.fp.path, timeout=60.0)
-        try:
-            try:
-                yield lock.acquire()
-            except MemcacheLockTimeoutError:
-                raise InternalDataStoreError("Timed out on calendar lock")
 
-            def newToken():
-                raise NotImplementedError()
-
-            if reset:
-                token = newToken()
-
-            raise NotImplementedError(token)
-
-        finally:
-            yield lock.clean()
-
-
-        raise NotImplementedError()
-
     def calendarObjectsInTimeRange(self, start, end, timeZone):
         raise NotImplementedError()
 
@@ -534,7 +532,9 @@
     def properties(self):
         # FIXME: needs direct tests - only covered by calendar store tests
         # FIXME: transactions
-        return PropertyStore(self._path)
+        props = PropertyStore(self._path)
+        self._transaction.addOperation(props.flush)
+        return props
 
 
 
@@ -658,10 +658,11 @@
     def organizer(self):
         return self.component().getOrganizer()
 
+    @_cached
     def properties(self):
-        if not hasattr(self, "_properties"):
-            self._properties = PropertyStore(self._path)
-        return self._properties
+        props = PropertyStore(self._path)
+        self._calendar._transaction.addOperation(props.flush)
+        return props
 
 
 

Modified: CalendarServer/branches/new-store/txdav/propertystore/xattr.py
===================================================================
--- CalendarServer/branches/new-store/txdav/propertystore/xattr.py	2010-06-04 22:10:00 UTC (rev 5688)
+++ CalendarServer/branches/new-store/txdav/propertystore/xattr.py	2010-06-04 22:12:16 UTC (rev 5689)
@@ -123,7 +123,7 @@
         try:
             data = self.attrs[self._encodeKey(key)]
         except IOError, e:
-            if e.errno in [_ERRNO_NO_ATTR]:
+            if e.errno in [_ERRNO_NO_ATTR, errno.ENOENT]:
                 raise KeyError(key)
             raise PropertyStoreError(e)
 
@@ -207,6 +207,16 @@
     #
 
     def flush(self):
+        # FIXME: The transaction may have deleted the file, and then obviously
+        # flushing would fail.  Let's try to detect that scenario.  The
+        # transaction should not attempt to flush properties if it is also
+        # deleting the resource, though, and there are other reasons we might
+        # want to know about that the file doesn't exist, so this should be
+        # fixed.
+        self.path.changed()
+        if not self.path.exists():
+            return
+
         attrs    = self.attrs
         removed  = self.removed
         modified = self.modified
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100604/7dc822e3/attachment.html>


More information about the calendarserver-changes mailing list