summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2019-03-14 09:07:04 -0400
committerGregory Wlodarek <gregory.wlodarek@mongodb.com>2019-03-20 12:38:17 -0400
commit79a301a6fdf621019259a01f95ddbe9a1ebd8205 (patch)
treeef6590b6ee75e1baba4a487b0e596fd74e3ab7b4
parent4f32712c85b266bf7b4a96b402472309a7f18610 (diff)
downloadmongo-79a301a6fdf621019259a01f95ddbe9a1ebd8205.tar.gz
SERVER-26625 Make collStats command consistent on background index reporting
-rw-r--r--jstests/noPassthroughWithMongod/collstats_shows_ready_and_in_progress_indexes.js54
-rw-r--r--src/mongo/db/stats/storage_stats.cpp11
2 files changed, 63 insertions, 2 deletions
diff --git a/jstests/noPassthroughWithMongod/collstats_shows_ready_and_in_progress_indexes.js b/jstests/noPassthroughWithMongod/collstats_shows_ready_and_in_progress_indexes.js
new file mode 100644
index 00000000000..3c509bdc32f
--- /dev/null
+++ b/jstests/noPassthroughWithMongod/collstats_shows_ready_and_in_progress_indexes.js
@@ -0,0 +1,54 @@
+/**
+ * Ensures that the 'collStats' command lists indexes that are ready and in-progress.
+ */
+(function() {
+ 'use strict';
+
+ load('jstests/noPassthrough/libs/index_build.js');
+
+ const failpoint = 'hangAfterStartingIndexBuildUnlocked';
+ assert.commandWorked(db.adminCommand({configureFailPoint: failpoint, mode: "alwaysOn"}));
+
+ const conn = db.getMongo();
+
+ const collName = 'collStats';
+ const coll = db.getCollection(collName);
+
+ const bulk = coll.initializeUnorderedBulkOp();
+ const numDocs = 5;
+ for (let i = 0; i < numDocs; i++) {
+ bulk.insert({a: i, b: i * i});
+ }
+ assert.commandWorked(bulk.execute());
+
+ // Start two index builds in the background.
+ const awaitParallelShell = startParallelShell(() => {
+ db.runCommand({
+ createIndexes: 'collStats',
+ indexes: [
+ {key: {a: 1}, name: 'a_1', background: true},
+ {key: {b: 1}, name: 'b_1', background: true}
+ ]
+ });
+ }, conn.port);
+
+ // Wait until both index builds begin.
+ IndexBuildTest.waitForIndexBuildToStart(db);
+
+ const collStats = assert.commandWorked(db.runCommand({collStats: collName}));
+
+ // Ensure the existence of the indexes in the following fields: 'indexSizes', 'nindexes' and
+ // 'indexDetails'.
+ assert.gte(collStats.indexSizes._id_, 0);
+ assert.gte(collStats.indexSizes.a_1, 0);
+ assert.gte(collStats.indexSizes.b_1, 0);
+
+ assert.eq(3, collStats.nindexes);
+
+ assert.eq(2, collStats.indexBuilds.length);
+ assert.eq('a_1', collStats.indexBuilds[0]);
+ assert.eq('b_1', collStats.indexBuilds[1]);
+
+ assert.commandWorked(db.adminCommand({configureFailPoint: failpoint, mode: "off"}));
+ awaitParallelShell();
+})();
diff --git a/src/mongo/db/stats/storage_stats.cpp b/src/mongo/db/stats/storage_stats.cpp
index fed4a513a90..88ab2323839 100644
--- a/src/mongo/db/stats/storage_stats.cpp
+++ b/src/mongo/db/stats/storage_stats.cpp
@@ -86,11 +86,13 @@ Status appendCollectionStorageStats(OperationContext* opCtx,
recordStore->appendCustomStats(opCtx, result, scale);
IndexCatalog* indexCatalog = collection->getIndexCatalog();
- result->append("nindexes", indexCatalog->numIndexesReady(opCtx));
+ result->append("nindexes", indexCatalog->numIndexesTotal(opCtx));
BSONObjBuilder indexDetails;
+ std::vector<std::string> indexBuilds;
- std::unique_ptr<IndexCatalog::IndexIterator> it = indexCatalog->getIndexIterator(opCtx, false);
+ std::unique_ptr<IndexCatalog::IndexIterator> it =
+ indexCatalog->getIndexIterator(opCtx, /*includeUnfinishedIndexes=*/true);
while (it->more()) {
const IndexCatalogEntry* entry = it->next();
const IndexDescriptor* descriptor = entry->descriptor();
@@ -101,9 +103,14 @@ Status appendCollectionStorageStats(OperationContext* opCtx,
if (iam->appendCustomStats(opCtx, &bob, scale)) {
indexDetails.append(descriptor->indexName(), bob.obj());
}
+
+ if (!entry->isReady(opCtx)) {
+ indexBuilds.push_back(descriptor->indexName());
+ }
}
result->append("indexDetails", indexDetails.obj());
+ result->append("indexBuilds", indexBuilds);
BSONObjBuilder indexSizes;
long long indexSize = collection->getIndexSize(opCtx, &indexSizes, scale);