From b4ba41a4d11da77437188f3f5d66b003e8ecffac Mon Sep 17 00:00:00 2001 From: Gregory Wlodarek Date: Tue, 4 Feb 2020 15:18:20 -0500 Subject: 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 --- .../noPassthrough/list_indexes_ready_and_in_progress.js | 6 +++++- jstests/noPassthrough/list_indexes_with_build_uuids.js | 9 +++++++-- src/mongo/db/catalog/list_indexes.cpp | 15 +++++++++++---- 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 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 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]); -- cgit v1.2.1