diff options
author | Daniel Gottlieb <daniel.gottlieb@10gen.com> | 2017-05-05 15:23:14 -0400 |
---|---|---|
committer | Daniel Gottlieb <daniel.gottlieb@10gen.com> | 2017-05-15 14:06:46 -0400 |
commit | b69aed9d10ef66de42880fd379b0a593419b6e47 (patch) | |
tree | 26afd158f751c711682ab801ff028e562b4503af /src/mongo/db/storage/bson_collection_catalog_entry.cpp | |
parent | c31686212e0011909bbe13f8740fe4f45b8117ef (diff) | |
download | mongo-b69aed9d10ef66de42880fd379b0a593419b6e47.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.cpp | 23 |
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"]); } } |