[CalendarServer-changes] [2641] CalendarServer/branches/sqlpropstore-2629

source_changes at macosforge.org source_changes at macosforge.org
Mon Jun 30 08:14:13 PDT 2008


Revision: 2641
          http://trac.macosforge.org/projects/calendarserver/changeset/2641
Author:   cdaboo at apple.com
Date:     2008-06-30 08:14:13 -0700 (Mon, 30 Jun 2008)
Log Message:
-----------
Use arbitrary keyword arguments to the property store __init__'s so that we can tailor prop store
behavior on a per store-type basis.

Modified Paths:
--------------
    CalendarServer/branches/sqlpropstore-2629/lib-patches/Twisted/twisted.web2.dav.noneprops.patch
    CalendarServer/branches/sqlpropstore-2629/lib-patches/Twisted/twisted.web2.dav.xattrprops.patch
    CalendarServer/branches/sqlpropstore-2629/twistedcaldav/directory/calendar.py
    CalendarServer/branches/sqlpropstore-2629/twistedcaldav/extensions.py
    CalendarServer/branches/sqlpropstore-2629/twistedcaldav/root.py
    CalendarServer/branches/sqlpropstore-2629/twistedcaldav/sqlprops.py
    CalendarServer/branches/sqlpropstore-2629/twistedcaldav/test/test_sqlprops.py

Modified: CalendarServer/branches/sqlpropstore-2629/lib-patches/Twisted/twisted.web2.dav.noneprops.patch
===================================================================
--- CalendarServer/branches/sqlpropstore-2629/lib-patches/Twisted/twisted.web2.dav.noneprops.patch	2008-06-30 14:46:11 UTC (rev 2640)
+++ CalendarServer/branches/sqlpropstore-2629/lib-patches/Twisted/twisted.web2.dav.noneprops.patch	2008-06-30 15:14:13 UTC (rev 2641)
@@ -2,8 +2,19 @@
 ===================================================================
 --- twisted/web2/dav/noneprops.py	(revision 19773)
 +++ twisted/web2/dav/noneprops.py	(working copy)
