[CalendarServer-changes] [11845] CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 12 11:20:56 PDT 2014
Revision: 11845
http://trac.calendarserver.org//changeset/11845
Author: cdaboo at apple.com
Date: 2013-10-29 17:05:49 -0700 (Tue, 29 Oct 2013)
Log Message:
-----------
Add progress/error logging for store data upgrades.
Modified Paths:
--------------
CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/addressbook_upgrade_from_1_to_2.py
CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_1_to_2.py
CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_3_to_4.py
CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_4_to_5.py
CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/util.py
Modified: CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/addressbook_upgrade_from_1_to_2.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/addressbook_upgrade_from_1_to_2.py 2013-10-29 23:59:02 UTC (rev 11844)
+++ CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/addressbook_upgrade_from_1_to_2.py 2013-10-30 00:05:49 UTC (rev 11845)
@@ -22,7 +22,8 @@
from txdav.base.propertystore.base import PropertyName
from txdav.common.datastore.sql_tables import _ABO_KIND_GROUP, schema
from txdav.common.datastore.upgrade.sql.upgrades.util import updateAddressBookDataVersion, \
- doToEachHomeNotAtVersion, removeProperty, cleanPropertyStore
+ doToEachHomeNotAtVersion, removeProperty, cleanPropertyStore, \
+ logUpgradeStatus
from txdav.xml import element
"""
@@ -73,14 +74,20 @@
#update rest
yield abObject.setComponent(component)
+ logUpgradeStatus("Starting Addressbook Populate Members")
+
# Do this to each calendar home not already at version 2
- yield doToEachHomeNotAtVersion(sqlStore, schema.ADDRESSBOOK_HOME, UPGRADE_TO_VERSION, doIt)
+ yield doToEachHomeNotAtVersion(sqlStore, schema.ADDRESSBOOK_HOME, UPGRADE_TO_VERSION, doIt, "Populate Members")
@inlineCallbacks
def removeResourceType(sqlStore):
+ logUpgradeStatus("Starting Addressbook Remove Resource Type")
+
sqlTxn = sqlStore.newTransaction()
yield removeProperty(sqlTxn, PropertyName.fromElement(element.ResourceType))
yield sqlTxn.commit()
yield cleanPropertyStore()
+
+ logUpgradeStatus("End Addressbook Remove Resource Type")
Modified: CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_1_to_2.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_1_to_2.py 2013-10-29 23:59:02 UTC (rev 11844)
+++ CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_1_to_2.py 2013-10-30 00:05:49 UTC (rev 11845)
@@ -16,12 +16,16 @@
##
from twext.enterprise.dal.syntax import Update
-from txdav.xml.parser import WebDAVDocument
+
from twisted.internet.defer import inlineCallbacks
+
from twistedcaldav import caldavxml
+
from txdav.common.datastore.sql_tables import schema
from txdav.common.datastore.upgrade.sql.upgrades.util import rowsForProperty,\
- removeProperty, updateCalendarDataVersion, doToEachHomeNotAtVersion
+ removeProperty, updateCalendarDataVersion, doToEachHomeNotAtVersion, \
+ logUpgradeStatus, logUpgradeError
+from txdav.xml.parser import WebDAVDocument
"""
Calendar data upgrade from database version 1 to 2
@@ -50,9 +54,14 @@
extracting the new format value from the XML property.
"""
+ logUpgradeStatus("Starting Move supported-component-set")
+
sqlTxn = sqlStore.newTransaction()
try:
+ calendar_rid = None
rows = (yield rowsForProperty(sqlTxn, caldavxml.SupportedCalendarComponentSet))
+ total = len(rows)
+ count = 0
for calendar_rid, value in rows:
prop = WebDAVDocument.fromString(value).root_element
supported_components = ",".join(sorted([comp.attributes["name"].upper() for comp in prop.children]))
@@ -63,11 +72,19 @@
},
Where=(meta.RESOURCE_ID == calendar_rid)
).on(sqlTxn)
+ count += 1
+ logUpgradeStatus("Move supported-component-set", count, total)
yield removeProperty(sqlTxn, caldavxml.SupportedCalendarComponentSet)
yield sqlTxn.commit()
+
+ logUpgradeStatus("End Move supported-component-set")
except RuntimeError:
yield sqlTxn.abort()
+ logUpgradeError(
+ "Move supported-component-set",
+ "Last calendar: {}".format(calendar_rid)
+ )
raise
@@ -86,5 +103,7 @@
home = yield txn.calendarHomeWithResourceID(homeResourceID)
yield home.splitCalendars()
+ logUpgradeStatus("Starting Split Calendars")
+
# Do this to each calendar home not already at version 2
- yield doToEachHomeNotAtVersion(sqlStore, schema.CALENDAR_HOME, UPGRADE_TO_VERSION, doIt)
+ yield doToEachHomeNotAtVersion(sqlStore, schema.CALENDAR_HOME, UPGRADE_TO_VERSION, doIt, "Split Calendars")
Modified: CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_3_to_4.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_3_to_4.py 2013-10-29 23:59:02 UTC (rev 11844)
+++ CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_3_to_4.py 2013-10-30 00:05:49 UTC (rev 11845)
@@ -25,7 +25,8 @@
from txdav.caldav.icalendarstore import InvalidDefaultCalendar
from txdav.common.datastore.sql_tables import schema, _BIND_MODE_OWN
from txdav.common.datastore.upgrade.sql.upgrades.util import rowsForProperty, updateCalendarDataVersion, \
- updateAllCalendarHomeDataVersions, removeProperty, cleanPropertyStore
+ updateAllCalendarHomeDataVersions, removeProperty, countProperty, cleanPropertyStore, \
+ logUpgradeStatus, logUpgradeError
from txdav.xml.parser import WebDAVDocument
from txdav.xml import element
from twisted.python.failure import Failure
@@ -78,13 +79,22 @@
cb = schema.CALENDAR_BIND
rp = schema.RESOURCE_PROPERTY
+ logUpgradeStatus("Starting Process {}".format(propname.qname()))
+
+ sqlTxn = sqlStore.newTransaction()
+ total = (yield countProperty(sqlTxn, propname))
+ yield sqlTxn.commit()
+ count = 0
+
try:
+ inbox_rid = None
while True:
sqlTxn = sqlStore.newTransaction()
rows = (yield rowsForProperty(sqlTxn, propname, batch=BATCH_SIZE))
if len(rows) == 0:
yield sqlTxn.commit()
break
+
delete_ids = []
for inbox_rid, value in rows:
delete_ids.append(inbox_rid)
@@ -127,10 +137,22 @@
yield sqlTxn.commit()
+ count += len(rows)
+ logUpgradeStatus(
+ "Process {}".format(propname.qname()),
+ count,
+ total
+ )
+
yield cleanPropertyStore()
+ logUpgradeStatus("End Process {}".format(propname.qname()))
- except RuntimeError:
+ except RuntimeError as e:
f = Failure()
+ logUpgradeError(
+ "Process {}".format(propname.qname()),
+ "Inbox: {}, error: {}".format(inbox_rid, e),
+ )
yield sqlTxn.abort()
f.raiseException()
@@ -147,14 +169,24 @@
cb = schema.CALENDAR_BIND
rp = schema.RESOURCE_PROPERTY
+ propname = caldavxml.ScheduleCalendarTransp
+ logUpgradeStatus("Starting Process {}".format(propname.qname()))
+
+ sqlTxn = sqlStore.newTransaction()
+ total = (yield countProperty(sqlTxn, propname))
+ yield sqlTxn.commit()
+ count = 0
+
try:
+ calendar_rid = None
calendars_for_id = {}
while True:
sqlTxn = sqlStore.newTransaction()
- rows = (yield rowsForProperty(sqlTxn, caldavxml.ScheduleCalendarTransp, with_uid=True, batch=BATCH_SIZE))
+ rows = (yield rowsForProperty(sqlTxn, propname, with_uid=True, batch=BATCH_SIZE))
if len(rows) == 0:
yield sqlTxn.commit()
break
+
delete_ids = []
for calendar_rid, value, viewer in rows:
delete_ids.append(calendar_rid)
@@ -191,13 +223,25 @@
yield sqlTxn.commit()
+ count += len(rows)
+ logUpgradeStatus(
+ "Process {}".format(propname.qname()),
+ count,
+ total,
+ )
+
sqlTxn = sqlStore.newTransaction()
yield removeProperty(sqlTxn, PropertyName.fromElement(caldavxml.CalendarFreeBusySet))
yield sqlTxn.commit()
yield cleanPropertyStore()
+ logUpgradeStatus("End Process {}".format(propname.qname()))
- except RuntimeError:
+ except RuntimeError as e:
f = Failure()
+ logUpgradeError(
+ "Process {}".format(propname.qname()),
+ "Inbox: {}, error: {}".format(calendar_rid, e),
+ )
yield sqlTxn.abort()
f.raiseException()
@@ -250,7 +294,15 @@
cb = schema.CALENDAR_BIND
rp = schema.RESOURCE_PROPERTY
+ logUpgradeStatus("Starting Process {} {}".format(propname.qname(), vevent))
+
+ sqlTxn = sqlStore.newTransaction()
+ total = (yield countProperty(sqlTxn, propname))
+ yield sqlTxn.commit()
+ count = 0
+
try:
+ rid = None
calendars_for_id = {}
while True:
sqlTxn = sqlStore.newTransaction()
@@ -258,6 +310,7 @@
if len(rows) == 0:
yield sqlTxn.commit()
break
+
delete_ids = []
for rid, value, viewer in rows:
delete_ids.append(rid)
@@ -311,10 +364,22 @@
yield sqlTxn.commit()
+ count += len(rows)
+ logUpgradeStatus(
+ "Process {} {}".format(propname.qname(), vevent),
+ count,
+ total,
+ )
+
yield cleanPropertyStore()
+ logUpgradeStatus("End Process {} {}".format(propname.qname(), vevent))
- except RuntimeError:
+ except RuntimeError as e:
f = Failure()
+ logUpgradeError(
+ "Process {} {}".format(propname.qname(), vevent),
+ "Rid: {}, error: {}".format(rid, e),
+ )
yield sqlTxn.abort()
f.raiseException()
@@ -322,7 +387,11 @@
@inlineCallbacks
def removeResourceType(sqlStore):
+ logUpgradeStatus("Starting Calendar Remove Resource Type")
+
sqlTxn = sqlStore.newTransaction()
yield removeProperty(sqlTxn, PropertyName.fromElement(element.ResourceType))
yield sqlTxn.commit()
yield cleanPropertyStore()
+
+ logUpgradeStatus("End Calendar Remove Resource Type")
Modified: CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_4_to_5.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_4_to_5.py 2013-10-29 23:59:02 UTC (rev 11844)
+++ CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_4_to_5.py 2013-10-30 00:05:49 UTC (rev 11845)
@@ -25,7 +25,8 @@
from txdav.base.propertystore.base import PropertyName
from txdav.common.datastore.sql_tables import schema, _BIND_MODE_OWN
from txdav.common.datastore.upgrade.sql.upgrades.util import rowsForProperty, updateCalendarDataVersion, \
- updateAllCalendarHomeDataVersions, removeProperty, cleanPropertyStore
+ updateAllCalendarHomeDataVersions, removeProperty, cleanPropertyStore, \
+ logUpgradeStatus, countProperty, logUpgradeError
from txdav.xml import element
from txdav.xml.parser import WebDAVDocument
from twext.web2.dav.resource import TwistedQuotaUsedProperty, \
@@ -64,14 +65,24 @@
cb = schema.CALENDAR_BIND
rp = schema.RESOURCE_PROPERTY
+ propname = caldavxml.CalendarTimeZone
+ logUpgradeStatus("Starting Process {}".format(propname.qname()))
+
+ sqlTxn = sqlStore.newTransaction()
+ total = (yield countProperty(sqlTxn, propname))
+ yield sqlTxn.commit()
+ count = 0
+
try:
+ calendar_rid = None
calendars_for_id = {}
while True:
sqlTxn = sqlStore.newTransaction()
- rows = (yield rowsForProperty(sqlTxn, caldavxml.CalendarTimeZone, with_uid=True, batch=BATCH_SIZE))
+ rows = (yield rowsForProperty(sqlTxn, propname, with_uid=True, batch=BATCH_SIZE))
if len(rows) == 0:
yield sqlTxn.commit()
break
+
delete_ids = []
for calendar_rid, value, viewer in rows:
delete_ids.append(calendar_rid)
@@ -107,11 +118,22 @@
).on(sqlTxn, ids=delete_ids)
yield sqlTxn.commit()
+ count += len(rows)
+ logUpgradeStatus(
+ "Process {}".format(propname.qname()),
+ count,
+ total,
+ )
yield cleanPropertyStore()
+ logUpgradeStatus("End Process {}".format(propname.qname()))
- except RuntimeError:
+ except RuntimeError as e:
f = Failure()
+ logUpgradeError(
+ "Process {}".format(propname.qname()),
+ "Rid: {}, error: {}".format(calendar_rid, e),
+ )
yield sqlTxn.abort()
f.raiseException()
@@ -128,10 +150,19 @@
cb = schema.CALENDAR_BIND
rp = schema.RESOURCE_PROPERTY
+ propname = customxml.CalendarAvailability
+ logUpgradeStatus("Starting Process {}".format(propname.qname()))
+
+ sqlTxn = sqlStore.newTransaction()
+ total = (yield countProperty(sqlTxn, propname))
+ yield sqlTxn.commit()
+ count = 0
+
try:
+ calendar_rid = None
while True:
sqlTxn = sqlStore.newTransaction()
- rows = (yield rowsForProperty(sqlTxn, customxml.CalendarAvailability, batch=BATCH_SIZE))
+ rows = (yield rowsForProperty(sqlTxn, propname, batch=BATCH_SIZE))
if len(rows) == 0:
yield sqlTxn.commit()
break
@@ -164,10 +195,22 @@
yield sqlTxn.commit()
+ count += len(rows)
+ logUpgradeStatus(
+ "Process {}".format(propname.qname()),
+ count,
+ total,
+ )
+
yield cleanPropertyStore()
+ logUpgradeStatus("End Process {}".format(propname.qname()))
- except RuntimeError:
+ except RuntimeError as e:
f = Failure()
+ logUpgradeError(
+ "Process {}".format(propname.qname()),
+ "Rid: {}, error: {}".format(calendar_rid, e),
+ )
yield sqlTxn.abort()
f.raiseException()
@@ -190,6 +233,8 @@
{http://twistedmatrix.com/xml_namespace/dav/}schedule-auto-respond
"""
+ logUpgradeStatus("Starting Calendar Remove Other Properties")
+
sqlTxn = sqlStore.newTransaction()
yield removeProperty(sqlTxn, PropertyName.fromElement(element.ACL))
@@ -205,3 +250,5 @@
yield sqlTxn.commit()
yield cleanPropertyStore()
+
+ logUpgradeStatus("End Calendar Remove Other Properties")
Modified: CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/util.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/util.py 2013-10-29 23:59:02 UTC (rev 11844)
+++ CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/util.py 2013-10-30 00:05:49 UTC (rev 11845)
@@ -14,7 +14,7 @@
# limitations under the License.
##
-from twext.enterprise.dal.syntax import Select, Delete, Update
+from twext.enterprise.dal.syntax import Select, Delete, Update, Count
from twext.python.log import Logger
from twisted.internet.defer import inlineCallbacks, returnValue
from txdav.base.propertystore.base import PropertyName
@@ -44,6 +44,21 @@
@inlineCallbacks
+def countProperty(txn, propelement):
+ pname = PropertyName.fromElement(propelement)
+
+ rp = schema.RESOURCE_PROPERTY
+ count = (yield Select(
+ [Count(rp.RESOURCE_ID), ],
+ From=rp,
+ Where=rp.NAME == pname.toString(),
+ ).on(txn))[0][0]
+
+ returnValue(count)
+
+
+
+ at inlineCallbacks
def cleanPropertyStore():
"""
We have manually manipulated the SQL property store by-passing the underlying implementation's caching
@@ -114,14 +129,25 @@
@inlineCallbacks
-def doToEachHomeNotAtVersion(store, homeSchema, version, doIt):
+def doToEachHomeNotAtVersion(store, homeSchema, version, doIt, logStr):
"""
Do something to each home whose version column indicates it is older
than the specified version. Do this in batches as there may be a lot of work to do.
"""
+ txn = store.newTransaction("updateDataVersion")
+ total = (yield Select(
+ [Count(homeSchema.RESOURCE_ID), ],
+ From=homeSchema,
+ Where=homeSchema.DATAVERSION < version,
+ ).on(txn))[0][0]
+ yield txn.commit()
+ count = 0
+
while True:
+ logUpgradeStatus(logStr, count, total)
+
# Get the next home with an old version
txn = store.newTransaction("updateDataVersion")
try:
@@ -135,6 +161,7 @@
if len(rows) == 0:
yield txn.commit()
+ logUpgradeStatus("End {}".format(logStr), count, total)
returnValue(None)
# Apply to the home
@@ -149,6 +176,26 @@
yield txn.commit()
except RuntimeError, e:
f = Failure()
- log.error("Failed to upgrade %s to %s: %s" % (homeSchema, version, e))
+ logUpgradeError(
+ logStr,
+ "Failed to upgrade {} to {}: {}".format(homeSchema, version, e)
+ )
yield txn.abort()
f.raiseException()
+
+ count += 1
+
+
+
+def logUpgradeStatus(title, count=None, total=None):
+ if total is None:
+ log.info("Database upgrade {title}", title=title)
+ else:
+ divisor = 1000 if total > 1000 else 100
+ if (divmod(count, divisor)[1] == 0) or (count == total):
+ log.info("Database upgrade {title}: {count} of {total}", title=title, count=count, total=total)
+
+
+
+def logUpgradeError(title, details):
+ log.error("Database upgrade {title} failed: {details}", title=title, details=details)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/656c733b/attachment.html>
More information about the calendarserver-changes
mailing list