diff options
-rw-r--r-- | jstests/noPassthroughWithMongod/top_drop.js | 11 | ||||
-rw-r--r-- | src/mongo/db/stats/top.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/stats/top.h | 2 |
3 files changed, 17 insertions, 4 deletions
diff --git a/jstests/noPassthroughWithMongod/top_drop.js b/jstests/noPassthroughWithMongod/top_drop.js index cc6df88a274..8dcc85f2142 100644 --- a/jstests/noPassthroughWithMongod/top_drop.js +++ b/jstests/noPassthroughWithMongod/top_drop.js @@ -65,4 +65,15 @@ // Check that dropping the database removes the remaining collections. assert.commandWorked(topDB.dropDatabase()); checkTopEntries([]); + + // Check that top doesn't keep state about non-existent collections. + assert.commandWorked(topDB.dropDatabase()); + topDB.foo.find().itcount(); + topDB.baz.update({}, {$set: {a: 1}}); + topDB.bar.remove({}); + let res = topDB.adminCommand("top"); + assert.isnull(res.totals["test.foo"]); + assert.isnull(res.totals["test.bar"]); + assert.isnull(res.totals["test.baz"]); + assert.commandWorked(topDB.dropDatabase()); }()); diff --git a/src/mongo/db/stats/top.cpp b/src/mongo/db/stats/top.cpp index 45680f7db15..155f122fef5 100644 --- a/src/mongo/db/stats/top.cpp +++ b/src/mongo/db/stats/top.cpp @@ -85,8 +85,9 @@ void Top::record(OperationContext* opCtx, auto hashedNs = UsageMap::HashedKey(ns); stdx::lock_guard<SimpleMutex> lk(_lock); - if ((command || logicalOp == LogicalOp::opQuery) && ns == _lastDropped) { - _lastDropped = ""; + if ((command || logicalOp == LogicalOp::opQuery) && + _collDropNs.find(ns.toString()) != _collDropNs.end()) { + _collDropNs.erase(ns.toString()); return; } @@ -142,10 +143,11 @@ void Top::_record(OperationContext* opCtx, void Top::collectionDropped(StringData ns, bool databaseDropped) { stdx::lock_guard<SimpleMutex> lk(_lock); _usage.erase(ns); + if (!databaseDropped) { // If a collection drop occurred, there will be a subsequent call to record for this // collection namespace which must be ignored. This does not apply to a database drop. - _lastDropped = ns.toString(); + _collDropNs.insert(ns.toString()); } } diff --git a/src/mongo/db/stats/top.h b/src/mongo/db/stats/top.h index ccd4ac5e13f..6dc2cf7f8a3 100644 --- a/src/mongo/db/stats/top.h +++ b/src/mongo/db/stats/top.h @@ -143,7 +143,7 @@ private: mutable SimpleMutex _lock; OperationLatencyHistogram _globalHistogramStats; UsageMap _usage; - std::string _lastDropped; + std::set<std::string> _collDropNs; }; } // namespace mongo |