summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2014-10-16 14:36:28 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2014-10-30 18:42:54 -0400
commitbc51c5e5b20a24fcfa3e0ecb5595f563abb7086a (patch)
tree6c6c0eb485ca7eb8a670b2078328716b857fda87
parentff475aa6c4eede38e7cf56853e3e11052e2e6511 (diff)
downloadmongo-bc51c5e5b20a24fcfa3e0ecb5595f563abb7086a.tar.gz
SERVER-15614 Move inProcCmd to a separate file and clean includes
It is currently in instance.cpp, which is very cluttered. This change is in preparation for the db.currentOp fix.
-rw-r--r--src/mongo/SConscript1
-rw-r--r--src/mongo/db/client.cpp2
-rw-r--r--src/mongo/db/clientcursor.cpp3
-rw-r--r--src/mongo/db/cloner.cpp1
-rw-r--r--src/mongo/db/commands/clone.cpp1
-rw-r--r--src/mongo/db/commands/mr.cpp1
-rw-r--r--src/mongo/db/commands/rename_collection.cpp3
-rw-r--r--src/mongo/db/currentop_command.cpp117
-rw-r--r--src/mongo/db/currentop_command.h43
-rw-r--r--src/mongo/db/instance.cpp68
-rw-r--r--src/mongo/db/prefetch.cpp1
-rw-r--r--src/mongo/db/repl/master_slave.cpp2
-rw-r--r--src/mongo/dbtests/basictests.cpp3
-rw-r--r--src/mongo/dbtests/dbhelper_tests.cpp1
-rw-r--r--src/mongo/dbtests/namespacetests.cpp2
15 files changed, 174 insertions, 75 deletions
diff --git a/src/mongo/SConscript b/src/mongo/SConscript
index 893d4e95360..f5771e5d54d 100644
--- a/src/mongo/SConscript
+++ b/src/mongo/SConscript
@@ -621,6 +621,7 @@ serverOnlyFiles = [ "db/background.cpp",
"db/commands/write_commands/batch_executor.cpp",
"db/commands/write_commands/write_commands.cpp",
"db/curop.cpp",
+ "db/currentop_command.cpp",
"db/dbcommands.cpp",
"db/dbcommands_admin.cpp",
"db/dbdirectclient.cpp",
diff --git a/src/mongo/db/client.cpp b/src/mongo/db/client.cpp
index 78e4bc6b8b8..638606de469 100644
--- a/src/mongo/db/client.cpp
+++ b/src/mongo/db/client.cpp
@@ -49,7 +49,7 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/auth/authz_session_external_state_d.h"
#include "mongo/db/auth/privilege.h"
-#include "mongo/db/db.h"
+#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/commands.h"
#include "mongo/db/curop.h"
#include "mongo/db/dbwebserver.h"
diff --git a/src/mongo/db/clientcursor.cpp b/src/mongo/db/clientcursor.cpp
index 01530586506..20d8bc82fb3 100644
--- a/src/mongo/db/clientcursor.cpp
+++ b/src/mongo/db/clientcursor.cpp
@@ -40,10 +40,11 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/auth/privilege.h"
#include "mongo/db/catalog/collection.h"
+#include "mongo/db/client.h"
#include "mongo/db/commands.h"
#include "mongo/db/commands/server_status.h"
#include "mongo/db/commands/server_status_metric.h"
-#include "mongo/db/db.h"
+#include "mongo/db/curop.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/operation_context_impl.h"
#include "mongo/db/repl/repl_coordinator_global.h"
diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp
index cfb741e4ca1..58e8d03c49d 100644
--- a/src/mongo/db/cloner.cpp
+++ b/src/mongo/db/cloner.cpp
@@ -41,6 +41,7 @@
#include "mongo/db/auth/authorization_manager_global.h"
#include "mongo/db/auth/internal_user_auth.h"
#include "mongo/db/catalog/collection.h"
+#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/catalog/index_create.h"
#include "mongo/db/commands.h"
#include "mongo/db/commands/copydb.h"
diff --git a/src/mongo/db/commands/clone.cpp b/src/mongo/db/commands/clone.cpp
index 44270a6596d..2acc7b1e452 100644
--- a/src/mongo/db/commands/clone.cpp
+++ b/src/mongo/db/commands/clone.cpp
@@ -40,7 +40,6 @@
#include "mongo/db/commands.h"
#include "mongo/db/commands/copydb.h"
#include "mongo/db/commands/rename_collection.h"
-#include "mongo/db/db.h"
#include "mongo/db/dbhelpers.h"
#include "mongo/db/index_builder.h"
#include "mongo/db/instance.h"
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index 976ee0efbc2..b22a48ea528 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -38,6 +38,7 @@
#include "mongo/client/parallel.h"
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/catalog/collection.h"
+#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/catalog/index_catalog.h"
#include "mongo/db/clientcursor.h"
#include "mongo/db/commands.h"
diff --git a/src/mongo/db/commands/rename_collection.cpp b/src/mongo/db/commands/rename_collection.cpp
index daadd13041f..0d159cac2b6 100644
--- a/src/mongo/db/commands/rename_collection.cpp
+++ b/src/mongo/db/commands/rename_collection.cpp
@@ -31,14 +31,15 @@
#include "mongo/client/dbclientcursor.h"
#include "mongo/db/catalog/collection.h"
#include "mongo/db/catalog/collection_catalog_entry.h"
+#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/catalog/index_catalog.h"
#include "mongo/db/catalog/index_create.h"
+#include "mongo/db/client.h"
#include "mongo/db/commands.h"
#include "mongo/db/commands/rename_collection.h"
#include "mongo/db/dbhelpers.h"
#include "mongo/db/index_builder.h"
#include "mongo/db/index/index_descriptor.h"
-#include "mongo/db/instance.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/operation_context_impl.h"
#include "mongo/db/ops/insert.h"
diff --git a/src/mongo/db/currentop_command.cpp b/src/mongo/db/currentop_command.cpp
new file mode 100644
index 00000000000..1753d024df2
--- /dev/null
+++ b/src/mongo/db/currentop_command.cpp
@@ -0,0 +1,117 @@
+/**
+ * Copyright (C) 2008-2014 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kCommands
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/db/audit.h"
+#include "mongo/db/auth/action_type.h"
+#include "mongo/db/auth/authorization_session.h"
+#include "mongo/bson/bsonobj.h"
+#include "mongo/db/client.h"
+#include "mongo/db/curop.h"
+#include "mongo/db/commands/fsync.h"
+#include "mongo/db/dbmessage.h"
+#include "mongo/db/operation_context_impl.h"
+#include "mongo/db/global_environment_experiment.h"
+#include "mongo/db/matcher/matcher.h"
+#include "mongo/util/log.h"
+
+namespace mongo {
+
+ void inProgCmd(OperationContext* txn, Message &m, DbResponse &dbresponse) {
+ DbMessage d(m);
+ QueryMessage q(d);
+ BSONObjBuilder b;
+
+ const bool isAuthorized =
+ txn->getClient()->getAuthorizationSession()->isAuthorizedForActionsOnResource(
+ ResourcePattern::forClusterResource(),
+ ActionType::inprog);
+ audit::logInProgAuthzCheck(txn->getClient(),
+ q.query,
+ isAuthorized ? ErrorCodes::OK : ErrorCodes::Unauthorized);
+ if (!isAuthorized) {
+ b.append("err", "unauthorized");
+ replyToQuery(0, m, dbresponse, b.obj());
+ return;
+ }
+
+ bool all = q.query["$all"].trueValue();
+ vector<BSONObj> vals;
+ {
+ BSONObj filter;
+ {
+ BSONObjBuilder b;
+ BSONObjIterator i( q.query );
+ while ( i.more() ) {
+ BSONElement e = i.next();
+ if ( str::equals( "$all", e.fieldName() ) )
+ continue;
+ b.append( e );
+ }
+ filter = b.obj();
+ }
+
+ const NamespaceString nss(d.getns());
+
+ Client& me = *txn->getClient();
+ scoped_lock bl(Client::clientsMutex);
+ Matcher m(filter, WhereCallbackReal(txn, nss.db()));
+ for( set<Client*>::iterator i = Client::clients.begin(); i != Client::clients.end(); i++ ) {
+ Client *c = *i;
+ verify( c );
+ CurOp* co = c->curop();
+ if ( c == &me && !co ) {
+ continue;
+ }
+ verify( co );
+ if( all || co->displayInCurop() ) {
+ BSONObjBuilder infoBuilder;
+
+ c->reportState(infoBuilder);
+ co->reportState(&infoBuilder);
+
+ const BSONObj info = infoBuilder.obj();
+ if ( all || m.matches( info )) {
+ vals.push_back( info );
+ }
+ }
+ }
+ }
+ b.append("inprog", vals);
+ if( lockedForWriting() ) {
+ b.append("fsyncLock", true);
+ b.append("info", "use db.fsyncUnlock() to terminate the fsync write/snapshot lock");
+ }
+
+ replyToQuery(0, m, dbresponse, b.obj());
+ }
+
+} // namespace mongo
diff --git a/src/mongo/db/currentop_command.h b/src/mongo/db/currentop_command.h
new file mode 100644
index 00000000000..5475eef1862
--- /dev/null
+++ b/src/mongo/db/currentop_command.h
@@ -0,0 +1,43 @@
+/**
+ * Copyright (C) 2014 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#pragma once
+
+namespace mongo {
+
+ struct DbResponse;
+ class Message;
+ class OperationContext;
+
+ /**
+ * Executes the db.currentOp() command. Currently not an actual "command" object, but should
+ * be converted to one at some point.
+ */
+ void inProgCmd(OperationContext* txn, Message &m, DbResponse &dbresponse);
+
+} // namespace mongo
diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp
index 445877df25e..7271903f409 100644
--- a/src/mongo/db/instance.cpp
+++ b/src/mongo/db/instance.cpp
@@ -45,6 +45,7 @@
#include "mongo/db/commands/fsync.h"
#include "mongo/db/concurrency/d_concurrency.h"
#include "mongo/db/concurrency/deadlock.h"
+#include "mongo/db/currentop_command.h"
#include "mongo/db/db.h"
#include "mongo/db/dbdirectclient.h"
#include "mongo/db/dbhelpers.h"
@@ -134,73 +135,6 @@ namespace {
MONGO_FP_DECLARE(rsStopGetMore);
- static void inProgCmd(OperationContext* txn, Message &m, DbResponse &dbresponse) {
- DbMessage d(m);
- QueryMessage q(d);
- BSONObjBuilder b;
-
- const bool isAuthorized = txn->getClient()->getAuthorizationSession()->isAuthorizedForActionsOnResource(
- ResourcePattern::forClusterResource(), ActionType::inprog);
-
- audit::logInProgAuthzCheck(
- txn->getClient(), q.query, isAuthorized ? ErrorCodes::OK : ErrorCodes::Unauthorized);
-
- if (!isAuthorized) {
- b.append("err", "unauthorized");
- }
- else {
- bool all = q.query["$all"].trueValue();
- vector<BSONObj> vals;
- {
- BSONObj filter;
- {
- BSONObjBuilder b;
- BSONObjIterator i( q.query );
- while ( i.more() ) {
- BSONElement e = i.next();
- if ( str::equals( "$all", e.fieldName() ) )
- continue;
- b.append( e );
- }
- filter = b.obj();
- }
-
- const NamespaceString nss(d.getns());
-
- Client& me = *txn->getClient();
- scoped_lock bl(Client::clientsMutex);
- Matcher m(filter, WhereCallbackReal(txn, nss.db()));
- for( set<Client*>::iterator i = Client::clients.begin(); i != Client::clients.end(); i++ ) {
- Client *c = *i;
- verify( c );
- CurOp* co = c->curop();
- if ( c == &me && !co ) {
- continue;
- }
- verify( co );
- if( all || co->displayInCurop() ) {
- BSONObjBuilder infoBuilder;
-
- c->reportState(infoBuilder);
- co->reportState(&infoBuilder);
-
- const BSONObj info = infoBuilder.obj();
- if ( all || m.matches( info )) {
- vals.push_back( info );
- }
- }
- }
- }
- b.append("inprog", vals);
- if( lockedForWriting() ) {
- b.append("fsyncLock", true);
- b.append("info", "use db.fsyncUnlock() to terminate the fsync write/snapshot lock");
- }
- }
-
- replyToQuery(0, m, dbresponse, b.obj());
- }
-
void killOp( OperationContext* txn, Message &m, DbResponse &dbresponse ) {
DbMessage d(m);
QueryMessage q(d);
diff --git a/src/mongo/db/prefetch.cpp b/src/mongo/db/prefetch.cpp
index 7638320722f..e85add16b31 100644
--- a/src/mongo/db/prefetch.cpp
+++ b/src/mongo/db/prefetch.cpp
@@ -33,6 +33,7 @@
#include "mongo/db/prefetch.h"
#include "mongo/db/catalog/collection.h"
+#include "mongo/db/catalog/database.h"
#include "mongo/db/commands/server_status_metric.h"
#include "mongo/db/dbhelpers.h"
#include "mongo/db/index/index_access_method.h"
diff --git a/src/mongo/db/repl/master_slave.cpp b/src/mongo/db/repl/master_slave.cpp
index b6fd488b50f..29df6cd5ccf 100644
--- a/src/mongo/db/repl/master_slave.cpp
+++ b/src/mongo/db/repl/master_slave.cpp
@@ -43,11 +43,11 @@
#include "mongo/db/repl/master_slave.h"
#include <pcrecpp.h>
-
#include <boost/thread/thread.hpp>
#include "mongo/db/auth/authorization_manager.h"
#include "mongo/db/catalog/database_catalog_entry.h"
+#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/cloner.h"
#include "mongo/db/commands.h"
#include "mongo/db/dbdirectclient.h"
diff --git a/src/mongo/dbtests/basictests.cpp b/src/mongo/dbtests/basictests.cpp
index 64fc2876b2e..35cafb2fc9b 100644
--- a/src/mongo/dbtests/basictests.cpp
+++ b/src/mongo/dbtests/basictests.cpp
@@ -29,9 +29,8 @@
* then also delete it in the license file.
*/
-#include "mongo/pch.h"
+#include "mongo/platform/basic.h"
-#include "mongo/db/db.h"
#include "mongo/db/operation_context_impl.h"
#include "mongo/dbtests/dbtests.h"
#include "mongo/util/base64.h"
diff --git a/src/mongo/dbtests/dbhelper_tests.cpp b/src/mongo/dbtests/dbhelper_tests.cpp
index 987874ff3b3..e615b653bb6 100644
--- a/src/mongo/dbtests/dbhelper_tests.cpp
+++ b/src/mongo/dbtests/dbhelper_tests.cpp
@@ -28,6 +28,7 @@
#include "mongo/client/dbclientcursor.h"
#include "mongo/db/catalog/collection.h"
+#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/dbdirectclient.h"
#include "mongo/db/dbhelpers.h"
#include "mongo/db/operation_context_impl.h"
diff --git a/src/mongo/dbtests/namespacetests.cpp b/src/mongo/dbtests/namespacetests.cpp
index b12c9631397..4914dbc325e 100644
--- a/src/mongo/dbtests/namespacetests.cpp
+++ b/src/mongo/dbtests/namespacetests.cpp
@@ -36,7 +36,7 @@
#include <string>
#include "mongo/db/catalog/collection.h"
-#include "mongo/db/db.h"
+#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/index/expression_keys_private.h"
#include "mongo/db/index_legacy.h"
#include "mongo/db/index_names.h"