summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2022-04-28 14:48:29 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-06-24 17:28:05 +0000
commite163059b8d3d069d52a251970266cedc4a12fb54 (patch)
treea6e6dafc684380a995e79112f38a2f01cef6c153
parentbd7423724f1cd2983ffa177e2ba538859ae4ff63 (diff)
downloadmongo-e163059b8d3d069d52a251970266cedc4a12fb54.tar.gz
SERVER-64659 add indexBulkBuilder server status section with minimal creation metrics
(cherry picked from commit adc47cc974960abf0bc10a1b15234dc95ee6fdd4)
-rw-r--r--jstests/noPassthrough/serverstatus_indexbulkbuilder.js40
-rw-r--r--src/mongo/db/index/index_access_method.cpp36
2 files changed, 75 insertions, 1 deletions
diff --git a/jstests/noPassthrough/serverstatus_indexbulkbuilder.js b/jstests/noPassthrough/serverstatus_indexbulkbuilder.js
new file mode 100644
index 00000000000..780033e4e62
--- /dev/null
+++ b/jstests/noPassthrough/serverstatus_indexbulkbuilder.js
@@ -0,0 +1,40 @@
+/**
+ * Tests that serverStatus contains an indexBuilder section. This section reports
+ * globally-aggregated statistics about index builds and the external sorter.
+ *
+ * @tags: [
+ * requires_persistence,
+ * requires_replication,
+ * ]
+ */
+(function() {
+'use strict';
+
+const replSet = new ReplSetTest({
+ nodes: 1,
+});
+replSet.startSet();
+replSet.initiate();
+
+let primary = replSet.getPrimary();
+let testDB = primary.getDB('test');
+let coll = testDB.getCollection('t');
+
+for (let i = 0; i < 10; i++) {
+ assert.commandWorked(coll.insert({
+ _id: i,
+ a: i,
+ }));
+}
+
+assert.commandWorked(coll.createIndex({a: 1}));
+
+let serverStatus = testDB.serverStatus();
+assert(serverStatus.hasOwnProperty('indexBulkBuilder'),
+ 'indexBuildBuilder section missing: ' + tojson(serverStatus));
+
+let indexBulkBuilderSection = serverStatus.indexBulkBuilder;
+assert.eq(indexBulkBuilderSection.count, 1, tojson(indexBulkBuilderSection));
+
+replSet.stopSet();
+})();
diff --git a/src/mongo/db/index/index_access_method.cpp b/src/mongo/db/index/index_access_method.cpp
index d5f3fe76074..67b09f80563 100644
--- a/src/mongo/db/index/index_access_method.cpp
+++ b/src/mongo/db/index/index_access_method.cpp
@@ -41,6 +41,7 @@
#include "mongo/db/catalog/index_catalog.h"
#include "mongo/db/catalog/index_consistency.h"
#include "mongo/db/client.h"
+#include "mongo/db/commands/server_status.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
#include "mongo/db/curop.h"
#include "mongo/db/index/index_build_interceptor.h"
@@ -53,6 +54,7 @@
#include "mongo/db/storage/durable_catalog.h"
#include "mongo/db/storage/storage_options.h"
#include "mongo/logv2/log.h"
+#include "mongo/platform/atomic_word.h"
#include "mongo/util/progress_meter.h"
#include "mongo/util/scopeguard.h"
#include "mongo/util/stacktrace.h"
@@ -75,6 +77,36 @@ static const RecordId kMultikeyMetadataKeyId =
RecordId{RecordId::ReservedId::kWildcardMultikeyMetadataId};
/**
+ * Metrics for index bulk builder operations. Intended to support index build diagnostics
+ * during the following scenarios:
+ * - createIndex commands;
+ * - collection cloning during initial sync; and
+ * - resuming index builds at startup.
+ *
+ * Also includes statistics for disk usage (by the external sorter) for index builds that
+ * do not fit in memory.
+ */
+class IndexBulkBuilderSSS : public ServerStatusSection {
+public:
+ IndexBulkBuilderSSS() : ServerStatusSection("indexBulkBuilder") {}
+
+ bool includeByDefault() const final {
+ return true;
+ }
+
+ void addRequiredPrivileges(std::vector<Privilege>* out) final {}
+
+ BSONObj generateSection(OperationContext* opCtx, const BSONElement& configElement) const final {
+ BSONObjBuilder builder;
+ builder.append("count", count.loadRelaxed());
+ return builder.obj();
+ }
+
+ // Number of instances of the bulk builder created.
+ AtomicWord<long long> count;
+} indexBulkBuilderSSS;
+
+/**
* Returns true if at least one prefix of any of the indexed fields causes the index to be
* multikey, and returns false otherwise. This function returns false if the 'multikeyPaths'
* vector is empty.
@@ -535,7 +567,9 @@ AbstractIndexAccessMethod::BulkBuilderImpl::BulkBuilderImpl(IndexCatalogEntry* i
std::pair<KeyString::Value::SorterDeserializeSettings,
mongo::NullValue::SorterDeserializeSettings>(
{index->accessMethod()->getSortedDataInterface()->getKeyStringVersion()}, {}))),
- _indexCatalogEntry(index) {}
+ _indexCatalogEntry(index) {
+ indexBulkBuilderSSS.count.addAndFetch(1);
+}
Status AbstractIndexAccessMethod::BulkBuilderImpl::insert(OperationContext* opCtx,
const BSONObj& obj,