[CalendarServer-changes] [14897] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Wed Jun 17 09:23:36 PDT 2015


Revision: 14897
          http://trac.calendarserver.org//changeset/14897
Author:   cdaboo at apple.com
Date:     2015-06-17 09:23:36 -0700 (Wed, 17 Jun 2015)
Log Message:
-----------
Add some revision clean-up controlapi for debugging.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/controlapi.py
    CalendarServer/trunk/txdav/common/datastore/work/revision_cleanup.py

Modified: CalendarServer/trunk/twistedcaldav/controlapi.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/controlapi.py	2015-06-16 20:37:37 UTC (rev 14896)
+++ CalendarServer/trunk/twistedcaldav/controlapi.py	2015-06-17 16:23:36 UTC (rev 14897)
@@ -352,3 +352,22 @@
         ))
 
         returnValue(self._ok("ok", "Scheduling done"))
+
+
+    @inlineCallbacks
+    def action_revisioncleanup(self, j):
+        """
+        Wait for all schedule queue items to complete.
+        """
+        from txdav.common.datastore.work.revision_cleanup import _triggerRevisionCleanup
+        from txdav.common.datastore.work.revision_cleanup import RevisionCleanupWork
+
+        txn = self._store.newTransaction()
+        yield _triggerRevisionCleanup(txn, 60)
+        yield txn.commit()
+
+        yield JobItem.waitWorkDone(self._store.newTransaction, reactor, 120.0, (
+            RevisionCleanupWork,
+        ))
+
+        returnValue(self._ok("ok", "RevisionCleanupWork done"))

Modified: CalendarServer/trunk/txdav/common/datastore/work/revision_cleanup.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/work/revision_cleanup.py	2015-06-16 20:37:37 UTC (rev 14896)
+++ CalendarServer/trunk/txdav/common/datastore/work/revision_cleanup.py	2015-06-17 16:23:36 UTC (rev 14897)
@@ -86,7 +86,7 @@
 
         if maxRevOlderThanDate > minValidRevision:
             # save new min valid revision
-            yield self.transaction.updateCalendarserverValue("MIN-VALID-REVISION", maxRevOlderThanDate)
+            yield self.transaction.updateCalendarserverValue("MIN-VALID-REVISION", maxRevOlderThanDate + 1)
 
             # Schedule revision cleanup
             yield RevisionCleanupWork.reschedule(self.transaction, seconds=0)
@@ -105,3 +105,42 @@
 
         # delete revisions
         yield self.transaction.deleteRevisionsBefore(minValidRevision)
+
+
+
+ at inlineCallbacks
+def _triggerRevisionCleanup(txn, backSeconds):
+    # Get the minimum valid revision
+    minValidRevision = int((yield txn.calendarserverValue("MIN-VALID-REVISION")))
+
+    # get max revision on table rows before dateLimit
+    dateLimit = (
+        datetime.datetime.utcnow() -
+        datetime.timedelta(seconds=backSeconds)
+    )
+    maxRevOlderThanDate = 0
+
+    # TODO: Use one Select statement
+    for table in (
+        schema.CALENDAR_OBJECT_REVISIONS,
+        schema.NOTIFICATION_OBJECT_REVISIONS,
+        schema.ADDRESSBOOK_OBJECT_REVISIONS,
+        schema.ABO_MEMBERS,
+    ):
+        revisionRows = yield Select(
+            [Max(table.REVISION)],
+            From=table,
+            Where=(table.MODIFIED < dateLimit),
+        ).on(txn)
+
+        if revisionRows:
+            tableMaxRevision = revisionRows[0][0]
+            if tableMaxRevision > maxRevOlderThanDate:
+                maxRevOlderThanDate = tableMaxRevision
+
+    if maxRevOlderThanDate > minValidRevision:
+        # save new min valid revision
+        yield txn.updateCalendarserverValue("MIN-VALID-REVISION", maxRevOlderThanDate + 1)
+
+        # Schedule revision cleanup
+        yield RevisionCleanupWork.reschedule(txn, seconds=0)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150617/ea7bc182/attachment-0001.html>


More information about the calendarserver-changes mailing list