[MongoDB] add indexes in event collection

Now in event collection only ttl index existed, that means response
on queries for event collection will become slower with collection growth.
Additional indexes based on timestamp and event_type fields in improves this.

Closes-bug: #1526793
Change-Id: I87f13262a213828e1aca5fbe60544db78999a341
This commit is contained in:
Igor Degtiarov 2015-12-16 15:48:57 +02:00
parent 512b7f0678
commit 033a2e3fd2
1 changed files with 7 additions and 0 deletions

View File

@ -57,6 +57,13 @@ class Connection(pymongo_base.Connection):
if 'event' not in self.db.conn.collection_names():
self.db.conn.create_collection('event')
# Establish indexes
# NOTE(idegtiarov): This indexes cover get_events, get_event_types, and
# get_trait_types requests based on event_type and timestamp fields.
self.db.event.create_index(
[('event_type', pymongo.ASCENDING),
('timestamp', pymongo.ASCENDING)],
name='event_type_idx'
)
ttl = cfg.CONF.database.event_time_to_live
impl_mongodb.Connection.update_ttl(ttl, 'event_ttl', 'timestamp',
self.db.event)