[CalendarServer-changes] [6562] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Wed Nov 3 13:00:53 PDT 2010
Revision: 6562
http://trac.macosforge.org/projects/calendarserver/changeset/6562
Author: cdaboo at apple.com
Date: 2010-11-03 13:00:51 -0700 (Wed, 03 Nov 2010)
Log Message:
-----------
Remove lock contention on home table by using a different table for meta-data.
Modified Paths:
--------------
CalendarServer/trunk/contrib/tools/LO_DB_upgrade.py
CalendarServer/trunk/txdav/caldav/datastore/sql.py
CalendarServer/trunk/txdav/carddav/datastore/sql.py
CalendarServer/trunk/txdav/common/datastore/sql.py
CalendarServer/trunk/txdav/common/datastore/sql_schema_v1.sql
CalendarServer/trunk/txdav/common/datastore/sql_tables.py
Modified: CalendarServer/trunk/contrib/tools/LO_DB_upgrade.py
===================================================================
--- CalendarServer/trunk/contrib/tools/LO_DB_upgrade.py 2010-11-03 19:51:58 UTC (rev 6561)
+++ CalendarServer/trunk/contrib/tools/LO_DB_upgrade.py 2010-11-03 20:00:51 UTC (rev 6562)
@@ -160,30 +160,54 @@
removeProperty(TwistedCalendarHasPrivateCommentsProperty)
db.commit()
- # Alter the CALENDAR_HOME table and add columns
- print "Alter the CALENDAR_HOME table"
+ # Create the CALENDAR_HOME_METADATA table
+ print "Create the CALENDAR_HOME_METADATA table"
try:
query(db, """
- alter table CALENDAR_HOME
- add column
- QUOTA_USED_BYTES integer default 0 not null;
+ ----------------------------
+ -- Calendar Home Metadata --
+ ----------------------------
+
+ create table CALENDAR_HOME_METADATA (
+ RESOURCE_ID integer not null references CALENDAR_HOME on delete cascade,
+ QUOTA_USED_BYTES integer default 0 not null
+ );
""")
+ # Provision with empty data
+ query(db, """
+ insert into CALENDAR_HOME_METADATA
+ select RESOURCE_ID from CALENDAR_HOME
+ """, ()
+ )
+
except pg.DatabaseError, e:
if str(e).find("already exists") == -1:
print "Fatal SQL error: %s" % (e,)
sys.exit(1)
db.commit()
- # Alter the ADDRESSBOOK_HOME table and add columns
- print "Alter the ADDRESSBOOK_HOME table"
+ # Alter the ADDRESSBOOK_HOME_METADATA table
+ print "Create the ADDRESSBOOK_HOME_METADATA table"
try:
query(db, """
- alter table ADDRESSBOOK_HOME
- add column
- QUOTA_USED_BYTES integer default 0 not null;
+ --------------------------------
+ -- AddressBook Home Meta-data --
+ --------------------------------
+
+ create table ADDRESSBOOK_HOME_METADATA (
+ RESOURCE_ID integer not null references ADDRESSBOOK_HOME on delete cascade,
+ QUOTA_USED_BYTES integer default 0 not null
+ );
""")
+ # Provision with empty data
+ query(db, """
+ insert into ADDRESSBOOK_HOME_METADATA
+ select RESOURCE_ID from ADDRESSBOOK_HOME
+ """, ()
+ )
+
except pg.DatabaseError, e:
if str(e).find("already exists") == -1:
print "Fatal SQL error: %s" % (e,)
@@ -201,13 +225,13 @@
# Since we don't know whether the resource-id is a calendar home or addressbook home
# just try updating both tables - the one that does not match will simply be ignored.
query(db, """
- update CALENDAR_HOME
+ update CALENDAR_HOME_METADATA
set QUOTA_USED_BYTES = %s
where RESOURCE_ID = %s
""", (int(str(prop)), resource_id,)
)
query(db, """
- update ADDRESSBOOK_HOME
+ update ADDRESSBOOK_HOME_METADATA
set QUOTA_USED_BYTES = %s
where RESOURCE_ID = %s
""", (int(str(prop)), resource_id,)
Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/sql.py 2010-11-03 19:51:58 UTC (rev 6561)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py 2010-11-03 20:00:51 UTC (rev 6562)
@@ -53,7 +53,7 @@
SQLLegacyCalendarShares, PostgresLegacyInboxIndexEmulator
from txdav.common.datastore.sql_tables import CALENDAR_TABLE,\
CALENDAR_BIND_TABLE, CALENDAR_OBJECT_REVISIONS_TABLE, CALENDAR_OBJECT_TABLE,\
- _ATTACHMENTS_MODE_WRITE, CALENDAR_HOME_TABLE
+ _ATTACHMENTS_MODE_WRITE, CALENDAR_HOME_TABLE, CALENDAR_HOME_METADATA_TABLE
from txdav.common.icommondatastore import IndexedSearchException
from vobject.icalendar import utc
@@ -69,6 +69,7 @@
def __init__(self, transaction, ownerUID, notifier):
self._homeTable = CALENDAR_HOME_TABLE
+ self._homeMetaDataTable = CALENDAR_HOME_METADATA_TABLE
self._childClass = Calendar
self._childTable = CALENDAR_TABLE
self._bindTable = CALENDAR_BIND_TABLE
Modified: CalendarServer/trunk/txdav/carddav/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/carddav/datastore/sql.py 2010-11-03 19:51:58 UTC (rev 6561)
+++ CalendarServer/trunk/txdav/carddav/datastore/sql.py 2010-11-03 20:00:51 UTC (rev 6562)
@@ -48,7 +48,8 @@
CommonObjectResource
from txdav.common.datastore.sql_tables import ADDRESSBOOK_TABLE,\
ADDRESSBOOK_BIND_TABLE, ADDRESSBOOK_OBJECT_REVISIONS_TABLE,\
- ADDRESSBOOK_OBJECT_TABLE, ADDRESSBOOK_HOME_TABLE
+ ADDRESSBOOK_OBJECT_TABLE, ADDRESSBOOK_HOME_TABLE,\
+ ADDRESSBOOK_HOME_METADATA_TABLE
from txdav.base.propertystore.base import PropertyName
@@ -60,6 +61,7 @@
def __init__(self, transaction, ownerUID, notifier):
self._homeTable = ADDRESSBOOK_HOME_TABLE
+ self._homeMetaDataTable = ADDRESSBOOK_HOME_METADATA_TABLE
self._childClass = AddressBook
self._childTable = ADDRESSBOOK_TABLE
self._bindTable = ADDRESSBOOK_BIND_TABLE
Modified: CalendarServer/trunk/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql.py 2010-11-03 19:51:58 UTC (rev 6561)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py 2010-11-03 20:00:51 UTC (rev 6562)
@@ -50,7 +50,8 @@
from txdav.common.datastore.sql_tables import CALENDAR_HOME_TABLE, \
ADDRESSBOOK_HOME_TABLE, NOTIFICATION_HOME_TABLE, _BIND_MODE_OWN, \
- _BIND_STATUS_ACCEPTED, NOTIFICATION_OBJECT_REVISIONS_TABLE
+ _BIND_STATUS_ACCEPTED, NOTIFICATION_OBJECT_REVISIONS_TABLE,\
+ CALENDAR_HOME_METADATA_TABLE, ADDRESSBOOK_HOME_METADATA_TABLE
from txdav.common.icommondatastore import HomeChildNameNotAllowedError, \
HomeChildNameAlreadyExistsError, NoSuchHomeChildError, \
ObjectResourceNameNotAllowedError, ObjectResourceNameAlreadyExistsError, \
@@ -132,6 +133,7 @@
"""
_homeClass = {}
_homeTable = {}
+ _homeMetaDataTable = {}
id = 0
@@ -163,6 +165,8 @@
CommonStoreTransaction._homeClass[EADDRESSBOOKTYPE] = AddressBookHome
CommonStoreTransaction._homeTable[ECALENDARTYPE] = CALENDAR_HOME_TABLE
CommonStoreTransaction._homeTable[EADDRESSBOOKTYPE] = ADDRESSBOOK_HOME_TABLE
+ CommonStoreTransaction._homeMetaDataTable[ECALENDARTYPE] = CALENDAR_HOME_METADATA_TABLE
+ CommonStoreTransaction._homeMetaDataTable[EADDRESSBOOKTYPE] = ADDRESSBOOK_HOME_METADATA_TABLE
self._sqlTxn = sqlTxn
@@ -217,9 +221,15 @@
[uid]
)
if not exists:
+ resourceid = (yield self.execSQL("""
+ insert into %(name)s (%(column_OWNER_UID)s) values (%%s)
+ returning %(column_RESOURCE_ID)s
+ """ % CommonStoreTransaction._homeTable[storeType],
+ [uid]
+ ))[0][0]
yield self.execSQL(
- "insert into %(name)s (%(column_OWNER_UID)s) values (%%s)" % CommonStoreTransaction._homeTable[storeType],
- [uid]
+ "insert into %(name)s (%(column_RESOURCE_ID)s) values (%%s)" % CommonStoreTransaction._homeMetaDataTable[storeType],
+ [resourceid]
)
home = yield self.homeWithUID(storeType, uid)
if not exists:
@@ -315,6 +325,7 @@
class CommonHome(LoggingMixIn):
_homeTable = None
+ _homeMetaDataTable = None
_childClass = None
_childTable = None
_bindTable = None
@@ -744,8 +755,8 @@
def quotaUsedBytes(self):
returnValue((yield self._txn.execSQL(
"select %(column_QUOTA_USED_BYTES)s from %(name)s"
- " where %(column_OWNER_UID)s = %%s" % self._homeTable,
- [self._ownerUID]
+ " where %(column_RESOURCE_ID)s = %%s" % self._homeMetaDataTable,
+ [self._resourceID]
))[0][0])
@@ -760,7 +771,7 @@
select * from %(name)s
where %(column_RESOURCE_ID)s = %%s
for update
- """ % self._homeTable,
+ """ % self._homeMetaDataTable,
[self._resourceID]
)
@@ -769,7 +780,7 @@
set %(column_QUOTA_USED_BYTES)s = %(column_QUOTA_USED_BYTES)s + %%s
where %(column_RESOURCE_ID)s = %%s
returning %(column_QUOTA_USED_BYTES)s
- """ % self._homeTable,
+ """ % self._homeMetaDataTable,
[delta, self._resourceID]
))[0][0]
# Double check integrity
@@ -779,7 +790,7 @@
update %(name)s
set %(column_QUOTA_USED_BYTES)s = 0
where %(column_RESOURCE_ID)s = %%s
- """ % self._homeTable,
+ """ % self._homeMetaDataTable,
[self._resourceID]
)
Modified: CalendarServer/trunk/txdav/common/datastore/sql_schema_v1.sql
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql_schema_v1.sql 2010-11-03 19:51:58 UTC (rev 6561)
+++ CalendarServer/trunk/txdav/common/datastore/sql_schema_v1.sql 2010-11-03 20:00:51 UTC (rev 6562)
@@ -11,7 +11,16 @@
create table CALENDAR_HOME (
RESOURCE_ID integer primary key default nextval('RESOURCE_ID_SEQ'),
- OWNER_UID varchar(255) not null unique,
+ OWNER_UID varchar(255) not null unique
+);
+
+
+----------------------------
+-- Calendar Home Metadata --
+----------------------------
+
+create table CALENDAR_HOME_METADATA (
+ RESOURCE_ID integer not null references CALENDAR_HOME on delete cascade,
QUOTA_USED_BYTES integer default 0 not null
);
@@ -266,7 +275,16 @@
create table ADDRESSBOOK_HOME (
RESOURCE_ID integer primary key default nextval('RESOURCE_ID_SEQ'),
- OWNER_UID varchar(255) not null unique,
+ OWNER_UID varchar(255) not null unique
+);
+
+
+--------------------------------
+-- AddressBook Home Meta-data --
+--------------------------------
+
+create table ADDRESSBOOK_HOME_METADATA (
+ RESOURCE_ID integer not null references ADDRESSBOOK_HOME on delete cascade,
QUOTA_USED_BYTES integer default 0 not null
);
Modified: CalendarServer/trunk/txdav/common/datastore/sql_tables.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql_tables.py 2010-11-03 19:51:58 UTC (rev 6561)
+++ CalendarServer/trunk/txdav/common/datastore/sql_tables.py 2010-11-03 20:00:51 UTC (rev 6562)
@@ -23,6 +23,11 @@
"name" : "CALENDAR_HOME",
"column_RESOURCE_ID" : "RESOURCE_ID",
"column_OWNER_UID" : "OWNER_UID",
+}
+
+CALENDAR_HOME_METADATA_TABLE = {
+ "name" : "CALENDAR_HOME_METADATA",
+ "column_RESOURCE_ID" : "RESOURCE_ID",
"column_QUOTA_USED_BYTES" : "QUOTA_USED_BYTES",
}
@@ -30,6 +35,11 @@
"name" : "ADDRESSBOOK_HOME",
"column_RESOURCE_ID" : "RESOURCE_ID",
"column_OWNER_UID" : "OWNER_UID",
+}
+
+ADDRESSBOOK_HOME_METADATA_TABLE = {
+ "name" : "ADDRESSBOOK_HOME_METADATA",
+ "column_RESOURCE_ID" : "RESOURCE_ID",
"column_QUOTA_USED_BYTES" : "QUOTA_USED_BYTES",
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20101103/87437fc7/attachment-0001.html>
More information about the calendarserver-changes
mailing list