diff options
author | Xiangyu Yao <xiangyu.yao@mongodb.com> | 2017-11-27 18:19:40 -0500 |
---|---|---|
committer | Xiangyu Yao <xiangyu.yao@mongodb.com> | 2017-11-29 20:07:37 -0500 |
commit | 2cc9396586e771a0484a4017bf3f126098818d2b (patch) | |
tree | 66a2201172fd5404dbea3b0344d2d8c8f718b55b /src/mongo/db | |
parent | 4174a84257760cae2ea9fdb26e8d3e65feadf253 (diff) | |
download | mongo-2cc9396586e771a0484a4017bf3f126098818d2b.tar.gz |
SERVER-25175 listIndexes command only includes ready indexes
Diffstat (limited to 'src/mongo/db')
6 files changed, 31 insertions, 1 deletions
diff --git a/src/mongo/db/catalog/collection_catalog_entry.h b/src/mongo/db/catalog/collection_catalog_entry.h index 9a2b6ba8f93..805bd130c46 100644 --- a/src/mongo/db/catalog/collection_catalog_entry.h +++ b/src/mongo/db/catalog/collection_catalog_entry.h @@ -64,6 +64,9 @@ public: virtual void getAllIndexes(OperationContext* opCtx, std::vector<std::string>* names) const = 0; + virtual void getReadyIndexes(OperationContext* opCtx, + std::vector<std::string>* names) const = 0; + virtual BSONObj getIndexSpec(OperationContext* opCtx, StringData idxName) const = 0; /** diff --git a/src/mongo/db/commands/list_indexes.cpp b/src/mongo/db/commands/list_indexes.cpp index d4e77888247..d94c798db00 100644 --- a/src/mongo/db/commands/list_indexes.cpp +++ b/src/mongo/db/commands/list_indexes.cpp @@ -154,7 +154,7 @@ public: vector<string> indexNames; writeConflictRetry(opCtx, "listIndexes", ns.ns(), [&indexNames, &cce, &opCtx] { indexNames.clear(); - cce->getAllIndexes(opCtx, &indexNames); + cce->getReadyIndexes(opCtx, &indexNames); }); auto ws = make_unique<WorkingSet>(); diff --git a/src/mongo/db/storage/bson_collection_catalog_entry.cpp b/src/mongo/db/storage/bson_collection_catalog_entry.cpp index fb47d11a7eb..57440d12e4d 100644 --- a/src/mongo/db/storage/bson_collection_catalog_entry.cpp +++ b/src/mongo/db/storage/bson_collection_catalog_entry.cpp @@ -144,6 +144,16 @@ void BSONCollectionCatalogEntry::getAllIndexes(OperationContext* opCtx, } } +void BSONCollectionCatalogEntry::getReadyIndexes(OperationContext* opCtx, + std::vector<std::string>* names) const { + MetaData md = _getMetaData(opCtx); + + for (unsigned i = 0; i < md.indexes.size(); i++) { + if (md.indexes[i].ready) + names->push_back(md.indexes[i].spec["name"].String()); + } +} + bool BSONCollectionCatalogEntry::isIndexMultikey(OperationContext* opCtx, StringData indexName, MultikeyPaths* multikeyPaths) const { diff --git a/src/mongo/db/storage/bson_collection_catalog_entry.h b/src/mongo/db/storage/bson_collection_catalog_entry.h index 8806829cd0b..6b950cd1a3b 100644 --- a/src/mongo/db/storage/bson_collection_catalog_entry.h +++ b/src/mongo/db/storage/bson_collection_catalog_entry.h @@ -59,6 +59,8 @@ public: virtual void getAllIndexes(OperationContext* opCtx, std::vector<std::string>* names) const; + virtual void getReadyIndexes(OperationContext* opCtx, std::vector<std::string>* names) const; + virtual bool isIndexMultikey(OperationContext* opCtx, StringData indexName, MultikeyPaths* multikeyPaths) const; diff --git a/src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.cpp b/src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.cpp index 98f3808f9ef..75c5365e396 100644 --- a/src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.cpp +++ b/src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.cpp @@ -107,6 +107,19 @@ void NamespaceDetailsCollectionCatalogEntry::getAllIndexes(OperationContext* opC } } +void NamespaceDetailsCollectionCatalogEntry::getReadyIndexes( + OperationContext* opCtx, std::vector<std::string>* names) const { + NamespaceDetails::IndexIterator i = _details->ii(true); + while (i.more()) { + const IndexDetails& id = i.next(); + const BSONObj obj = _indexRecordStore->dataFor(opCtx, id.info.toRecordId()).toBson(); + const char* idxName = obj.getStringField("name"); + if (isIndexReady(opCtx, StringData(idxName))) { + names->push_back(idxName); + } + } +} + bool NamespaceDetailsCollectionCatalogEntry::isIndexMultikey(OperationContext* opCtx, StringData idxName, MultikeyPaths* multikeyPaths) const { diff --git a/src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.h b/src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.h index 9cfbce48933..874f1716881 100644 --- a/src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.h +++ b/src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.h @@ -66,6 +66,8 @@ public: void getAllIndexes(OperationContext* opCtx, std::vector<std::string>* names) const final; + void getReadyIndexes(OperationContext* opCtx, std::vector<std::string>* names) const final; + BSONObj getIndexSpec(OperationContext* opCtx, StringData idxName) const final; bool isIndexMultikey(OperationContext* opCtx, |