-@@ -49,6 +49,9 @@
-     def __init__(self, resource):
+@@ -41,14 +41,17 @@
+     """
+     __singleton = None
+ 
+-    def __new__(clazz, resource):
++    def __new__(cls, resource, **kwargs):
+         if NonePropertyStore.__singleton is None:
+-            NonePropertyStore.__singleton = object.__new__(clazz)
++            NonePropertyStore.__singleton = object.__new__(cls)
+         return NonePropertyStore.__singleton
+ 
+-    def __init__(self, resource):
++    def __init__(self, resource, **kwargs):
          pass
  
 +    def cacheAllChildProperties(self):

Modified: CalendarServer/branches/sqlpropstore-2629/lib-patches/Twisted/twisted.web2.dav.xattrprops.patch
===================================================================
--- CalendarServer/branches/sqlpropstore-2629/lib-patches/Twisted/twisted.web2.dav.xattrprops.patch	2008-06-30 14:46:11 UTC (rev 2640)
+++ CalendarServer/branches/sqlpropstore-2629/lib-patches/Twisted/twisted.web2.dav.xattrprops.patch	2008-06-30 15:14:13 UTC (rev 2641)
@@ -49,7 +49,12 @@
  
          index = name.find("}")
      
-@@ -95,21 +94,79 @@
+@@ -91,25 +90,83 @@
+     _encode = classmethod(_encode)
+     _decode = classmethod(_decode)
+ 
+-    def __init__(self, resource):
++    def __init__(self, resource, **kwargs):
          self.resource = resource
          self.attrs = xattr.xattr(self.resource.fp.path)
  

Modified: CalendarServer/branches/sqlpropstore-2629/twistedcaldav/directory/calendar.py
===================================================================
--- CalendarServer/branches/sqlpropstore-2629/twistedcaldav/directory/calendar.py	2008-06-30 14:46:11 UTC (rev 2640)
+++ CalendarServer/branches/sqlpropstore-2629/twistedcaldav/directory/calendar.py	2008-06-30 15:14:13 UTC (rev 2641)
@@ -273,6 +273,12 @@
             assert isinstance(child, cls), "Child %r is not a %s: %r" % (name, cls.__name__, child)
             self.putChild(name, child)
 
+    def deadProperties(self):
+        if not hasattr(self, '_dead_properties'):
+            self._dead_properties = config.PropertyStoreClass(self, avoid_contention=True)
+
+        return self._dead_properties
+
     def provisionDefaultCalendars(self):
         self.provision()
 

Modified: CalendarServer/branches/sqlpropstore-2629/twistedcaldav/extensions.py
===================================================================
--- CalendarServer/branches/sqlpropstore-2629/twistedcaldav/extensions.py	2008-06-30 14:46:11 UTC (rev 2640)
+++ CalendarServer/branches/sqlpropstore-2629/twistedcaldav/extensions.py	2008-06-30 15:14:13 UTC (rev 2641)
@@ -779,10 +779,10 @@
     """
     A Property Store that caches attributes from the xattrs.
     """
-    def __init__(self, resource):
+    def __init__(self, resource, **kwargs):
         self._cache = {}
         self._not_found = {}
-        super(CachingXattrPropertyStore, self).__init__(resource)
+        super(CachingXattrPropertyStore, self).__init__(resource, **kwargs)
 
     def get(self, qname):
         log.debug("Get: %r, %r" % (self.resource.fp.path, qname))

Modified: CalendarServer/branches/sqlpropstore-2629/twistedcaldav/root.py
===================================================================
--- CalendarServer/branches/sqlpropstore-2629/twistedcaldav/root.py	2008-06-30 14:46:11 UTC (rev 2640)
+++ CalendarServer/branches/sqlpropstore-2629/twistedcaldav/root.py	2008-06-30 15:14:13 UTC (rev 2641)
@@ -94,7 +94,7 @@
 
     def deadProperties(self):
         if not hasattr(self, '_dead_properties'):
-            self._dead_properties = config.PropertyStoreClass(self)
+            self._dead_properties = config.PropertyStoreClass(self, root_resource=True)
 
         return self._dead_properties
 

Modified: CalendarServer/branches/sqlpropstore-2629/twistedcaldav/sqlprops.py
===================================================================
--- CalendarServer/branches/sqlpropstore-2629/twistedcaldav/sqlprops.py	2008-06-30 14:46:11 UTC (rev 2640)
+++ CalendarServer/branches/sqlpropstore-2629/twistedcaldav/sqlprops.py	2008-06-30 15:14:13 UTC (rev 2641)
@@ -44,7 +44,7 @@
     A dead property store that uses an SQLite database back end.
     """
  
-    def __init__(self, resource, use_cache=True, use_parent_db=True):
+    def __init__(self, resource, use_cache=True, root_resource=False, avoid_contention=False, **kwargs):
         self.resource = resource
         if os.path.exists(os.path.dirname(resource.fp.path)):
             if resource.isCollection():
@@ -52,15 +52,7 @@
             else:
                 self.childindex = None
 
-            from twistedcaldav.root import RootResource
-            from twistedcaldav.directory.calendar import DirectoryCalendarHomeResource
-            if (
-                isinstance(resource, RootResource) or
-                isinstance(resource, DirectoryCalendarHomeResource)
-            ):
-                use_parent_db = False
-
-            if resource.isCollection() and not use_parent_db:
+            if resource.isCollection() and (root_resource or avoid_contention):
                 self.rname = ""
                 self.index = self.childindex
             else:

Modified: CalendarServer/branches/sqlpropstore-2629/twistedcaldav/test/test_sqlprops.py
===================================================================
--- CalendarServer/branches/sqlpropstore-2629/twistedcaldav/test/test_sqlprops.py	2008-06-30 14:46:11 UTC (rev 2640)
+++ CalendarServer/branches/sqlpropstore-2629/twistedcaldav/test/test_sqlprops.py	2008-06-30 15:14:13 UTC (rev 2641)
@@ -60,7 +60,7 @@
     def _setUpIndex(self):
         self.collection_name, self.collection_uri = self.mkdtemp("sql")
         rsrc = CalDAVFile(os.path.join(self.collection_name, "file.ics"))
-        return sqlPropertyStore(rsrc, False)
+        return sqlPropertyStore(rsrc, use_cache=False)
         
     def _setOnePropertyAndTest(self, prop):
         index = self._setUpIndex()
