From 9ffba6fb700e6830c62a5ce68e4c2753128f75bf Mon Sep 17 00:00:00 2001 From: Eoghan Glynn Date: Wed, 12 Mar 2014 23:36:12 +0000 Subject: [PATCH] Ensure intended indices on project_id are created for mongo Fixes bug 1291666 Previously, despite the clear intent of the code, the mongodb driver failed to create indices on project_id for the meter and resource collections, due to a index name clash. Now, we ensure a different index name is used for the user_id and project_id indices on each collection. The previously missing index is created in the background to avoid blocking other DB operations when upgrading against an existing mongo instance with large collections. Change-Id: Ia3c6765445f16ab9beafbd7fd9265a045814003f --- ceilometer/storage/impl_mongodb.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ceilometer/storage/impl_mongodb.py b/ceilometer/storage/impl_mongodb.py index aba00c4c5..c6eb7d3e2 100644 --- a/ceilometer/storage/impl_mongodb.py +++ b/ceilometer/storage/impl_mongodb.py @@ -453,18 +453,24 @@ class Connection(pymongo_base.Connection): # project_id values are usually mutually exclusive in the # queries, so the database won't take advantage of an index # including both. + name_qualifier = dict(user_id='', project_id='project_') + background = dict(user_id=False, project_id=True) for primary in ['user_id', 'project_id']: + name = 'resource_%sidx' % name_qualifier[primary] self.db.resource.ensure_index([ (primary, pymongo.ASCENDING), ('source', pymongo.ASCENDING), - ], name='resource_idx') + ], name=name, background=background[primary]) + + name = 'meter_%sidx' % name_qualifier[primary] self.db.meter.ensure_index([ ('resource_id', pymongo.ASCENDING), (primary, pymongo.ASCENDING), ('counter_name', pymongo.ASCENDING), ('timestamp', pymongo.ASCENDING), ('source', pymongo.ASCENDING), - ], name='meter_idx') + ], name=name, background=background[primary]) + self.db.resource.ensure_index([('last_sample_timestamp', pymongo.DESCENDING)], name='last_sample_timestamp_idx',