summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2015-01-13 14:58:50 -0500
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2015-01-15 10:41:43 -0500
commit02a78a7f3d936813ea9e4195887b11d83448fcd6 (patch)
tree225019d9b28e394dfe141a3bb5a50217f8ee50ef /src/mongo/db/catalog
parentd3ed3fad57e35f2459660c05b37e3b0509e45e5c (diff)
downloadmongo-02a78a7f3d936813ea9e4195887b11d83448fcd6.tar.gz
SERVER-16431 Simplify DB profile code
Diffstat (limited to 'src/mongo/db/catalog')
-rw-r--r--src/mongo/db/catalog/database.cpp27
-rw-r--r--src/mongo/db/catalog/database.h7
-rw-r--r--src/mongo/db/catalog/database_holder.cpp21
-rw-r--r--src/mongo/db/catalog/database_holder.h6
4 files changed, 38 insertions, 23 deletions
diff --git a/src/mongo/db/catalog/database.cpp b/src/mongo/db/catalog/database.cpp
index 2d7b9588ae4..3028f5e4f59 100644
--- a/src/mongo/db/catalog/database.cpp
+++ b/src/mongo/db/catalog/database.cpp
@@ -279,25 +279,28 @@ namespace mongo {
}
}
- bool Database::setProfilingLevel( OperationContext* txn, int newLevel , string& errmsg ) {
- if ( _profile == newLevel )
- return true;
-
- if ( newLevel < 0 || newLevel > 2 ) {
- errmsg = "profiling level has to be >=0 and <= 2";
- return false;
+ Status Database::setProfilingLevel(OperationContext* txn, int newLevel) {
+ if (_profile == newLevel) {
+ return Status::OK();
}
- if ( newLevel == 0 ) {
+ if (newLevel == 0) {
_profile = 0;
- return true;
+ return Status::OK();
}
- if (!getOrCreateProfileCollection(txn, this, true, &errmsg))
- return false;
+ if (newLevel < 0 || newLevel > 2) {
+ return Status(ErrorCodes::BadValue, "profiling level has to be >=0 and <= 2");
+ }
+
+ Status status = createProfileCollection(txn, this);
+ if (!status.isOK()) {
+ return status;
+ }
_profile = newLevel;
- return true;
+
+ return Status::OK();
}
void Database::getStats( OperationContext* opCtx, BSONObjBuilder* output, double scale ) {
diff --git a/src/mongo/db/catalog/database.h b/src/mongo/db/catalog/database.h
index 48f178abc88..83e16ea0a0a 100644
--- a/src/mongo/db/catalog/database.h
+++ b/src/mongo/db/catalog/database.h
@@ -68,9 +68,12 @@ namespace mongo {
void clearTmpCollections(OperationContext* txn);
/**
- * @return true if success. false if bad level or error creating profile ns
+ * Sets a new profiling level for the database and returns the outcome.
+ *
+ * @param txn Operation context which to use for creating the profiling collection.
+ * @param newLevel New profiling level to use.
*/
- bool setProfilingLevel( OperationContext* txn, int newLevel , std::string& errmsg );
+ Status setProfilingLevel(OperationContext* txn, int newLevel);
int getProfilingLevel() const { return _profile; }
const char* getProfilingNS() const { return _profileName.c_str(); }
diff --git a/src/mongo/db/catalog/database_holder.cpp b/src/mongo/db/catalog/database_holder.cpp
index 4a554b4089f..83006f7d60e 100644
--- a/src/mongo/db/catalog/database_holder.cpp
+++ b/src/mongo/db/catalog/database_holder.cpp
@@ -30,13 +30,15 @@
#include "mongo/platform/basic.h"
+#include "mongo/db/catalog/database_holder.h"
+
#include "mongo/db/audit.h"
#include "mongo/db/auth/auth_index_d.h"
#include "mongo/db/background.h"
#include "mongo/db/client.h"
#include "mongo/db/clientcursor.h"
+#include "mongo/db/catalog/database.h"
#include "mongo/db/catalog/database_catalog_entry.h"
-#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/global_environment_experiment.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/storage/storage_engine.h"
@@ -45,15 +47,13 @@
namespace mongo {
- using std::endl;
using std::set;
using std::string;
using std::stringstream;
- static DatabaseHolder _dbHolder;
-
namespace {
- static StringData _todb(const StringData& ns) {
+
+ StringData _todb(const StringData& ns) {
size_t i = ns.find('.');
if (i == std::string::npos) {
uassert(13074, "db name can't be empty", ns.size());
@@ -67,12 +67,18 @@ namespace {
return d;
}
-}
+
+
+ DatabaseHolder _dbHolder;
+
+} // namespace
+
DatabaseHolder& dbHolder() {
return _dbHolder;
}
+
Database* DatabaseHolder::get(OperationContext* txn,
const StringData& ns) const {
@@ -182,8 +188,7 @@ namespace {
if( !force && BackgroundOperation::inProgForDb(name) ) {
log() << "WARNING: can't close database "
<< name
- << " because a bg job is in progress - try killOp command"
- << endl;
+ << " because a bg job is in progress - try killOp command";
nNotClosed++;
continue;
}
diff --git a/src/mongo/db/catalog/database_holder.h b/src/mongo/db/catalog/database_holder.h
index dd3afdf2470..6ad69c5bef2 100644
--- a/src/mongo/db/catalog/database_holder.h
+++ b/src/mongo/db/catalog/database_holder.h
@@ -28,13 +28,17 @@
#pragma once
+#include <set>
+
#include "mongo/base/string_data.h"
-#include "mongo/db/catalog/database.h"
#include "mongo/db/namespace_string.h"
+#include "mongo/util/concurrency/mutex.h"
#include "mongo/util/string_map.h"
namespace mongo {
+ class Database;
+
/**
* Registry of opened databases.
*/