@@ -82,7 +82,7 @@
     def test_db_init_directory(self):
         self.collection_name, self.collection_uri = self.mkdtemp("sql")
         rsrc = CalDAVFile(self.collection_name)
-        index = sqlPropertyStore(rsrc, False)
+        index = sqlPropertyStore(rsrc, use_cache=False)
         index.index._db()
         self.assertTrue(os.path.exists(os.path.join(os.path.dirname(self.collection_name), SQLPropertiesDatabase.dbFilename)),
                         msg="Could not initialize index via collection resource.")
@@ -90,7 +90,7 @@
     def test_db_init_root(self):
         self.collection_name, self.collection_uri = self.mkdtemp("sql")
         rsrc = RootResource(self.collection_name)
-        index = sqlPropertyStore(rsrc, False)
+        index = sqlPropertyStore(rsrc, use_cache=False, root_resource=True)
         index.index._db()
         self.assertTrue(os.path.exists(os.path.join(self.collection_name, SQLPropertiesDatabase.dbFilename)),
                         msg="Could not initialize index via collection resource.")
@@ -158,7 +158,7 @@
             rsrc.writeDeadProperty(md5)
             
             # Check index
-            index = sqlPropertyStore(rsrc, False)
+            index = sqlPropertyStore(rsrc, use_cache=False)
             self._testProperty(index, md5)
             
             def doneDelete(response):
@@ -226,7 +226,7 @@
             rsrc.writeDeadProperty(displayname)
             
             # Check index
-            index = sqlPropertyStore(rsrc, False)
+            index = sqlPropertyStore(rsrc, use_cache=False)
             self._testProperty(index, displayname)
             
             def doneCopy(response):
@@ -244,7 +244,7 @@
                 self._testProperty(index, displayname, "on original resource")
 
                 rsrc_new = CalDAVFile(fpath_new)
-                index_new = sqlPropertyStore(rsrc_new, False)
+                index_new = sqlPropertyStore(rsrc_new, use_cache=False)
                 self._testProperty(index_new, displayname, "on new resource")
 
             # Copy resource and test
@@ -295,7 +295,7 @@
             rsrc.writeDeadProperty(displayname)
             
             # Check index
-            index = sqlPropertyStore(rsrc, False)
+            index = sqlPropertyStore(rsrc, use_cache=False)
             self._testProperty(index, displayname)
             
             def doneMove(response):
@@ -314,7 +314,7 @@
                                  msg="Property %s exists after resource was moved." % displayname)
 
                 rsrc_new = CalDAVFile(fpath_new)
-                index_new = sqlPropertyStore(rsrc_new, False)
+                index_new = sqlPropertyStore(rsrc_new, use_cache=False)
                 self._testProperty(index_new, displayname, "on new resource")
 
             def work():
@@ -375,7 +375,7 @@
         collection_index.cacheAllChildProperties()
 
 
-    def test_user_parent_db(self):
+    def test_avoid_contention(self):
 
         collection_name, _ignore = self.mkdtemp("sql")
 
@@ -384,7 +384,7 @@
         collection_name1_A = os.path.join(collection_name1, "A")
         os.mkdir(collection_name1_A)
         collection1 = CalDAVFile(collection_name1_A)
-        collection1_index = sqlPropertyStore(collection1)
+        collection1_index = sqlPropertyStore(collection1, avoid_contention=False)
         for prop in SQLProps.props:
             self._setProperty(collection1_index, prop)
         self.assertTrue(os.path.exists(os.path.join(collection_name1, SQLPropertiesDatabase.dbFilename)))
@@ -395,7 +395,7 @@
         collection_name2_A = os.path.join(collection_name2, "A")
         os.mkdir(collection_name2_A)
         collection2 = CalDAVFile(collection_name2_A)
-        collection2_index = sqlPropertyStore(collection2, use_parent_db=False)
+        collection2_index = sqlPropertyStore(collection2, avoid_contention=True)
         for prop in SQLProps.props:
             self._setProperty(collection2_index, prop)
         self.assertFalse(os.path.exists(os.path.join(collection_name2, SQLPropertiesDatabase.dbFilename)))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080630/b31a6b97/attachment-0001.html 


More information about the calendarserver-changes mailing list