summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiangyu Yao <xiangyu.yao@mongodb.com>2018-11-27 17:42:23 -0500
committerXiangyu Yao <xiangyu.yao@mongodb.com>2019-03-25 16:58:34 -0400
commit562bc105b058c139be44c6655cc5be5a40d8379e (patch)
tree962928ebd0fa15591c65bb08d910d7a6fa5e71ee
parentfce41c4b76d816b1be155c45e9b352eadbfaadf5 (diff)
downloadmongo-562bc105b058c139be44c6655cc5be5a40d8379e.tar.gz
SERVER-36437 Use MODE_IS for dbstats
(cherry picked from commit 091ef080cdcfcbed720a536e57f5afd9b8a54b46)
-rw-r--r--src/mongo/db/catalog/database_impl.cpp16
-rw-r--r--src/mongo/db/commands/dbcommands.cpp5
2 files changed, 9 insertions, 12 deletions
diff --git a/src/mongo/db/catalog/database_impl.cpp b/src/mongo/db/catalog/database_impl.cpp
index 626df16fad8..989e00ff5db 100644
--- a/src/mongo/db/catalog/database_impl.cpp
+++ b/src/mongo/db/catalog/database_impl.cpp
@@ -269,8 +269,7 @@ void DatabaseImpl::init(OperationContext* const opCtx) {
list<string> collections;
_dbEntry->getCollectionNamespaces(&collections);
- for (list<string>::const_iterator it = collections.begin(); it != collections.end(); ++it) {
- const string ns = *it;
+ for (auto ns : collections) {
NamespaceString nss(ns);
_collections[ns] = _getOrCreateCollectionInstance(opCtx, nss);
}
@@ -295,8 +294,7 @@ void DatabaseImpl::clearTmpCollections(OperationContext* opCtx) {
list<string> collections;
_dbEntry->getCollectionNamespaces(&collections);
- for (list<string>::iterator i = collections.begin(); i != collections.end(); ++i) {
- string ns = *i;
+ for (auto ns : collections) {
invariant(NamespaceString::normal(ns));
CollectionCatalogEntry* coll = _dbEntry->getCollectionCatalogEntry(ns);
@@ -367,8 +365,6 @@ bool DatabaseImpl::isDropPending(OperationContext* opCtx) const {
}
void DatabaseImpl::getStats(OperationContext* opCtx, BSONObjBuilder* output, double scale) {
- list<string> collections;
- _dbEntry->getCollectionNamespaces(&collections);
long long nCollections = 0;
long long nViews = 0;
@@ -379,9 +375,13 @@ void DatabaseImpl::getStats(OperationContext* opCtx, BSONObjBuilder* output, dou
long long indexes = 0;
long long indexSize = 0;
- for (list<string>::const_iterator it = collections.begin(); it != collections.end(); ++it) {
- const string ns = *it;
+ invariant(opCtx->lockState()->isDbLockedForMode(name(), MODE_IS));
+ list<string> collections;
+ _dbEntry->getCollectionNamespaces(&collections);
+
+ for (auto ns : collections) {
+ Lock::CollectionLock colLock(opCtx->lockState(), ns, MODE_IS);
Collection* collection = getCollection(opCtx, ns);
if (!collection)
diff --git a/src/mongo/db/commands/dbcommands.cpp b/src/mongo/db/commands/dbcommands.cpp
index 98920e2ee30..261b332fc7d 100644
--- a/src/mongo/db/commands/dbcommands.cpp
+++ b/src/mongo/db/commands/dbcommands.cpp
@@ -1039,10 +1039,7 @@ public:
CurOp::get(opCtx)->setNS_inlock(dbname);
}
- // We lock the entire database in S-mode in order to ensure that the contents will not
- // change for the stats snapshot. This might be unnecessary and if it becomes a
- // performance issue, we can take IS lock and then lock collection-by-collection.
- AutoGetDb autoDb(opCtx, ns, MODE_S);
+ AutoGetDb autoDb(opCtx, ns, MODE_IS);
result.append("db", ns);