summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorTess Avitabile <tess.avitabile@mongodb.com>2016-10-06 13:22:17 -0400
committerTess Avitabile <tess.avitabile@mongodb.com>2016-10-06 18:51:01 -0400
commite00e6edde50c8eb1ac31ec70e7e8d91c1c6742e6 (patch)
tree573451ba19e68cb06e03c87c1b53e5d22027744f /src/mongo
parent36b0eac52c0ca75aa7171ff977ac37a9bd85d2d1 (diff)
downloadmongo-e00e6edde50c8eb1ac31ec70e7e8d91c1c6742e6.tar.gz
SERVER-26488 BSONObj buffer size used by _id index keys should match object size
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/index/btree_key_generator.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/mongo/db/index/btree_key_generator.cpp b/src/mongo/db/index/btree_key_generator.cpp
index 4f0928794f0..b088db10784 100644
--- a/src/mongo/db/index/btree_key_generator.cpp
+++ b/src/mongo/db/index/btree_key_generator.cpp
@@ -317,10 +317,18 @@ void BtreeKeyGeneratorV1::getKeysImpl(std::vector<const char*> fieldNames,
BSONElement e = obj["_id"];
if (e.eoo()) {
keys->insert(_nullKey);
- } else {
+ } else if (_collator) {
BSONObjBuilder b;
CollationIndexKey::collationAwareIndexKeyAppend(e, _collator, &b);
+
+ // Insert a copy so its buffer size fits the object size.
+ keys->insert(b.obj().copy());
+ } else {
+ int size = e.size() + 5 /* bson over head*/ - 3 /* remove _id string */;
+ BSONObjBuilder b(size);
+ b.appendAs(e, "");
keys->insert(b.obj());
+ invariant(keys->begin()->objsize() == size);
}
// The {_id: 1} index can never be multikey because the _id field isn't allowed to be an