summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2022-08-26 08:12:49 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-08-26 12:47:17 +0000
commiteb3adbe5a061ecb3c7fb123f42241bbae03f88bd (patch)
tree28c430671c1269475db02a49ee655712069fa0df
parent26d341317559b63d21f07f25f7ff2f99373891a2 (diff)
downloadmongo-eb3adbe5a061ecb3c7fb123f42241bbae03f88bd.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/SConscript1
-rw-r--r--src/mongo/db/index/index_access_method.cpp36
3 files changed, 76 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/SConscript b/src/mongo/db/index/SConscript
index b9e79ee6116..ed11b2417a9 100644
--- a/src/mongo/db/index/SConscript
+++ b/src/mongo/db/index/SConscript
@@ -124,6 +124,7 @@ serveronlyEnv.Library(
'index_descriptor',
],
LIBDEPS_PRIVATE=[
+ '$BUILD_DIR/mongo/db/commands/server_status',
'$BUILD_DIR/mongo/db/logical_clock',
'$BUILD_DIR/mongo/idl/server_parameter',
],
diff --git a/src/mongo/db/index/index_access_method.cpp b/src/mongo/db/index/index_access_method.cpp
index 41ff27a6ddb..cde0fbaa055 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_access_method_gen.h"
@@ -52,6 +53,7 @@
#include "mongo/db/repl/timestamp_block.h"
#include "mongo/db/storage/durable_catalog.h"
#include "mongo/db/storage/storage_options.h"
+#include "mongo/platform/atomic_word.h"
#include "mongo/util/log.h"
#include "mongo/util/progress_meter.h"
#include "mongo/util/scopeguard.h"
@@ -72,6 +74,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.
@@ -600,7 +632,9 @@ AbstractIndexAccessMethod::BulkBuilderImpl::BulkBuilderImpl(const IndexAccessMet
.ExtSortAllowed()
.MaxMemoryUsageBytes(maxMemoryUsageBytes),
BtreeExternalSortComparison(descriptor->keyPattern(), descriptor->version()))),
- _real(index) {}
+ _real(index) {
+ indexBulkBuilderSSS.count.addAndFetch(1);
+}
Status AbstractIndexAccessMethod::BulkBuilderImpl::insert(OperationContext* opCtx,
const BSONObj& obj,