blobserver/mongo, missing index on "key"

The mongo blobserver does not ensure an index on "key" key which stores
the blobref.
It is slow and enumerate fails when there are too many blobs
because mongodb can't sort when there are too many results.

Change-Id: Id644a48f93be308007f77cf5ea6b6620acf489bd
This commit is contained in:
Antonin Amand 2014-09-20 20:19:41 +02:00
parent 2bde109c41
commit b18a28edd1
1 changed files with 12 additions and 1 deletions

View File

@ -69,13 +69,24 @@ func newFromConfig(_ blobserver.Loader, config jsonconfig.Obj) (blobserver.Stora
return newMongoStorage(cfg)
}
var uniqueKeyIndex = mgo.Index{
Key: []string{"key"},
Unique: true,
DropDups: false,
Background: false,
Sparse: false,
}
func newMongoStorage(cfg config) (blobserver.Storage, error) {
session, err := getConnection(cfg.url())
if err != nil {
return nil, err
}
c := session.DB(cfg.database).C(cfg.collection)
err = c.EnsureIndex(uniqueKeyIndex)
if err != nil {
return nil, err
}
return blobserver.Storage(&mongoStorage{c: c}), nil
}