summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2020-02-04 15:18:20 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-02-05 00:24:29 +0000
commitb4ba41a4d11da77437188f3f5d66b003e8ecffac (patch)
tree6e946d61043c20d7beb5577c9c72746e2410075e
parent35cf05881732c60b671fbe05c635dd623429c8ee (diff)
downloadmongo-b4ba41a4d11da77437188f3f5d66b003e8ecffac.tar.gz
SERVER-37980 Add a function to the index builds interface to return the build UUID given a namespace and index name and hook it up for listIndexes to use
-rw-r--r--jstests/noPassthrough/list_indexes_ready_and_in_progress.js6
-rw-r--r--jstests/noPassthrough/list_indexes_with_build_uuids.js9
-rw-r--r--src/mongo/db/catalog/list_indexes.cpp15
3 files changed, 23 insertions, 7 deletions
diff --git a/jstests/noPassthrough/list_indexes_ready_and_in_progress.js b/jstests/noPassthrough/list_indexes_ready_and_in_progress.js
index d5c473f4d02..00217196457 100644
--- a/jstests/noPassthrough/list_indexes_ready_and_in_progress.js
+++ b/jstests/noPassthrough/list_indexes_ready_and_in_progress.js
@@ -29,7 +29,11 @@ const createIdx =
IndexBuildTest.waitForIndexBuildToScanCollection(testDB, coll.getName(), 'b_1');
// The listIndexes command supports returning all indexes, including ones that are not ready.
-IndexBuildTest.assertIndexes(coll, 3, ["_id_", "a_1"], ["b_1"], {includeBuildUUIDs: true});
+if (IndexBuildTest.supportsTwoPhaseIndexBuild(conn)) {
+ IndexBuildTest.assertIndexes(coll, 3, ["_id_", "a_1"], ["b_1"], {includeBuildUUIDs: true});
+} else {
+ IndexBuildTest.assertIndexes(coll, 3, ["_id_", "a_1"], ["b_1"], {includeBuildUUIDs: false});
+}
IndexBuildTest.resumeIndexBuilds(conn);
diff --git a/jstests/noPassthrough/list_indexes_with_build_uuids.js b/jstests/noPassthrough/list_indexes_with_build_uuids.js
index 34c4c4cb3ab..711658feb05 100644
--- a/jstests/noPassthrough/list_indexes_with_build_uuids.js
+++ b/jstests/noPassthrough/list_indexes_with_build_uuids.js
@@ -87,8 +87,13 @@ jsTest.log(indexes);
assert.eq(indexes[0].name, "_id_");
assert.eq(indexes[1].name, "first");
-assert.eq(indexes[2].spec.name, "second");
-assert(indexes[2].hasOwnProperty("buildUUID"));
+
+if (IndexBuildTest.supportsTwoPhaseIndexBuild(secondary)) {
+ assert.eq(indexes[2].spec.name, "second");
+ assert(indexes[2].hasOwnProperty("buildUUID"));
+} else {
+ assert.eq(indexes[2].name, "second");
+}
// Allow the replica set to finish the index build.
IndexBuildTest.resumeIndexBuilds(secondary);
diff --git a/src/mongo/db/catalog/list_indexes.cpp b/src/mongo/db/catalog/list_indexes.cpp
index 510fd7e3aec..ff395e72802 100644
--- a/src/mongo/db/catalog/list_indexes.cpp
+++ b/src/mongo/db/catalog/list_indexes.cpp
@@ -68,6 +68,7 @@ std::list<BSONObj> listIndexesInLock(OperationContext* opCtx,
Collection* collection,
const NamespaceString& nss,
bool includeBuildUUIDs) {
+ invariant(opCtx->lockState()->isCollectionLockedForMode(nss, MODE_IS));
auto durableCatalog = DurableCatalog::get(opCtx);
@@ -86,14 +87,20 @@ std::list<BSONObj> listIndexesInLock(OperationContext* opCtx,
auto indexSpec = writeConflictRetry(opCtx, "listIndexes", nss.ns(), [&] {
if (includeBuildUUIDs &&
!durableCatalog->isIndexReady(opCtx, collection->getCatalogId(), indexNames[i])) {
+ // The durable catalog will not have a build UUID for the given index name if it was
+ // not being built with two-phase.
+ const auto durableBuildUUID = DurableCatalog::get(opCtx)->getIndexBuildUUID(
+ opCtx, collection->getCatalogId(), indexNames[i]);
+ if (!durableBuildUUID) {
+ return durableCatalog->getIndexSpec(
+ opCtx, collection->getCatalogId(), indexNames[i]);
+ }
+
BSONObjBuilder builder;
builder.append(
"spec"_sd,
durableCatalog->getIndexSpec(opCtx, collection->getCatalogId(), indexNames[i]));
-
- // TODO(SERVER-37980): Replace with index build UUID.
- auto indexBuildUUID = UUID::gen();
- indexBuildUUID.appendToBuilder(&builder, "buildUUID"_sd);
+ durableBuildUUID->appendToBuilder(&builder, "buildUUID"_sd);
return builder.obj();
}
return durableCatalog->getIndexSpec(opCtx, collection->getCatalogId(), indexNames[i]);