summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage/bson_collection_catalog_entry.cpp
diff options
context:
space:
mode:
authorDaniel Gottlieb <daniel.gottlieb@10gen.com>2017-05-05 09:41:35 -0400
committerDaniel Gottlieb <daniel.gottlieb@10gen.com>2017-05-05 09:41:35 -0400
commit867eda89f5451408c9ba96eaa1035c89f3401bb1 (patch)
tree9934690c1703c3d4e677561271ce194164b4e896 /src/mongo/db/storage/bson_collection_catalog_entry.cpp
parentaa10fc48720dc915d106bfb14a8c9bc391f10fe6 (diff)
downloadmongo-867eda89f5451408c9ba96eaa1035c89f3401bb1.tar.gz
SERVER-28742: Assign prefixes to collections/indexes when --groupCollections is engaged
Diffstat (limited to 'src/mongo/db/storage/bson_collection_catalog_entry.cpp')
-rw-r--r--src/mongo/db/storage/bson_collection_catalog_entry.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/mongo/db/storage/bson_collection_catalog_entry.cpp b/src/mongo/db/storage/bson_collection_catalog_entry.cpp
index 9bd57ee6941..48e8c41bc50 100644
--- a/src/mongo/db/storage/bson_collection_catalog_entry.cpp
+++ b/src/mongo/db/storage/bson_collection_catalog_entry.cpp
@@ -31,6 +31,7 @@
#include "mongo/db/storage/bson_collection_catalog_entry.h"
#include <algorithm>
+#include <numeric>
#include "mongo/db/field_ref.h"
@@ -175,6 +176,14 @@ bool BSONCollectionCatalogEntry::isIndexReady(OperationContext* opCtx, StringDat
return md.indexes[offset].ready;
}
+KVPrefix BSONCollectionCatalogEntry::getIndexPrefix(OperationContext* opCtx,
+ StringData indexName) const {
+ MetaData md = _getMetaData(opCtx);
+ int offset = md.findIndexOffset(indexName);
+ invariant(offset >= 0);
+ return md.indexes[offset].prefix;
+}
+
// --------------------------
void BSONCollectionCatalogEntry::IndexMetaData::updateTTLSetting(long long newExpireSeconds) {
@@ -228,6 +237,15 @@ void BSONCollectionCatalogEntry::MetaData::rename(StringData toNS) {
}
}
+KVPrefix BSONCollectionCatalogEntry::MetaData::getMaxPrefix() const {
+ // Use the collection prefix as the initial max value seen. Then compare it with each index
+ // prefix. Note the oplog has no indexes so the vector of 'IndexMetaData' may be empty.
+ return std::accumulate(
+ indexes.begin(), indexes.end(), prefix, [](KVPrefix max, IndexMetaData index) {
+ return max < index.prefix ? index.prefix : max;
+ });
+}
+
BSONObj BSONCollectionCatalogEntry::MetaData::toBSON() const {
BSONObjBuilder b;
b.append("ns", ns);
@@ -249,10 +267,12 @@ BSONObj BSONCollectionCatalogEntry::MetaData::toBSON() const {
}
sub.append("head", static_cast<long long>(indexes[i].head.repr()));
+ sub.append("prefix", indexes[i].prefix.toBSONValue());
sub.doneFast();
}
arr.doneFast();
}
+ b.append("prefix", prefix.toBSONValue());
return b.obj();
}
@@ -282,8 +302,11 @@ void BSONCollectionCatalogEntry::MetaData::parse(const BSONObj& obj) {
parseMultikeyPathsFromBytes(multikeyPathsElem.Obj(), &imd.multikeyPaths);
}
+ imd.prefix = KVPrefix::fromBSONElement(idx["prefix"]);
indexes.push_back(imd);
}
}
+
+ prefix = KVPrefix::fromBSONElement(obj["prefix"]);
}
}