diff options
-rw-r--r-- | jstests/noPassthrough/serverstatus_indexbulkbuilder.js | 5 | ||||
-rw-r--r-- | src/mongo/db/index/index_access_method.cpp | 9 |
2 files changed, 13 insertions, 1 deletions
diff --git a/jstests/noPassthrough/serverstatus_indexbulkbuilder.js b/jstests/noPassthrough/serverstatus_indexbulkbuilder.js index 780033e4e62..d42ae64db58 100644 --- a/jstests/noPassthrough/serverstatus_indexbulkbuilder.js +++ b/jstests/noPassthrough/serverstatus_indexbulkbuilder.js @@ -12,6 +12,7 @@ const replSet = new ReplSetTest({ nodes: 1, + nodeOptions: {setParameter: {maxIndexBuildMemoryUsageMegabytes: 50}}, }); replSet.startSet(); replSet.initiate(); @@ -23,7 +24,7 @@ let coll = testDB.getCollection('t'); for (let i = 0; i < 10; i++) { assert.commandWorked(coll.insert({ _id: i, - a: i, + a: 'a'.repeat(10 * 1024 * 1024), })); } @@ -35,6 +36,8 @@ assert(serverStatus.hasOwnProperty('indexBulkBuilder'), let indexBulkBuilderSection = serverStatus.indexBulkBuilder; assert.eq(indexBulkBuilderSection.count, 1, tojson(indexBulkBuilderSection)); +assert.eq(indexBulkBuilderSection.filesOpenedForExternalSort, 4, tojson(indexBulkBuilderSection)); +assert.eq(indexBulkBuilderSection.filesClosedForExternalSort, 4, 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 cde0fbaa055..b1fccf76307 100644 --- a/src/mongo/db/index/index_access_method.cpp +++ b/src/mongo/db/index/index_access_method.cpp @@ -96,11 +96,19 @@ public: BSONObj generateSection(OperationContext* opCtx, const BSONElement& configElement) const final { BSONObjBuilder builder; builder.append("count", count.loadRelaxed()); + builder.append("filesOpenedForExternalSort", sorterFileStats.opened.loadRelaxed()); + builder.append("filesClosedForExternalSort", sorterFileStats.closed.loadRelaxed()); return builder.obj(); } // Number of instances of the bulk builder created. AtomicWord<long long> count; + + // Number of times the external sorter opened/closed a file handle to spill data to disk. + // This pair of counters in aggregate indicate the number of open file handles used by + // the external sorter and may be useful in diagnosing situations where the process is + // close to exhausting this finite resource. + SorterFileStats sorterFileStats; } indexBulkBuilderSSS; /** @@ -630,6 +638,7 @@ AbstractIndexAccessMethod::BulkBuilderImpl::BulkBuilderImpl(const IndexAccessMet SortOptions() .TempDir(storageGlobalParams.dbpath + "/_tmp") .ExtSortAllowed() + .FileStats(&indexBulkBuilderSSS.sorterFileStats) .MaxMemoryUsageBytes(maxMemoryUsageBytes), BtreeExternalSortComparison(descriptor->keyPattern(), descriptor->version()))), _real(index) { |