Comment 0 for bug 1291666

Revision history for this message
Eoghan Glynn (eglynn) wrote :

The mongodb driver clearly intends to create indices for both user_id and project_id on the meter and resource tables:

   https://github.com/openstack/ceilometer/blob/master/ceilometer/storage/impl_mongodb.py#L420

However since it uses the same per-collection index name on each iteration of the index-creating for loop, the project_id indices are never created:

> db.meter.getIndexes()
[
 {
  "v" : 1,
  "key" : {
   "_id" : 1
  },
  "ns" : "ceilometer.meter",
  "name" : "_id_"
 },
 {
  "v" : 1,
  "key" : {
   "resource_id" : 1,
   "user_id" : 1,
   "counter_name" : 1,
   "timestamp" : 1,
   "source" : 1
  },
  "ns" : "ceilometer.meter",
  "name" : "meter_idx"
 },
 {
  "v" : 1,
  "key" : {
   "timestamp" : -1
  },
  "ns" : "ceilometer.meter",
  "name" : "timestamp_idx"
 }
]
> db.resource.getIndexes()
[
 {
  "v" : 1,
  "key" : {
   "_id" : 1
  },
  "ns" : "ceilometer.resource",
  "name" : "_id_"
 },
 {
  "v" : 1,
  "key" : {
   "user_id" : 1,
   "source" : 1
  },
  "ns" : "ceilometer.resource",
  "name" : "resource_idx"
 },
 {
  "v" : 1,
  "key" : {
   "last_sample_timestamp" : -1
  },
  "ns" : "ceilometer.resource",
  "sparse" : true,
  "name" : "last_sample_timestamp_idx"
 }
]

Instead, a distinguished index name should be used for the project_id index in each case (e.g. meter_project_id_idx) to avoid the name clash.

Also this new index should be created with background=True to avoid slow start-up on upgrade with large existing collections.