From 5a29fa08eeea0ece229102dcd4e7b6580c7acd1d Mon Sep 17 00:00:00 2001 From: matt dannenberg Date: Thu, 9 Apr 2015 10:01:45 -0400 Subject: SERVER-15860 Switch replication metadata ops to be replication-specific, rather than using commands --- src/mongo/SConscript | 1 + src/mongo/db/auth/sasl_commands.cpp | 12 +- src/mongo/db/catalog/apply_ops.cpp | 1 - src/mongo/db/catalog/capped_utils.cpp | 5 +- src/mongo/db/catalog/create_collection.cpp | 94 ++++++++++++ src/mongo/db/catalog/create_collection.h | 43 ++++++ src/mongo/db/clientcursor.cpp | 8 +- src/mongo/db/clientlistplugin.cpp | 3 +- src/mongo/db/cloner.cpp | 43 +++--- src/mongo/db/cloner.h | 7 +- src/mongo/db/commands.cpp | 24 ++- src/mongo/db/commands.h | 23 +-- src/mongo/db/commands/apply_ops.cpp | 5 +- src/mongo/db/commands/authentication_commands.cpp | 13 +- src/mongo/db/commands/authentication_commands.h | 3 +- src/mongo/db/commands/cleanup_orphaned_cmd.cpp | 3 +- src/mongo/db/commands/clone.cpp | 4 +- src/mongo/db/commands/clone_collection.cpp | 3 +- src/mongo/db/commands/collection_to_capped.cpp | 10 +- src/mongo/db/commands/compact.cpp | 7 +- src/mongo/db/commands/connection_status.cpp | 2 +- src/mongo/db/commands/copydb.cpp | 4 +- src/mongo/db/commands/copydb_start_commands.cpp | 6 +- src/mongo/db/commands/count.cpp | 3 +- src/mongo/db/commands/cpuprofile.cpp | 12 +- src/mongo/db/commands/create_indexes.cpp | 27 ++-- src/mongo/db/commands/current_op.cpp | 3 +- src/mongo/db/commands/dbhash.cpp | 7 +- src/mongo/db/commands/dbhash.h | 7 +- src/mongo/db/commands/distinct.cpp | 8 +- src/mongo/db/commands/drop_indexes.cpp | 16 +- src/mongo/db/commands/explain_cmd.cpp | 10 +- src/mongo/db/commands/explain_cmd.h | 3 +- src/mongo/db/commands/fail_point_cmd.cpp | 3 +- src/mongo/db/commands/find_and_modify.cpp | 6 +- src/mongo/db/commands/find_cmd.cpp | 3 +- src/mongo/db/commands/fsync.cpp | 10 +- src/mongo/db/commands/geo_near_cmd.cpp | 7 +- src/mongo/db/commands/get_last_error.cpp | 17 ++- src/mongo/db/commands/getmore_cmd.cpp | 3 +- src/mongo/db/commands/group.cpp | 3 +- src/mongo/db/commands/group.h | 3 +- src/mongo/db/commands/hashcmd.cpp | 3 +- src/mongo/db/commands/index_filter_commands.cpp | 8 +- src/mongo/db/commands/index_filter_commands.h | 8 +- src/mongo/db/commands/isself.cpp | 7 +- src/mongo/db/commands/kill_op.cpp | 3 +- src/mongo/db/commands/list_collections.cpp | 3 +- src/mongo/db/commands/list_databases.cpp | 3 +- src/mongo/db/commands/list_indexes.cpp | 3 +- src/mongo/db/commands/merge_chunks_cmd.cpp | 3 +- src/mongo/db/commands/mr.cpp | 15 +- src/mongo/db/commands/oplog_note.cpp | 3 +- src/mongo/db/commands/parallel_collection_scan.cpp | 9 +- src/mongo/db/commands/parameters.cpp | 14 +- src/mongo/db/commands/pipeline_command.cpp | 8 +- src/mongo/db/commands/plan_cache_commands.cpp | 8 +- src/mongo/db/commands/plan_cache_commands.h | 8 +- src/mongo/db/commands/rename_collection.cpp | 24 ++- src/mongo/db/commands/repair_cursor.cpp | 9 +- src/mongo/db/commands/server_status.cpp | 7 +- src/mongo/db/commands/test_commands.cpp | 25 ++- src/mongo/db/commands/touch.cpp | 3 +- src/mongo/db/commands/user_management_commands.cpp | 57 +++---- src/mongo/db/commands/validate.cpp | 7 +- .../db/commands/write_commands/batch_executor.cpp | 3 +- .../db/commands/write_commands/write_commands.cpp | 9 +- .../db/commands/write_commands/write_commands.h | 3 +- .../db/commands/writeback_compatibility_shim.cpp | 6 +- src/mongo/db/dbcommands.cpp | 170 +++++++++------------ src/mongo/db/dbcommands_generic.cpp | 60 ++++++-- src/mongo/db/dbdirectclient.cpp | 3 +- src/mongo/db/dbeval.cpp | 3 +- src/mongo/db/dbwebserver.cpp | 4 +- src/mongo/db/driverHelpers.cpp | 7 +- src/mongo/db/exec/stagedebug_cmd.cpp | 8 +- src/mongo/db/exec/update.cpp | 1 - src/mongo/db/geo/haystack.cpp | 8 +- src/mongo/db/instance.cpp | 10 +- src/mongo/db/repl/master_slave.cpp | 4 +- src/mongo/db/repl/oplog.cpp | 120 +++++++++++++-- src/mongo/db/repl/oplog.h | 2 - src/mongo/db/repl/replication_info.cpp | 7 +- src/mongo/db/repl/replset_commands.cpp | 90 ++++++++--- src/mongo/db/repl/resync.cpp | 3 +- src/mongo/db/repl/rs_initialsync.cpp | 1 - src/mongo/db/repl/rs_rollback.cpp | 2 +- src/mongo/db/repl/sync_tail.cpp | 4 +- src/mongo/db/stats/top.cpp | 7 +- .../storage/mmap_v1/journal_latency_test_cmd.cpp | 7 +- src/mongo/s/client/shard.cpp | 7 +- src/mongo/s/client/shard_connection.cpp | 3 +- src/mongo/s/commands/cluster_add_shard_cmd.cpp | 3 +- src/mongo/s/commands/cluster_count_cmd.cpp | 3 +- src/mongo/s/commands/cluster_drop_database_cmd.cpp | 3 +- .../s/commands/cluster_enable_sharding_cmd.cpp | 3 +- src/mongo/s/commands/cluster_explain_cmd.cpp | 13 +- src/mongo/s/commands/cluster_find_cmd.cpp | 3 +- .../s/commands/cluster_flush_router_config_cmd.cpp | 3 +- src/mongo/s/commands/cluster_fsync_cmd.cpp | 3 +- .../s/commands/cluster_get_last_error_cmd.cpp | 3 +- .../s/commands/cluster_get_prev_error_cmd.cpp | 3 +- .../s/commands/cluster_get_shard_version_cmd.cpp | 3 +- src/mongo/s/commands/cluster_index_filter_cmd.cpp | 6 +- src/mongo/s/commands/cluster_is_db_grid_cmd.cpp | 3 +- src/mongo/s/commands/cluster_is_master_cmd.cpp | 3 +- src/mongo/s/commands/cluster_kill_op.cpp | 3 +- .../s/commands/cluster_list_databases_cmd.cpp | 3 +- src/mongo/s/commands/cluster_list_shards_cmd.cpp | 3 +- src/mongo/s/commands/cluster_merge_chunks_cmd.cpp | 3 +- src/mongo/s/commands/cluster_move_chunk_cmd.cpp | 3 +- src/mongo/s/commands/cluster_move_primary_cmd.cpp | 3 +- src/mongo/s/commands/cluster_netstat_cmd.cpp | 3 +- src/mongo/s/commands/cluster_plan_cache_cmd.cpp | 6 +- src/mongo/s/commands/cluster_remove_shard_cmd.cpp | 3 +- .../s/commands/cluster_repl_set_get_status_cmd.cpp | 3 +- src/mongo/s/commands/cluster_reset_error_cmd.cpp | 3 +- .../s/commands/cluster_shard_collection_cmd.cpp | 3 +- src/mongo/s/commands/cluster_shutdown_cmd.cpp | 3 +- .../s/commands/cluster_split_collection_cmd.cpp | 3 +- src/mongo/s/commands/cluster_whats_my_uri_cmd.cpp | 3 +- src/mongo/s/commands/cluster_write_cmd.cpp | 3 +- src/mongo/s/commands/commands_public.cpp | 139 ++++++++++++----- src/mongo/s/commands/run_on_all_shards_cmd.cpp | 3 +- src/mongo/s/commands/run_on_all_shards_cmd.h | 3 +- src/mongo/s/cursors.cpp | 7 +- src/mongo/s/d_migrate.cpp | 49 +++++- src/mongo/s/d_split.cpp | 28 +++- src/mongo/s/d_state.cpp | 28 +++- src/mongo/s/distlock_test.cpp | 24 ++- src/mongo/s/s_only.cpp | 14 +- 131 files changed, 1059 insertions(+), 607 deletions(-) create mode 100644 src/mongo/db/catalog/create_collection.cpp create mode 100644 src/mongo/db/catalog/create_collection.h (limited to 'src') diff --git a/src/mongo/SConscript b/src/mongo/SConscript index 13d3c8dd274..878d714947a 100644 --- a/src/mongo/SConscript +++ b/src/mongo/SConscript @@ -701,6 +701,7 @@ env.Library('elapsed_tracker', # libs. serverOnlyFiles = [ "db/background.cpp", "db/catalog/apply_ops.cpp", + "db/catalog/create_collection.cpp", "db/catalog/coll_mod.cpp", "db/catalog/collection.cpp", "db/catalog/collection_compact.cpp", diff --git a/src/mongo/db/auth/sasl_commands.cpp b/src/mongo/db/auth/sasl_commands.cpp index a6ef35c1a74..a4843e9d900 100644 --- a/src/mongo/db/auth/sasl_commands.cpp +++ b/src/mongo/db/auth/sasl_commands.cpp @@ -74,8 +74,7 @@ namespace { BSONObj& cmdObj, int options, std::string& ignored, - BSONObjBuilder& result, - bool fromRepl); + BSONObjBuilder& result); virtual void help(stringstream& help) const; virtual bool isWriteCommandForConfigServer() const { return false; } @@ -97,8 +96,7 @@ namespace { BSONObj& cmdObj, int options, std::string& ignored, - BSONObjBuilder& result, - bool fromRepl); + BSONObjBuilder& result); virtual void help(stringstream& help) const; virtual bool isWriteCommandForConfigServer() const { return false; } @@ -273,8 +271,7 @@ namespace { BSONObj& cmdObj, int options, std::string& ignored, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { ClientBasic* client = ClientBasic::getCurrent(); AuthenticationSession::set(client, std::unique_ptr()); @@ -319,8 +316,7 @@ namespace { BSONObj& cmdObj, int options, std::string& ignored, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { ClientBasic* client = ClientBasic::getCurrent(); std::unique_ptr sessionGuard; diff --git a/src/mongo/db/catalog/apply_ops.cpp b/src/mongo/db/catalog/apply_ops.cpp index 2ef6d46c9d0..9722982abfe 100644 --- a/src/mongo/db/catalog/apply_ops.cpp +++ b/src/mongo/db/catalog/apply_ops.cpp @@ -136,7 +136,6 @@ namespace mongo { repl::applyOperation_inlock(txn, ctx.db(), temp, - !txn->writesAreReplicated(), alwaysUpsert); break; } diff --git a/src/mongo/db/catalog/capped_utils.cpp b/src/mongo/db/catalog/capped_utils.cpp index 76be6e8d040..fc228a02025 100644 --- a/src/mongo/db/catalog/capped_utils.cpp +++ b/src/mongo/db/catalog/capped_utils.cpp @@ -41,6 +41,7 @@ #include "mongo/db/query/internal_plans.h" #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/service_context.h" +#include "mongo/util/scopeguard.h" namespace mongo { namespace { @@ -224,8 +225,9 @@ namespace { } - bool shouldReplicateWrites = txn->writesAreReplicated(); + const bool shouldReplicateWrites = txn->writesAreReplicated(); txn->setReplicatedWrites(false); + ON_BLOCK_EXIT(&OperationContext::setReplicatedWrites, txn, shouldReplicateWrites); Status status = cloneCollectionAsCapped(txn, db, shortSource.toString(), @@ -234,7 +236,6 @@ namespace { true); if (!status.isOK()) { - txn->setReplicatedWrites(shouldReplicateWrites); return status; } diff --git a/src/mongo/db/catalog/create_collection.cpp b/src/mongo/db/catalog/create_collection.cpp new file mode 100644 index 00000000000..fd598521a41 --- /dev/null +++ b/src/mongo/db/catalog/create_collection.cpp @@ -0,0 +1,94 @@ +/** + * Copyright (C) 2015 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 . + * + * 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. + */ + +#include "mongo/platform/basic.h" + +#include "mongo/db/catalog/create_collection.h" + +#include "mongo/bson/bsonobj.h" +#include "mongo/db/concurrency/write_conflict_exception.h" +#include "mongo/db/curop.h" +#include "mongo/db/db_raii.h" +#include "mongo/db/operation_context.h" +#include "mongo/db/ops/insert.h" +#include "mongo/db/repl/replication_coordinator_global.h" + +namespace mongo { + Status createCollection(OperationContext* txn, + const std::string& dbName, + const BSONObj& cmdObj) { + BSONObjIterator it(cmdObj); + + // Extract ns from first cmdObj element. + BSONElement firstElt = it.next(); + uassert(15888, + "must pass name of collection to create", + firstElt.valuestrsafe()[0] != '\0'); + + Status status = userAllowedWriteNS(dbName, firstElt.valuestr()); + if (!status.isOK()) { + return status; + } + + const std::string ns = dbName + '.' + firstElt.valuestrsafe(); + + // Build options object from remaining cmdObj elements. + BSONObjBuilder optionsBuilder; + while (it.more()) { + optionsBuilder.append(it.next()); + } + + BSONObj options = optionsBuilder.obj(); + uassert(14832, + "specify size: when capped is true", + !options["capped"].trueValue() || options["size"].isNumber() || + options.hasField("$nExtents")); + + MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN { + ScopedTransaction transaction(txn, MODE_IX); + Lock::DBLock dbXLock(txn->lockState(), dbName, MODE_X); + OldClientContext ctx(txn, ns); + if (txn->writesAreReplicated() && + !repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(dbName)) { + return Status(ErrorCodes::NotMaster, + str::stream() << "Not primary while creating collection " << ns); + } + + WriteUnitOfWork wunit(txn); + + // Create collection. + status = userCreateNS(txn, ctx.db(), ns.c_str(), options); + if (!status.isOK()) { + return status; + } + + wunit.commit(); + } MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "create", ns); + return Status::OK(); + } +} // namespace mongo diff --git a/src/mongo/db/catalog/create_collection.h b/src/mongo/db/catalog/create_collection.h new file mode 100644 index 00000000000..e96a7d799f9 --- /dev/null +++ b/src/mongo/db/catalog/create_collection.h @@ -0,0 +1,43 @@ +/** + * Copyright (C) 2015 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 . + * + * 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. + */ + +#include + +#include "mongo/base/status.h" + +namespace mongo { + class BSONObj; + class OperationContext; + + /** + * Creates a collection as described in "cmdObj" on the database "dbName". + */ + Status createCollection(OperationContext* txn, + const std::string& dbName, + const BSONObj& cmdObj); +} // namespace mongo diff --git a/src/mongo/db/clientcursor.cpp b/src/mongo/db/clientcursor.cpp index 9fc4c309aa5..d0919fce1ab 100644 --- a/src/mongo/db/clientcursor.cpp +++ b/src/mongo/db/clientcursor.cpp @@ -339,8 +339,12 @@ namespace mongo { actions.addAction(ActionType::cursorInfo); out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); } - bool run(OperationContext* txn, const string& dbname, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& result, - bool fromRepl ) { + bool run(OperationContext* txn, + const string& dbname, + BSONObj& jsobj, + int, + string& errmsg, + BSONObjBuilder& result) { _appendCursorStats( result ); return true; } diff --git a/src/mongo/db/clientlistplugin.cpp b/src/mongo/db/clientlistplugin.cpp index a777026cb0d..ba2069d2b69 100644 --- a/src/mongo/db/clientlistplugin.cpp +++ b/src/mongo/db/clientlistplugin.cpp @@ -174,8 +174,7 @@ namespace { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { scoped_ptr filter; if ( cmdObj["filter"].isABSONObj() ) { diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp index c8dae4e827d..88fdec2ece3 100644 --- a/src/mongo/db/cloner.cpp +++ b/src/mongo/db/cloner.cpp @@ -131,7 +131,7 @@ namespace mongo { uassert(ErrorCodes::NotMaster, str::stream() << "Not primary while cloning collection " << from_collection.ns() << " to " << to_collection.ns(), - !logForRepl || + !txn->writesAreReplicated() || repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(_dbName)); // Make sure database still exists after we resume from the temp release @@ -148,7 +148,6 @@ namespace mongo { << to_collection.ns() << "]", !createdCollection ); WriteUnitOfWork wunit(txn); - invariant(logForRepl == txn->writesAreReplicated()); collection = db->createCollection(txn, to_collection.ns(), CollectionOptions()); verify(collection); @@ -179,7 +178,7 @@ namespace mongo { globalWriteLock.reset(new Lock::GlobalWrite(txn->lockState())); // Check if everything is still all right. - if (logForRepl) { + if (txn->writesAreReplicated()) { uassert(28592, str::stream() << "Cannot write to db: " << _dbName << " after yielding", @@ -246,7 +245,6 @@ namespace mongo { NamespaceString from_collection; NamespaceString to_collection; time_t saveLast; - bool logForRepl; bool _mayYield; bool _mayBeInterrupted; }; @@ -257,7 +255,6 @@ namespace mongo { const string& toDBName, const NamespaceString& from_collection, const NamespaceString& to_collection, - bool logForRepl, bool masterSameProcess, bool slaveOk, bool mayYield, @@ -270,7 +267,6 @@ namespace mongo { f.from_collection = from_collection; f.to_collection = to_collection; f.saveLast = time( 0 ); - f.logForRepl = logForRepl; f._mayYield = mayYield; f._mayBeInterrupted = mayBeInterrupted; @@ -285,7 +281,7 @@ namespace mongo { str::stream() << "Not primary while cloning collection " << from_collection.ns() << " to " << to_collection.ns() << " with filter " << query.toString(), - !logForRepl || + !txn->writesAreReplicated() || repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(toDBName)); } @@ -293,7 +289,6 @@ namespace mongo { const string& toDBName, const NamespaceString& from_collection, const NamespaceString& to_collection, - bool logForRepl, bool masterSameProcess, bool slaveOk, bool mayYield, @@ -317,7 +312,7 @@ namespace mongo { uassert(ErrorCodes::NotMaster, str::stream() << "Not primary while copying indexes from " << from_collection.ns() << " to " << to_collection.ns() << " (Cloner)", - !logForRepl || + !txn->writesAreReplicated() || repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(toDBName)); @@ -331,7 +326,6 @@ namespace mongo { Collection* collection = db->getCollection( to_collection ); if ( !collection ) { WriteUnitOfWork wunit(txn); - invariant(logForRepl == txn->writesAreReplicated()); collection = db->createCollection(txn, to_collection.ns(), CollectionOptions()); invariant(collection); wunit.commit(); @@ -355,7 +349,7 @@ namespace mongo { WriteUnitOfWork wunit(txn); indexer.commit(); - if (logForRepl) { + if (txn->writesAreReplicated()) { const string targetSystemIndexesCollectionName = to_collection.getSystemIndexesCollection(); const char* createIndexNs = targetSystemIndexesCollectionName.c_str(); @@ -373,8 +367,7 @@ namespace mongo { string& errmsg, bool mayYield, bool mayBeInterrupted, - bool shouldCopyIndexes, - bool logForRepl) { + bool shouldCopyIndexes) { const NamespaceString nss(ns); const string dbname = nss.db().toString(); @@ -384,7 +377,7 @@ namespace mongo { uassert(ErrorCodes::NotMaster, str::stream() << "Not primary while copying collection " << ns << " (Cloner)", - !logForRepl || + !txn->writesAreReplicated() || repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(dbname)); Database* db = dbHolder().openDb(txn, dbname); @@ -397,7 +390,6 @@ namespace mongo { BSONObj col = collList.front(); if (col["options"].isABSONObj()) { WriteUnitOfWork wunit(txn); - invariant(logForRepl == txn->writesAreReplicated()); Status status = userCreateNS(txn, db, ns, col["options"].Obj(), 0); if ( !status.isOK() ) { errmsg = status.toString(); @@ -410,7 +402,7 @@ namespace mongo { // main data copy(txn, dbname, nss, nss, - logForRepl, false, true, mayYield, mayBeInterrupted, + false, true, mayYield, mayBeInterrupted, Query(query).snapshot()); /* TODO : copyIndexes bool does not seem to be implemented! */ @@ -421,7 +413,7 @@ namespace mongo { // indexes copyIndexes(txn, dbname, NamespaceString(ns), NamespaceString(ns), - logForRepl, false, true, mayYield, + false, true, mayYield, mayBeInterrupted); return true; @@ -438,7 +430,9 @@ namespace mongo { if ( errCode ) { *errCode = 0; } - massert( 10289 , "useReplAuth is not written to replication log", !opts.useReplAuth || !opts.logForRepl ); + massert(10289, + "useReplAuth is not written to replication log", + !opts.useReplAuth || !txn->writesAreReplicated()); const ConnectionString cs = ConnectionString::parse(masterHost, errmsg); if (!cs.isValid()) { @@ -559,7 +553,7 @@ namespace mongo { uassert(ErrorCodes::NotMaster, str::stream() << "Not primary while cloning database " << opts.fromDB << " (after getting list of collections to clone)", - !opts.logForRepl || + !txn->writesAreReplicated() || repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(toDBName)); if ( opts.syncData ) { @@ -579,7 +573,6 @@ namespace mongo { // we defer building id index for performance - building it in batch is much // faster - invariant(opts.logForRepl == txn->writesAreReplicated()); Status createStatus = userCreateNS(txn, db, to_name.ns(), options, false); if ( !createStatus.isOK() ) { errmsg = str::stream() << "failed to create collection \"" @@ -600,7 +593,6 @@ namespace mongo { toDBName, from_name, to_name, - opts.logForRepl, masterSameProcess, opts.slaveOk, opts.mayYield, @@ -635,7 +627,11 @@ namespace mongo { WriteUnitOfWork wunit(txn); BSONObj id; - c->deleteDocument(txn, *it, true, true, opts.logForRepl ? &id : NULL); + c->deleteDocument(txn, + *it, + true, + true, + txn->writesAreReplicated() ? &id : nullptr); wunit.commit(); } @@ -645,7 +641,7 @@ namespace mongo { WriteUnitOfWork wunit(txn); indexer.commit(); - if (opts.logForRepl) { + if (txn->writesAreReplicated()) { getGlobalServiceContext()->getOpObserver()->onCreateIndex( txn, c->ns().getSystemIndexesCollection().c_str(), @@ -671,7 +667,6 @@ namespace mongo { toDBName, from_name, to_name, - opts.logForRepl, masterSameProcess, opts.slaveOk, opts.mayYield, diff --git a/src/mongo/db/cloner.h b/src/mongo/db/cloner.h index 80dd941b19e..e9218d8ab67 100644 --- a/src/mongo/db/cloner.h +++ b/src/mongo/db/cloner.h @@ -65,15 +65,13 @@ namespace mongo { std::string& errmsg, bool mayYield, bool mayBeInterrupted, - bool copyIndexes = true, - bool logForRepl = true ); + bool copyIndexes = true); private: void copy(OperationContext* txn, const std::string& toDBName, const NamespaceString& from_ns, const NamespaceString& to_ns, - bool logForRepl, bool masterSameProcess, bool slaveOk, bool mayYield, @@ -84,7 +82,6 @@ namespace mongo { const std::string& toDBName, const NamespaceString& from_ns, const NamespaceString& to_ns, - bool logForRepl, bool masterSameProcess, bool slaveOk, bool mayYield, @@ -103,7 +100,6 @@ namespace mongo { */ struct CloneOptions { CloneOptions() { - logForRepl = true; slaveOk = false; useReplAuth = false; snapshot = true; @@ -117,7 +113,6 @@ namespace mongo { std::string fromDB; std::set collsToIgnore; - bool logForRepl; bool slaveOk; bool useReplAuth; bool snapshot; diff --git a/src/mongo/db/commands.cpp b/src/mongo/db/commands.cpp index f81caefe991..0db0b13e739 100644 --- a/src/mongo/db/commands.cpp +++ b/src/mongo/db/commands.cpp @@ -364,10 +364,9 @@ namespace mongo { static Status _checkAuthorizationImpl(Command* c, ClientBasic* client, const std::string& dbname, - const BSONObj& cmdObj, - bool fromRepl) { + const BSONObj& cmdObj) { namespace mmb = mutablebson; - if ( c->adminOnly() && ! fromRepl && dbname != "admin" ) { + if ( c->adminOnly() && dbname != "admin" ) { return Status(ErrorCodes::Unauthorized, str::stream() << c->name << " may only be run against the admin database."); } @@ -397,10 +396,9 @@ namespace mongo { Status Command::_checkAuthorization(Command* c, ClientBasic* client, const std::string& dbname, - const BSONObj& cmdObj, - bool fromRepl) { + const BSONObj& cmdObj) { namespace mmb = mutablebson; - Status status = _checkAuthorizationImpl(c, client, dbname, cmdObj, fromRepl); + Status status = _checkAuthorizationImpl(c, client, dbname, cmdObj); if (!status.isOK()) { log(LogComponent::kAccessControl) << status << std::endl; } @@ -434,7 +432,12 @@ namespace mongo { out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); } - virtual bool run(OperationContext* txn, const string&, mongo::BSONObj&, int, std::string&, mongo::BSONObjBuilder& result, bool) { + virtual bool run(OperationContext* txn, + const string&, + mongo::BSONObj&, + int, + std::string&, + mongo::BSONObjBuilder& result) { shardConnectionPool.flush(); pool.flush(); return true; @@ -457,7 +460,12 @@ namespace mongo { actions.addAction(ActionType::connPoolStats); out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); } - virtual bool run(OperationContext* txn, const string&, mongo::BSONObj&, int, std::string&, mongo::BSONObjBuilder& result, bool) { + virtual bool run(OperationContext* txn, + const string&, + mongo::BSONObj&, + int, + std::string&, + mongo::BSONObjBuilder& result) { pool.appendInfo( result ); result.append( "numDBClientConnection" , DBClientConnection::getNumConnections() ); result.append( "numAScopedConnection" , AScopedConnection::getNumConnections() ); diff --git a/src/mongo/db/commands.h b/src/mongo/db/commands.h index c3da3ad9578..16db4cf84bd 100644 --- a/src/mongo/db/commands.h +++ b/src/mongo/db/commands.h @@ -91,9 +91,6 @@ namespace mutablebson { /* run the given command implement this... - fromRepl - command is being invoked as part of replication syncing. In this situation you - normally do not want to log the command to the local oplog. - return value is true if succeeded. if false, set errmsg text. */ virtual bool run(OperationContext* txn, @@ -101,8 +98,7 @@ namespace mutablebson { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl = false ) = 0; + BSONObjBuilder& result) = 0; /** * This designation for the command is only used by the 'help' call and has nothing to do @@ -130,7 +126,6 @@ namespace mutablebson { virtual bool localHostOnlyIfNoAuth(const BSONObj& cmdObj) { return false; } /* Return true if slaves are allowed to execute the command - (the command directly from a client -- if fromRepl, always allowed). */ virtual bool slaveOk() const = 0; @@ -262,8 +257,7 @@ namespace mutablebson { int queryOptions, const char *ns, BSONObj& cmdObj, - BSONObjBuilder& result, - bool fromRepl ); + BSONObjBuilder& result); // For mongos static void execCommandClientBasic(OperationContext* txn, Command* c, @@ -271,8 +265,7 @@ namespace mutablebson { int queryOptions, const char *ns, BSONObj& cmdObj, - BSONObjBuilder& result, - bool fromRepl ); + BSONObjBuilder& result); // Helper for setting errmsg and ok field in command result object. static void appendCommandStatus(BSONObjBuilder& result, bool ok, const std::string& errmsg); @@ -339,10 +332,6 @@ namespace mutablebson { * Checks to see if the client is authorized to run the given command with the given * parameters on the given named database. * - * fromRepl is true if this command is running as part of oplog application, which for - * historic reasons has slightly different authorization semantics. TODO(schwerin): Check - * to see if this oddity can now be eliminated. - * * Returns Status::OK() if the command is authorized. Most likely returns * ErrorCodes::Unauthorized otherwise, but any return other than Status::OK implies not * authorized. @@ -350,8 +339,7 @@ namespace mutablebson { static Status _checkAuthorization(Command* c, ClientBasic* client, const std::string& dbname, - const BSONObj& cmdObj, - bool fromRepl); + const BSONObj& cmdObj); }; bool _runCommands(OperationContext* txn, @@ -359,7 +347,7 @@ namespace mutablebson { BSONObj& _cmdobj, BufBuilder& b, BSONObjBuilder& anObjBuilder, - bool fromRepl, int queryOptions); + int queryOptions); bool runCommands(OperationContext* txn, const char* ns, @@ -367,7 +355,6 @@ namespace mutablebson { CurOp& curop, BufBuilder& b, BSONObjBuilder& anObjBuilder, - bool fromRepl, int queryOptions); } // namespace mongo diff --git a/src/mongo/db/commands/apply_ops.cpp b/src/mongo/db/commands/apply_ops.cpp index 5342d8ac1c8..3222c371ddc 100644 --- a/src/mongo/db/commands/apply_ops.cpp +++ b/src/mongo/db/commands/apply_ops.cpp @@ -80,10 +80,7 @@ namespace mongo { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { - invariant(!fromRepl == txn->writesAreReplicated()); - + BSONObjBuilder& result) { if ( cmdObj.firstElement().type() != Array ) { errmsg = "ops has to be an array"; return false; diff --git a/src/mongo/db/commands/authentication_commands.cpp b/src/mongo/db/commands/authentication_commands.cpp index 4a432e03cb2..6ebe3f06da8 100644 --- a/src/mongo/db/commands/authentication_commands.cpp +++ b/src/mongo/db/commands/authentication_commands.cpp @@ -113,7 +113,12 @@ namespace mongo { virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, std::vector* out) {} // No auth required - bool run(OperationContext* txn, const string&, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { nonce64 n = getNextNonce(); stringstream ss; ss << hex << n; @@ -152,8 +157,7 @@ namespace mongo { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { if (!serverGlobalParams.quiet) { mutablebson::Document cmdToLog(cmdObj, mutablebson::Document::kInPlaceDisabled); @@ -413,8 +417,7 @@ namespace mongo { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { AuthorizationSession* authSession = AuthorizationSession::get(ClientBasic::getCurrent()); authSession->logoutDatabase(dbname); diff --git a/src/mongo/db/commands/authentication_commands.h b/src/mongo/db/commands/authentication_commands.h index e6b0dd87ab5..e22711454e2 100644 --- a/src/mongo/db/commands/authentication_commands.h +++ b/src/mongo/db/commands/authentication_commands.h @@ -55,8 +55,7 @@ namespace mongo { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl); + BSONObjBuilder& result); private: /** diff --git a/src/mongo/db/commands/cleanup_orphaned_cmd.cpp b/src/mongo/db/commands/cleanup_orphaned_cmd.cpp index 3294bec5b92..876297e2d56 100644 --- a/src/mongo/db/commands/cleanup_orphaned_cmd.cpp +++ b/src/mongo/db/commands/cleanup_orphaned_cmd.cpp @@ -216,8 +216,7 @@ namespace mongo { BSONObj &cmdObj, int, string &errmsg, - BSONObjBuilder &result, - bool ) { + BSONObjBuilder &result) { string ns; if ( !FieldParser::extract( cmdObj, nsField, &ns, &errmsg ) ) { diff --git a/src/mongo/db/commands/clone.cpp b/src/mongo/db/commands/clone.cpp index bc0b8f70311..78b576553b3 100644 --- a/src/mongo/db/commands/clone.cpp +++ b/src/mongo/db/commands/clone.cpp @@ -92,8 +92,7 @@ namespace mongo { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { string from = cmdObj.getStringField("clone"); if ( from.empty() ) @@ -101,7 +100,6 @@ namespace mongo { CloneOptions opts; opts.fromDB = dbname; - opts.logForRepl = ! fromRepl; opts.slaveOk = cmdObj["slaveOk"].trueValue(); // See if there's any collections we should ignore diff --git a/src/mongo/db/commands/clone_collection.cpp b/src/mongo/db/commands/clone_collection.cpp index 734d49ff100..1c5bbfe0bb2 100644 --- a/src/mongo/db/commands/clone_collection.cpp +++ b/src/mongo/db/commands/clone_collection.cpp @@ -104,8 +104,7 @@ namespace mongo { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { string fromhost = cmdObj.getStringField("from"); if ( fromhost.empty() ) { diff --git a/src/mongo/db/commands/collection_to_capped.cpp b/src/mongo/db/commands/collection_to_capped.cpp index 5538e4b70e0..97e4637d296 100644 --- a/src/mongo/db/commands/collection_to_capped.cpp +++ b/src/mongo/db/commands/collection_to_capped.cpp @@ -82,9 +82,7 @@ namespace mongo { BSONObj& jsobj, int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { - invariant(!fromRepl == txn->writesAreReplicated()); + BSONObjBuilder& result) { string from = jsobj.getStringField( "cloneCollectionAsCapped" ); string to = jsobj.getStringField( "toCollection" ); double size = jsobj.getField( "size" ).number(); @@ -98,8 +96,7 @@ namespace mongo { ScopedTransaction transaction(txn, MODE_IX); AutoGetDb autoDb(txn, dbname, MODE_X); - if (!fromRepl && - !repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(dbname)) { + if (!repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(dbname)) { return appendCommandStatus(result, Status(ErrorCodes::NotMaster, str::stream() << "Not primary while cloning collection " << from << " to " << to << " (as capped)")); @@ -156,8 +153,7 @@ namespace mongo { BSONObj& jsobj, int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl ) { + BSONObjBuilder& result) { string shortSource = jsobj.getStringField( "convertToCapped" ); double size = jsobj.getField( "size" ).number(); diff --git a/src/mongo/db/commands/compact.cpp b/src/mongo/db/commands/compact.cpp index 12bb7f16a6d..c0986823389 100644 --- a/src/mongo/db/commands/compact.cpp +++ b/src/mongo/db/commands/compact.cpp @@ -87,7 +87,12 @@ namespace mongo { return IndexBuilder::killMatchingIndexBuilds(db->getCollection(ns), criteria); } - virtual bool run(OperationContext* txn, const string& db, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + virtual bool run(OperationContext* txn, + const string& db, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { const std::string nsToCompact = parseNsCollectionRequired(db, cmdObj); repl::ReplicationCoordinator* replCoord = repl::getGlobalReplicationCoordinator(); diff --git a/src/mongo/db/commands/connection_status.cpp b/src/mongo/db/commands/connection_status.cpp index 1ad5d9f4318..06a4367c9ed 100644 --- a/src/mongo/db/commands/connection_status.cpp +++ b/src/mongo/db/commands/connection_status.cpp @@ -52,7 +52,7 @@ namespace mongo { } bool run(OperationContext* txn, const string&, BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, bool fromRepl) { + BSONObjBuilder& result) { AuthorizationSession* authSession = AuthorizationSession::get(ClientBasic::getCurrent()); diff --git a/src/mongo/db/commands/copydb.cpp b/src/mongo/db/commands/copydb.cpp index d043f717ddd..415f3b396c7 100644 --- a/src/mongo/db/commands/copydb.cpp +++ b/src/mongo/db/commands/copydb.cpp @@ -126,8 +126,7 @@ namespace mongo { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { string fromhost = cmdObj.getStringField("fromhost"); bool fromSelf = fromhost.empty(); @@ -140,7 +139,6 @@ namespace mongo { CloneOptions cloneOptions; cloneOptions.fromDB = cmdObj.getStringField("fromdb"); - cloneOptions.logForRepl = !fromRepl; cloneOptions.slaveOk = cmdObj["slaveOk"].trueValue(); cloneOptions.useReplAuth = false; cloneOptions.snapshot = true; diff --git a/src/mongo/db/commands/copydb_start_commands.cpp b/src/mongo/db/commands/copydb_start_commands.cpp index 18979fa6022..99c79e9345a 100644 --- a/src/mongo/db/commands/copydb_start_commands.cpp +++ b/src/mongo/db/commands/copydb_start_commands.cpp @@ -100,8 +100,7 @@ namespace mongo { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { string fromhost = cmdObj.getStringField("fromhost"); if ( fromhost.empty() ) { @@ -174,8 +173,7 @@ namespace mongo { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { string fromDb = cmdObj.getStringField("fromdb"); string fromHost = cmdObj.getStringField("fromhost"); diff --git a/src/mongo/db/commands/count.cpp b/src/mongo/db/commands/count.cpp index 64605e5878a..15700af1d42 100644 --- a/src/mongo/db/commands/count.cpp +++ b/src/mongo/db/commands/count.cpp @@ -114,8 +114,7 @@ namespace mongo { const string& dbname, BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { CountRequest request; Status parseStatus = parseRequest(dbname, cmdObj, &request); diff --git a/src/mongo/db/commands/cpuprofile.cpp b/src/mongo/db/commands/cpuprofile.cpp index 283e9d7c0b6..b50dd0233a5 100644 --- a/src/mongo/db/commands/cpuprofile.cpp +++ b/src/mongo/db/commands/cpuprofile.cpp @@ -100,8 +100,7 @@ namespace mongo { BSONObj &cmdObj, int options, std::string &errmsg, - BSONObjBuilder &result, - bool fromRepl ); + BSONObjBuilder &result); static char const *const commandName; } cpuProfilerStartCommandInstance; @@ -118,8 +117,7 @@ namespace mongo { BSONObj &cmdObj, int options, std::string &errmsg, - BSONObjBuilder &result, - bool fromRepl ); + BSONObjBuilder &result); static char const *const commandName; } cpuProfilerStopCommandInstance; @@ -132,8 +130,7 @@ namespace mongo { BSONObj &cmdObj, int options, std::string &errmsg, - BSONObjBuilder &result, - bool fromRepl ) { + BSONObjBuilder &result) { ScopedTransaction transaction(txn, MODE_IX); Lock::DBLock dbXLock(txn->lockState(), db, MODE_X); // The lock here is just to prevent concurrency, nothing will write. @@ -152,8 +149,7 @@ namespace mongo { BSONObj &cmdObj, int options, std::string &errmsg, - BSONObjBuilder &result, - bool fromRepl ) { + BSONObjBuilder &result) { ScopedTransaction transaction(txn, MODE_IX); Lock::DBLock dbXLock(txn->lockState(), db, MODE_X); OldClientContext ctx(txn, db); diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp index 6b0de488273..46ad1759247 100644 --- a/src/mongo/db/commands/create_indexes.cpp +++ b/src/mongo/db/commands/create_indexes.cpp @@ -84,10 +84,7 @@ namespace mongo { } virtual bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int options, - string& errmsg, BSONObjBuilder& result, - bool fromRepl = false ) { - invariant(!fromRepl == txn->writesAreReplicated()); - + string& errmsg, BSONObjBuilder& result) { // --- parse NamespaceString ns( dbname, cmdObj[name].String() ); @@ -144,8 +141,7 @@ namespace mongo { // Note: createIndexes command does not currently respect shard versioning. ScopedTransaction transaction(txn, MODE_IX); Lock::DBLock dbLock(txn->lockState(), ns.db(), MODE_X); - if (!fromRepl && - !repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(dbname)) { + if (!repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(dbname)) { return appendCommandStatus(result, Status(ErrorCodes::NotMaster, str::stream() << "Not primary while creating indexes in " << ns.ns())); } @@ -207,8 +203,7 @@ namespace mongo { if (indexer.getBuildInBackground()) { txn->recoveryUnit()->commitAndRestart(); dbLock.relockWithMode(MODE_IX); - if (!fromRepl && - !repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(dbname)) { + if (!repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(dbname)) { return appendCommandStatus(result, Status(ErrorCodes::NotMaster, str::stream() << "Not primary while creating background indexes in " << ns.ns())); } @@ -228,8 +223,7 @@ namespace mongo { // that day, to avoid data corruption due to lack of index cleanup. txn->recoveryUnit()->commitAndRestart(); dbLock.relockWithMode(MODE_X); - if (!fromRepl && - !repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase( + if (!repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase( dbname)) { return appendCommandStatus( result, @@ -251,7 +245,6 @@ namespace mongo { dbLock.relockWithMode(MODE_X); uassert(ErrorCodes::NotMaster, str::stream() << "Not primary while completing index build in " << dbname, - fromRepl || repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase( dbname)); @@ -266,13 +259,11 @@ namespace mongo { indexer.commit(); - if ( !fromRepl ) { - for ( size_t i = 0; i < specs.size(); i++ ) { - std::string systemIndexes = ns.getSystemIndexesCollection(); - getGlobalServiceContext()->getOpObserver()->onCreateIndex(txn, - systemIndexes, - specs[i]); - } + for ( size_t i = 0; i < specs.size(); i++ ) { + std::string systemIndexes = ns.getSystemIndexesCollection(); + getGlobalServiceContext()->getOpObserver()->onCreateIndex(txn, + systemIndexes, + specs[i]); } wunit.commit(); diff --git a/src/mongo/db/commands/current_op.cpp b/src/mongo/db/commands/current_op.cpp index 6648aa7d869..f5306d9dbe0 100644 --- a/src/mongo/db/commands/current_op.cpp +++ b/src/mongo/db/commands/current_op.cpp @@ -74,8 +74,7 @@ namespace mongo { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) final { + BSONObjBuilder& result) final { const bool includeAll = cmdObj["$all"].trueValue(); diff --git a/src/mongo/db/commands/dbhash.cpp b/src/mongo/db/commands/dbhash.cpp index 9f12c82d699..b99d8305a40 100644 --- a/src/mongo/db/commands/dbhash.cpp +++ b/src/mongo/db/commands/dbhash.cpp @@ -143,7 +143,12 @@ namespace mongo { return hash; } - bool DBHashCmd::run(OperationContext* txn, const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + bool DBHashCmd::run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { Timer timer; set desiredCollections; diff --git a/src/mongo/db/commands/dbhash.h b/src/mongo/db/commands/dbhash.h index 2063cfeca22..35e5c9302fb 100644 --- a/src/mongo/db/commands/dbhash.h +++ b/src/mongo/db/commands/dbhash.h @@ -46,7 +46,12 @@ namespace mongo { const BSONObj& cmdObj, std::vector* out); - virtual bool run(OperationContext* txn, const std::string& dbname , BSONObj& cmdObj, int, std::string& errmsg, BSONObjBuilder& result, bool); + virtual bool run(OperationContext* txn, + const std::string& dbname, + BSONObj& cmdObj, + int, + std::string& errmsg, + BSONObjBuilder& result); void wipeCacheForCollection(OperationContext* txn, StringData ns); diff --git a/src/mongo/db/commands/distinct.cpp b/src/mongo/db/commands/distinct.cpp index 3bf0220c8c9..778bfdd723d 100644 --- a/src/mongo/db/commands/distinct.cpp +++ b/src/mongo/db/commands/distinct.cpp @@ -71,8 +71,12 @@ namespace mongo { help << "{ distinct : 'collection name' , key : 'a.b' , query : {} }"; } - bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, - bool fromRepl ) { + bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { Timer t; diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp index 8b1a898be1e..d4558145bce 100644 --- a/src/mongo/db/commands/drop_indexes.cpp +++ b/src/mongo/db/commands/drop_indexes.cpp @@ -83,9 +83,12 @@ namespace mongo { } CmdDropIndexes() : Command("dropIndexes", false, "deleteIndexes") { } - bool run(OperationContext* txn, const string& dbname, BSONObj& jsobj, int, string& errmsg, - BSONObjBuilder& result, bool fromRepl) { - invariant(!fromRepl == txn->writesAreReplicated()); + bool run(OperationContext* txn, + const string& dbname, + BSONObj& jsobj, + int, + string& errmsg, + BSONObjBuilder& result) { const std::string ns = parseNsCollectionRequired(dbname, jsobj); return appendCommandStatus(result, dropIndexes(txn, @@ -121,7 +124,12 @@ namespace mongo { return IndexBuilder::killMatchingIndexBuilds(db->getCollection(ns), criteria); } - bool run(OperationContext* txn, const string& dbname , BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& result, bool /*fromRepl*/) { + bool run(OperationContext* txn, + const string& dbname, + BSONObj& jsobj, + int, + string& errmsg, + BSONObjBuilder& result) { DBDirectClient db(txn); const std::string toDeleteNs = parseNsCollectionRequired(dbname, jsobj); diff --git a/src/mongo/db/commands/explain_cmd.cpp b/src/mongo/db/commands/explain_cmd.cpp index 9a411c8fa26..b7184152110 100644 --- a/src/mongo/db/commands/explain_cmd.cpp +++ b/src/mongo/db/commands/explain_cmd.cpp @@ -67,15 +67,7 @@ namespace mongo { const string& dbname, BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { - // Should never get explain commands issued from replication. - if (fromRepl) { - Status commandStat(ErrorCodes::IllegalOperation, - "explain command should not be from repl"); - appendCommandStatus(result, commandStat); - return false; - } + BSONObjBuilder& result) { ExplainCommon::Verbosity verbosity; Status parseStatus = ExplainCommon::parseCmdBSON(cmdObj, &verbosity); diff --git a/src/mongo/db/commands/explain_cmd.h b/src/mongo/db/commands/explain_cmd.h index 5fab99fc8ff..24edec205ca 100644 --- a/src/mongo/db/commands/explain_cmd.h +++ b/src/mongo/db/commands/explain_cmd.h @@ -82,8 +82,7 @@ namespace mongo { const std::string& dbname, BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl); + BSONObjBuilder& result); }; diff --git a/src/mongo/db/commands/fail_point_cmd.cpp b/src/mongo/db/commands/fail_point_cmd.cpp index 4b570c828e9..944d3ca491c 100644 --- a/src/mongo/db/commands/fail_point_cmd.cpp +++ b/src/mongo/db/commands/fail_point_cmd.cpp @@ -88,8 +88,7 @@ namespace mongo { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { const string failPointName(cmdObj.firstElement().str()); FailPointRegistry* registry = getGlobalFailPointRegistry(); FailPoint* failPoint = registry->getFailPoint(failPointName); diff --git a/src/mongo/db/commands/find_and_modify.cpp b/src/mongo/db/commands/find_and_modify.cpp index 227f684e16d..b8e76b8e0a2 100644 --- a/src/mongo/db/commands/find_and_modify.cpp +++ b/src/mongo/db/commands/find_and_modify.cpp @@ -395,9 +395,9 @@ namespace { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) override { - invariant(!fromRepl); // findAndModify command is not replicated directly. + BSONObjBuilder& result) override { + // findAndModify command is not replicated directly. + invariant(txn->writesAreReplicated()); const std::string fullNs = parseNsCollectionRequired(dbName, cmdObj); StatusWith parseStatus = diff --git a/src/mongo/db/commands/find_cmd.cpp b/src/mongo/db/commands/find_cmd.cpp index 3e41d395090..e856c9639a8 100644 --- a/src/mongo/db/commands/find_cmd.cpp +++ b/src/mongo/db/commands/find_cmd.cpp @@ -174,8 +174,7 @@ namespace mongo { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) override { + BSONObjBuilder& result) override { const std::string fullns = parseNs(dbname, cmdObj); const NamespaceString nss(fullns); diff --git a/src/mongo/db/commands/fsync.cpp b/src/mongo/db/commands/fsync.cpp index 3307e96b80e..fb4e1dd167b 100644 --- a/src/mongo/db/commands/fsync.cpp +++ b/src/mongo/db/commands/fsync.cpp @@ -105,7 +105,12 @@ namespace mongo { actions.addAction(ActionType::fsync); out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); } - virtual bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + virtual bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { if (txn->lockState()->isLocked()) { errmsg = "fsync: Cannot execute fsync command from contexts that hold a data lock"; @@ -191,8 +196,7 @@ namespace mongo { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) override { + BSONObjBuilder& result) override { log() << "command: unlock requested"; diff --git a/src/mongo/db/commands/geo_near_cmd.cpp b/src/mongo/db/commands/geo_near_cmd.cpp index 066386779de..d543772e0ae 100644 --- a/src/mongo/db/commands/geo_near_cmd.cpp +++ b/src/mongo/db/commands/geo_near_cmd.cpp @@ -77,7 +77,12 @@ namespace mongo { out->push_back(Privilege(parseResourcePattern(dbname, cmdObj), actions)); } - bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { if (!cmdObj["start"].eoo()) { errmsg = "using deprecated 'start' argument to geoNear"; return false; diff --git a/src/mongo/db/commands/get_last_error.cpp b/src/mongo/db/commands/get_last_error.cpp index 065fc484d58..25a2069dee6 100644 --- a/src/mongo/db/commands/get_last_error.cpp +++ b/src/mongo/db/commands/get_last_error.cpp @@ -66,7 +66,12 @@ namespace mongo { help << "reset error state (used with getpreverror)"; } CmdResetError() : Command("resetError", false, "reseterror") {} - bool run(OperationContext* txn, const string& db, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + bool run(OperationContext* txn, + const string& db, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { LastError *le = lastError.get(); verify( le ); le->reset(); @@ -97,8 +102,7 @@ namespace mongo { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl ) { + BSONObjBuilder& result) { // // Correct behavior here is very finicky. @@ -275,7 +279,12 @@ namespace mongo { const BSONObj& cmdObj, std::vector* out) {} // No auth required CmdGetPrevError() : Command("getPrevError", false, "getpreverror") {} - bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { LastError *le = lastError.disableForCommand(); le->appendSelf( result ); if ( le->valid ) diff --git a/src/mongo/db/commands/getmore_cmd.cpp b/src/mongo/db/commands/getmore_cmd.cpp index 190e9bac1e6..4e96ae4544c 100644 --- a/src/mongo/db/commands/getmore_cmd.cpp +++ b/src/mongo/db/commands/getmore_cmd.cpp @@ -110,8 +110,7 @@ namespace mongo { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) override { + BSONObjBuilder& result) override { // Counted as a getMore, not as a command. globalOpCounters.gotGetMore(); diff --git a/src/mongo/db/commands/group.cpp b/src/mongo/db/commands/group.cpp index d7310e69ab8..4dd4f5a1956 100644 --- a/src/mongo/db/commands/group.cpp +++ b/src/mongo/db/commands/group.cpp @@ -132,8 +132,7 @@ namespace mongo { BSONObj& cmdObj, int, std::string& errmsg, - BSONObjBuilder& out, - bool fromRepl) { + BSONObjBuilder& out) { GroupRequest groupRequest; Status parseRequestStatus = parseRequest(dbname, cmdObj, &groupRequest); if (!parseRequestStatus.isOK()) { diff --git a/src/mongo/db/commands/group.h b/src/mongo/db/commands/group.h index 55da71df1d0..d6486a8d978 100644 --- a/src/mongo/db/commands/group.h +++ b/src/mongo/db/commands/group.h @@ -68,8 +68,7 @@ namespace mongo { BSONObj& jsobj, int, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl); + BSONObjBuilder& result); virtual Status explain(OperationContext* txn, const std::string& dbname, diff --git a/src/mongo/db/commands/hashcmd.cpp b/src/mongo/db/commands/hashcmd.cpp index 94d9267ded7..21fc475469d 100644 --- a/src/mongo/db/commands/hashcmd.cpp +++ b/src/mongo/db/commands/hashcmd.cpp @@ -78,8 +78,7 @@ namespace mongo { bool run(OperationContext* txn, const string& db, BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl = false ){ + BSONObjBuilder& result){ result.appendAs(cmdObj.firstElement(),"key"); int seed = 0; diff --git a/src/mongo/db/commands/index_filter_commands.cpp b/src/mongo/db/commands/index_filter_commands.cpp index 8532a22df36..5aa1301b0cf 100644 --- a/src/mongo/db/commands/index_filter_commands.cpp +++ b/src/mongo/db/commands/index_filter_commands.cpp @@ -126,8 +126,12 @@ namespace mongo { : Command(name), helpText(helpText) { } - bool IndexFilterCommand::run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int options, - string& errmsg, BSONObjBuilder& result, bool fromRepl) { + bool IndexFilterCommand::run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int options, + string& errmsg, + BSONObjBuilder& result) { string ns = parseNs(dbname, cmdObj); Status status = runIndexFilterCommand(txn, ns, cmdObj, &result); diff --git a/src/mongo/db/commands/index_filter_commands.h b/src/mongo/db/commands/index_filter_commands.h index cb46b8d4e46..1ed6fa506c0 100644 --- a/src/mongo/db/commands/index_filter_commands.h +++ b/src/mongo/db/commands/index_filter_commands.h @@ -63,8 +63,12 @@ namespace mongo { * implement plan cache command functionality. */ - bool run(OperationContext* txn, const std::string& dbname, BSONObj& cmdObj, int options, - std::string& errmsg, BSONObjBuilder& result, bool fromRepl); + bool run(OperationContext* txn, + const std::string& dbname, + BSONObj& cmdObj, + int options, + std::string& errmsg, + BSONObjBuilder& result); virtual bool isWriteCommandForConfigServer() const; diff --git a/src/mongo/db/commands/isself.cpp b/src/mongo/db/commands/isself.cpp index 8b6c6fd6d9f..ebec8ae4fdb 100644 --- a/src/mongo/db/commands/isself.cpp +++ b/src/mongo/db/commands/isself.cpp @@ -50,7 +50,12 @@ namespace mongo { virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, std::vector* out) {} // No auth required - bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { + bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { result.append( "id" , repl::instanceId ); return true; } diff --git a/src/mongo/db/commands/kill_op.cpp b/src/mongo/db/commands/kill_op.cpp index afcc12c4a9f..efa43986d0d 100644 --- a/src/mongo/db/commands/kill_op.cpp +++ b/src/mongo/db/commands/kill_op.cpp @@ -71,8 +71,7 @@ namespace mongo { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) final { + BSONObjBuilder& result) final { long long op; uassertStatusOK(bsonExtractIntegerField(cmdObj, "op", &op)); diff --git a/src/mongo/db/commands/list_collections.cpp b/src/mongo/db/commands/list_collections.cpp index 64767c6cb07..1e98b719214 100644 --- a/src/mongo/db/commands/list_collections.cpp +++ b/src/mongo/db/commands/list_collections.cpp @@ -93,8 +93,7 @@ namespace mongo { BSONObj& jsobj, int, string& errmsg, - BSONObjBuilder& result, - bool /*fromRepl*/) { + BSONObjBuilder& result) { boost::scoped_ptr matcher; BSONElement filterElt = jsobj["filter"]; if (!filterElt.eoo()) { diff --git a/src/mongo/db/commands/list_databases.cpp b/src/mongo/db/commands/list_databases.cpp index e5997e36d2c..81779a83a76 100644 --- a/src/mongo/db/commands/list_databases.cpp +++ b/src/mongo/db/commands/list_databases.cpp @@ -74,8 +74,7 @@ namespace mongo { BSONObj& jsobj, int, string& errmsg, - BSONObjBuilder& result, - bool /*fromRepl*/) { + BSONObjBuilder& result) { vector< string > dbNames; StorageEngine* storageEngine = getGlobalServiceContext()->getGlobalStorageEngine(); diff --git a/src/mongo/db/commands/list_indexes.cpp b/src/mongo/db/commands/list_indexes.cpp index fddf6cc6cba..c53303b04c7 100644 --- a/src/mongo/db/commands/list_indexes.cpp +++ b/src/mongo/db/commands/list_indexes.cpp @@ -91,8 +91,7 @@ namespace mongo { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool /*fromRepl*/) { + BSONObjBuilder& result) { BSONElement first = cmdObj.firstElement(); uassert( diff --git a/src/mongo/db/commands/merge_chunks_cmd.cpp b/src/mongo/db/commands/merge_chunks_cmd.cpp index 9212b4183ff..87721b11469 100644 --- a/src/mongo/db/commands/merge_chunks_cmd.cpp +++ b/src/mongo/db/commands/merge_chunks_cmd.cpp @@ -88,8 +88,7 @@ namespace mongo { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool ) { + BSONObjBuilder& result) { string ns = parseNs(dbname, cmdObj); diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp index 259cb19a314..34b4ad96904 100644 --- a/src/mongo/db/commands/mr.cpp +++ b/src/mongo/db/commands/mr.cpp @@ -1266,8 +1266,12 @@ namespace mongo { addPrivilegesRequiredForMapReduce(this, dbname, cmdObj, out); } - bool run(OperationContext* txn, const string& dbname , BSONObj& cmd, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { - invariant(!fromRepl == txn->writesAreReplicated()); + bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmd, + int, + string& errmsg, + BSONObjBuilder& result) { Timer t; if (txn->getClient()->isInDirectClient()) { @@ -1546,7 +1550,12 @@ namespace mongo { actions.addAction(ActionType::internal); out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); } - bool run(OperationContext* txn, const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { ShardedConnectionInfo::addHook(); // legacy name string shardedOutputCollection = cmdObj["shardedOutputCollection"].valuestrsafe(); diff --git a/src/mongo/db/commands/oplog_note.cpp b/src/mongo/db/commands/oplog_note.cpp index c57d43c86bb..c512c2a8c8b 100644 --- a/src/mongo/db/commands/oplog_note.cpp +++ b/src/mongo/db/commands/oplog_note.cpp @@ -67,8 +67,7 @@ namespace mongo { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { if (!repl::getGlobalReplicationCoordinator()->isReplEnabled()) { return appendCommandStatus(result, Status( ErrorCodes::NoReplicationEnabled, diff --git a/src/mongo/db/commands/parallel_collection_scan.cpp b/src/mongo/db/commands/parallel_collection_scan.cpp index a84e9070a21..49ebeb9de5a 100644 --- a/src/mongo/db/commands/parallel_collection_scan.cpp +++ b/src/mongo/db/commands/parallel_collection_scan.cpp @@ -71,9 +71,12 @@ namespace mongo { return Status(ErrorCodes::Unauthorized, "Unauthorized"); } - virtual bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int options, - string& errmsg, BSONObjBuilder& result, - bool fromRepl = false ) { + virtual bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int options, + string& errmsg, + BSONObjBuilder& result) { NamespaceString ns( dbname, cmdObj[name].String() ); diff --git a/src/mongo/db/commands/parameters.cpp b/src/mongo/db/commands/parameters.cpp index 5ee17f6c962..c9048ee54c2 100644 --- a/src/mongo/db/commands/parameters.cpp +++ b/src/mongo/db/commands/parameters.cpp @@ -80,7 +80,12 @@ namespace mongo { appendParameterNames( help ); help << "{ getParameter:'*' } to get everything\n"; } - bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { + bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { bool all = *cmdObj.firstElement().valuestrsafe() == '*'; int before = result.len(); @@ -118,7 +123,12 @@ namespace mongo { help << "{ setParameter:1, : }\n"; appendParameterNames( help ); } - bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { + bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { int numSet = 0; bool found = false; diff --git a/src/mongo/db/commands/pipeline_command.cpp b/src/mongo/db/commands/pipeline_command.cpp index a67620e6343..f94eec9d11d 100644 --- a/src/mongo/db/commands/pipeline_command.cpp +++ b/src/mongo/db/commands/pipeline_command.cpp @@ -180,8 +180,12 @@ namespace mongo { Pipeline::addRequiredPrivileges(this, dbname, cmdObj, out); } - virtual bool run(OperationContext* txn, const string &db, BSONObj &cmdObj, int options, - string &errmsg, BSONObjBuilder &result, bool fromRepl) { + virtual bool run(OperationContext* txn, + const string &db, + BSONObj &cmdObj, + int options, + string &errmsg, + BSONObjBuilder &result) { NamespaceString nss(parseNs(db, cmdObj)); if (nss.coll().empty()) { errmsg = "missing collection name"; diff --git a/src/mongo/db/commands/plan_cache_commands.cpp b/src/mongo/db/commands/plan_cache_commands.cpp index 9098299c800..0f7003e3dd9 100644 --- a/src/mongo/db/commands/plan_cache_commands.cpp +++ b/src/mongo/db/commands/plan_cache_commands.cpp @@ -124,8 +124,12 @@ namespace mongo { helpText(helpText), actionType(actionType) { } - bool PlanCacheCommand::run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int options, - string& errmsg, BSONObjBuilder& result, bool fromRepl) { + bool PlanCacheCommand::run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int options, + string& errmsg, + BSONObjBuilder& result) { string ns = parseNs(dbname, cmdObj); Status status = runPlanCacheCommand(txn, ns, cmdObj, &result); diff --git a/src/mongo/db/commands/plan_cache_commands.h b/src/mongo/db/commands/plan_cache_commands.h index 34660d9a48b..05b7c5969a8 100644 --- a/src/mongo/db/commands/plan_cache_commands.h +++ b/src/mongo/db/commands/plan_cache_commands.h @@ -58,8 +58,12 @@ namespace mongo { * implement plan cache command functionality. */ - bool run(OperationContext* txn, const std::string& dbname, BSONObj& cmdObj, int options, - std::string& errmsg, BSONObjBuilder& result, bool fromRepl); + bool run(OperationContext* txn, + const std::string& dbname, + BSONObj& cmdObj, + int options, + std::string& errmsg, + BSONObjBuilder& result); virtual bool isWriteCommandForConfigServer() const; diff --git a/src/mongo/db/commands/rename_collection.cpp b/src/mongo/db/commands/rename_collection.cpp index 2cc098bf621..91d7ac3254f 100644 --- a/src/mongo/db/commands/rename_collection.cpp +++ b/src/mongo/db/commands/rename_collection.cpp @@ -112,9 +112,7 @@ namespace mongo { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { - invariant(!fromRepl == txn->writesAreReplicated()); + BSONObjBuilder& result) { string source = cmdObj.getStringField( name.c_str() ); string target = cmdObj.getStringField( "to" ); @@ -145,18 +143,16 @@ namespace mongo { return false; } - if (!fromRepl) { // If it got through on the master, need to allow it here too - Status sourceStatus = userAllowedWriteNS(source); - if (!sourceStatus.isOK()) { - errmsg = "error with source namespace: " + sourceStatus.reason(); - return false; - } + Status sourceStatus = userAllowedWriteNS(source); + if (!sourceStatus.isOK()) { + errmsg = "error with source namespace: " + sourceStatus.reason(); + return false; + } - Status targetStatus = userAllowedWriteNS(target); - if (!targetStatus.isOK()) { - errmsg = "error with target namespace: " + targetStatus.reason(); - return false; - } + Status targetStatus = userAllowedWriteNS(target); + if (!targetStatus.isOK()) { + errmsg = "error with target namespace: " + targetStatus.reason(); + return false; } if (NamespaceString(source).coll() == "system.indexes" diff --git a/src/mongo/db/commands/repair_cursor.cpp b/src/mongo/db/commands/repair_cursor.cpp index cc2cf8d183b..1c7c653081b 100644 --- a/src/mongo/db/commands/repair_cursor.cpp +++ b/src/mongo/db/commands/repair_cursor.cpp @@ -59,9 +59,12 @@ namespace mongo { return Status(ErrorCodes::Unauthorized, "Unauthorized"); } - virtual bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int options, - string& errmsg, BSONObjBuilder& result, - bool fromRepl = false ) { + virtual bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int options, + string& errmsg, + BSONObjBuilder& result) { NamespaceString ns(parseNs(dbname, cmdObj)); diff --git a/src/mongo/db/commands/server_status.cpp b/src/mongo/db/commands/server_status.cpp index 5b3973753b3..d2bf917f6c4 100644 --- a/src/mongo/db/commands/server_status.cpp +++ b/src/mongo/db/commands/server_status.cpp @@ -81,7 +81,12 @@ namespace mongo { actions.addAction(ActionType::serverStatus); out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); } - bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { _runCalled = true; diff --git a/src/mongo/db/commands/test_commands.cpp b/src/mongo/db/commands/test_commands.cpp index 6ab83549325..e0eeb67c365 100644 --- a/src/mongo/db/commands/test_commands.cpp +++ b/src/mongo/db/commands/test_commands.cpp @@ -67,7 +67,12 @@ namespace mongo { virtual void help( stringstream &help ) const { help << "internal. for testing only."; } - virtual bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + virtual bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { string coll = cmdObj[ "godinsert" ].valuestrsafe(); log() << "test only command godinsert invoked coll:" << coll << endl; uassert( 13049, "godinsert must specify a collection", !coll.empty() ); @@ -113,7 +118,12 @@ namespace mongo { const BSONObj& cmdObj, std::vector* out) {} CmdSleep() : Command("sleep") { } - bool run(OperationContext* txn, const string& ns, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + bool run(OperationContext* txn, + const string& ns, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { log() << "test only command sleep invoked" << endl; long long millis = 10 * 1000; @@ -155,7 +165,12 @@ namespace mongo { virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, std::vector* out) {} - virtual bool run(OperationContext* txn, const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + virtual bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { string coll = cmdObj[ "captrunc" ].valuestrsafe(); uassert( 13416, "captrunc must specify a collection", !coll.empty() ); NamespaceString nss( dbname, coll ); @@ -191,7 +206,6 @@ namespace mongo { EmptyCapped() : Command( "emptycapped" ) {} virtual bool slaveOk() const { return false; } virtual bool isWriteCommandForConfigServer() const { return false; } - virtual bool logTheOp() { return true; } // No auth needed because it only works when enabled via command line. virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, @@ -202,8 +216,7 @@ namespace mongo { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { const std::string ns = parseNsCollectionRequired(dbname, cmdObj); return appendCommandStatus(result, emptyCapped(txn, NamespaceString(ns))); diff --git a/src/mongo/db/commands/touch.cpp b/src/mongo/db/commands/touch.cpp index 2288d54551d..1b71e55ab53 100644 --- a/src/mongo/db/commands/touch.cpp +++ b/src/mongo/db/commands/touch.cpp @@ -81,8 +81,7 @@ namespace mongo { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { const std::string ns = parseNsCollectionRequired(dbname, cmdObj); const NamespaceString nss(ns); diff --git a/src/mongo/db/commands/user_management_commands.cpp b/src/mongo/db/commands/user_management_commands.cpp index 366b1760f69..d0813279a0f 100644 --- a/src/mongo/db/commands/user_management_commands.cpp +++ b/src/mongo/db/commands/user_management_commands.cpp @@ -359,8 +359,7 @@ namespace mongo { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { auth::CreateOrUpdateUserArgs args; Status status = auth::parseCreateOrUpdateUserCommands(cmdObj, "createUser", @@ -568,8 +567,7 @@ namespace mongo { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { auth::CreateOrUpdateUserArgs args; Status status = auth::parseCreateOrUpdateUserCommands(cmdObj, "updateUser", @@ -712,8 +710,7 @@ namespace mongo { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { AuthorizationManager* authzManager = getGlobalAuthorizationManager(); AuthzDocumentsUpdateGuard updateGuard(authzManager); if (!updateGuard.tryLock("Drop user")) { @@ -799,8 +796,7 @@ namespace mongo { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { AuthorizationManager* authzManager = getGlobalAuthorizationManager(); AuthzDocumentsUpdateGuard updateGuard(authzManager); if (!updateGuard.tryLock("Drop all users from database")) { @@ -882,8 +878,7 @@ namespace mongo { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { AuthorizationManager* authzManager = getGlobalAuthorizationManager(); AuthzDocumentsUpdateGuard updateGuard(authzManager); if (!updateGuard.tryLock("Grant roles to user")) { @@ -980,8 +975,7 @@ namespace mongo { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { AuthorizationManager* authzManager = getGlobalAuthorizationManager(); AuthzDocumentsUpdateGuard updateGuard(authzManager); if (!updateGuard.tryLock("Revoke roles from user")) { @@ -1096,8 +1090,7 @@ namespace mongo { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { auth::UsersInfoArgs args; Status status = auth::parseUsersInfoCommand(cmdObj, dbname, &args); @@ -1231,8 +1224,7 @@ namespace mongo { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { auth::CreateOrUpdateRoleArgs args; Status status = auth::parseCreateOrUpdateRoleCommands(cmdObj, "createRole", @@ -1377,8 +1369,7 @@ namespace mongo { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { auth::CreateOrUpdateRoleArgs args; Status status = auth::parseCreateOrUpdateRoleCommands(cmdObj, "updateRole", @@ -1499,8 +1490,7 @@ namespace mongo { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { AuthorizationManager* authzManager = getGlobalAuthorizationManager(); AuthzDocumentsUpdateGuard updateGuard(authzManager); if (!updateGuard.tryLock("Grant privileges to role")) { @@ -1636,8 +1626,7 @@ namespace mongo { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { AuthorizationManager* authzManager = getGlobalAuthorizationManager(); AuthzDocumentsUpdateGuard updateGuard(authzManager); if (!updateGuard.tryLock("Revoke privileges from role")) { @@ -1774,8 +1763,7 @@ namespace mongo { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { std::string roleNameString; std::vector rolesToAdd; BSONObj writeConcern; @@ -1894,8 +1882,7 @@ namespace mongo { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { AuthorizationManager* authzManager = getGlobalAuthorizationManager(); AuthzDocumentsUpdateGuard updateGuard(authzManager); if (!updateGuard.tryLock("Revoke roles from role")) { @@ -2014,8 +2001,7 @@ namespace mongo { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { AuthorizationManager* authzManager = getGlobalAuthorizationManager(); AuthzDocumentsUpdateGuard updateGuard(authzManager); if (!updateGuard.tryLock("Drop role")) { @@ -2185,8 +2171,7 @@ namespace mongo { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { BSONObj writeConcern; Status status = auth::parseDropAllRolesFromDatabaseCommand(cmdObj, dbname, @@ -2343,8 +2328,7 @@ namespace mongo { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { auth::RolesInfoArgs args; Status status = auth::parseRolesInfoCommand(cmdObj, dbname, &args); @@ -2424,8 +2408,7 @@ namespace mongo { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { AuthorizationManager* authzManager = getGlobalAuthorizationManager(); authzManager->invalidateUserCache(); @@ -2469,8 +2452,7 @@ namespace mongo { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { AuthorizationManager* authzManager = getGlobalAuthorizationManager(); result.append("cacheGeneration", authzManager->getCacheGeneration()); @@ -2911,8 +2893,7 @@ namespace mongo { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { auth::MergeAuthzCollectionsArgs args; Status status = auth::parseMergeAuthzCollectionsCommand(cmdObj, &args); diff --git a/src/mongo/db/commands/validate.cpp b/src/mongo/db/commands/validate.cpp index f8509b394f3..5fc7a871de0 100644 --- a/src/mongo/db/commands/validate.cpp +++ b/src/mongo/db/commands/validate.cpp @@ -66,7 +66,12 @@ namespace mongo { } //{ validate: "collectionnamewithoutthedbpart" [, scandata: ] [, full: } */ - bool run(OperationContext* txn, const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { + bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { string ns = dbname + "." + cmdObj.firstElement().valuestrsafe(); NamespaceString ns_string(ns); diff --git a/src/mongo/db/commands/write_commands/batch_executor.cpp b/src/mongo/db/commands/write_commands/batch_executor.cpp index 010f44deb04..72bdb1fc144 100644 --- a/src/mongo/db/commands/write_commands/batch_executor.cpp +++ b/src/mongo/db/commands/write_commands/batch_executor.cpp @@ -1238,8 +1238,7 @@ namespace mongo { cmd, 0, errmsg, - resultBuilder, - false /* fromrepl */); + resultBuilder); Command::appendCommandStatus(resultBuilder, success, errmsg); BSONObj cmdResult = resultBuilder.done(); uassertStatusOK(Command::getStatusFromCommandResult(cmdResult)); diff --git a/src/mongo/db/commands/write_commands/write_commands.cpp b/src/mongo/db/commands/write_commands/write_commands.cpp index 0fdecdf7786..d6d6d7ff137 100644 --- a/src/mongo/db/commands/write_commands/write_commands.cpp +++ b/src/mongo/db/commands/write_commands/write_commands.cpp @@ -118,12 +118,9 @@ namespace mongo { BSONObj& cmdObj, int options, string& errMsg, - BSONObjBuilder& result, - bool fromRepl) { - invariant(!fromRepl == txn->writesAreReplicated()); - - // Can't be run on secondaries (logTheOp() == false, slaveOk() == false). - dassert( !fromRepl ); + BSONObjBuilder& result) { + // Can't be run on secondaries. + dassert(txn->writesAreReplicated()); BatchedCommandRequest request( _writeType ); BatchedCommandResponse response; diff --git a/src/mongo/db/commands/write_commands/write_commands.h b/src/mongo/db/commands/write_commands/write_commands.h index 1ea34cb77e7..cbb2db6cac6 100644 --- a/src/mongo/db/commands/write_commands/write_commands.h +++ b/src/mongo/db/commands/write_commands/write_commands.h @@ -78,8 +78,7 @@ namespace mongo { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl); + BSONObjBuilder& result); // Write commands can be explained. virtual Status explain(OperationContext* txn, diff --git a/src/mongo/db/commands/writeback_compatibility_shim.cpp b/src/mongo/db/commands/writeback_compatibility_shim.cpp index 63bb3ba2718..99feccfad58 100644 --- a/src/mongo/db/commands/writeback_compatibility_shim.cpp +++ b/src/mongo/db/commands/writeback_compatibility_shim.cpp @@ -79,7 +79,11 @@ namespace mongo { } virtual bool run(OperationContext* opCtx, - const string&, BSONObj&, int, string&, BSONObjBuilder& result, bool) { + const string&, + BSONObj&, + int, + string&, + BSONObjBuilder& result) { string errMsg = stream() << "Writeback functionality is no longer present in v3.0 mongod, " diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp index 40eb29ed6dc..ecd5d00df21 100644 --- a/src/mongo/db/dbcommands.cpp +++ b/src/mongo/db/dbcommands.cpp @@ -51,6 +51,7 @@ #include "mongo/db/catalog/coll_mod.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/collection_catalog_entry.h" +#include "mongo/db/catalog/create_collection.h" #include "mongo/db/catalog/drop_collection.h" #include "mongo/db/catalog/drop_database.h" #include "mongo/db/catalog/database_catalog_entry.h" @@ -105,7 +106,6 @@ namespace mongo { using std::string; using std::stringstream; - class CmdShutdownMongoD : public CmdShutdown { public: virtual void help(stringstream& help) const { @@ -122,10 +122,7 @@ namespace mongo { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { - - invariant(!fromRepl == txn->writesAreReplicated()); + BSONObjBuilder& result) { bool force = cmdObj.hasField("force") && cmdObj["force"].trueValue(); long long timeoutSecs = 0; @@ -175,8 +172,7 @@ namespace mongo { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { // disallow dropping the config database if (serverGlobalParams.configsvr && (dbname == "config")) { return appendCommandStatus(result, @@ -258,8 +254,12 @@ namespace mongo { return allKilledIndexes; } - bool run(OperationContext* txn, const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { - invariant(!fromRepl == txn->writesAreReplicated()); + bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { BSONElement e = cmdObj.firstElement(); if ( e.numberInt() != 1 ) { errmsg = "bad option"; @@ -347,10 +347,7 @@ namespace mongo { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { - invariant(!fromRepl == txn->writesAreReplicated()); - + BSONObjBuilder& result) { // Needs to be locked exclusively, because creates the system.profile collection // in the local database. ScopedTransaction transaction(txn, MODE_IX); @@ -406,7 +403,12 @@ namespace mongo { out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); } - bool run(OperationContext* txn, const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { const char* deprecationWarning = "CMD diagLogging is deprecated and will be removed in a future release"; warning() << deprecationWarning << startupWarningsLog; @@ -455,9 +457,7 @@ namespace mongo { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { - invariant(!fromRepl == txn->writesAreReplicated()); + BSONObjBuilder& result) { const std::string nsToDrop = parseNsCollectionRequired(dbname, cmdObj); if (nsToDrop.find('$') != string::npos) { @@ -522,57 +522,9 @@ namespace mongo { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { - invariant(!fromRepl == txn->writesAreReplicated()); - BSONObjIterator it(cmdObj); - - // Extract ns from first cmdObj element. - BSONElement firstElt = it.next(); - uassert(15888, - "must pass name of collection to create", - firstElt.valuestrsafe()[0] != '\0'); - - Status status = userAllowedWriteNS( dbname, firstElt.valuestr() ); - if ( !status.isOK() ) { - return appendCommandStatus( result, status ); - } - - const std::string ns = dbname + '.' + firstElt.valuestrsafe(); - - // Build options object from remaining cmdObj elements. - BSONObjBuilder optionsBuilder; - while (it.more()) { - optionsBuilder.append(it.next()); - } - - BSONObj options = optionsBuilder.obj(); - uassert(14832, - "specify size: when capped is true", - !options["capped"].trueValue() || options["size"].isNumber() || - options.hasField("$nExtents")); - - MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN { - ScopedTransaction transaction(txn, MODE_IX); - Lock::DBLock dbXLock(txn->lockState(), dbname, MODE_X); - OldClientContext ctx(txn, ns); - if (!fromRepl && - !repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(dbname)) { - return appendCommandStatus(result, Status(ErrorCodes::NotMaster, str::stream() - << "Not primary while creating collection " << ns)); - } - - WriteUnitOfWork wunit(txn); - - // Create collection. - status = userCreateNS(txn, ctx.db(), ns.c_str(), options); - if ( !status.isOK() ) { - return appendCommandStatus( result, status ); - } - - wunit.commit(); - } MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "create", ns); - return true; + BSONObjBuilder& result) { + return appendCommandStatus(result, + createCollection(txn, dbname, cmdObj)); } } cmdCreate; @@ -607,8 +559,12 @@ namespace mongo { out->push_back(Privilege(parseResourcePattern(dbname, cmdObj), ActionType::find)); } - bool run(OperationContext* txn, const string& dbname, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { - invariant(!fromRepl == txn->writesAreReplicated()); + bool run(OperationContext* txn, + const string& dbname, + BSONObj& jsobj, + int, + string& errmsg, + BSONObjBuilder& result) { const std::string ns = parseNs(dbname, jsobj); md5digest d; @@ -761,8 +717,12 @@ namespace mongo { out->push_back(Privilege(parseResourcePattern(dbname, cmdObj), actions)); } - bool run(OperationContext* txn, const string& dbname, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { - invariant(!fromRepl == txn->writesAreReplicated()); + bool run(OperationContext* txn, + const string& dbname, + BSONObj& jsobj, + int, + string& errmsg, + BSONObjBuilder& result) { Timer timer; string ns = jsobj.firstElement().String(); @@ -886,8 +846,12 @@ namespace mongo { out->push_back(Privilege(parseResourcePattern(dbname, cmdObj), actions)); } - bool run(OperationContext* txn, const string& dbname, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { - invariant(!fromRepl == txn->writesAreReplicated()); + bool run(OperationContext* txn, + const string& dbname, + BSONObj& jsobj, + int, + string& errmsg, + BSONObjBuilder& result) { int scale = 1; if ( jsobj["scale"].isNumber() ) { scale = jsobj["scale"].numberInt(); @@ -998,10 +962,7 @@ namespace mongo { BSONObj& jsobj, int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { - invariant(!fromRepl == txn->writesAreReplicated()); - + BSONObjBuilder& result) { const std::string ns = parseNsCollectionRequired(dbname, jsobj); return appendCommandStatus(result, collMod(txn, NamespaceString(ns), jsobj, &result)); @@ -1032,8 +993,12 @@ namespace mongo { out->push_back(Privilege(ResourcePattern::forDatabaseName(dbname), actions)); } - bool run(OperationContext* txn, const string& dbname, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { - invariant(!fromRepl == txn->writesAreReplicated()); + bool run(OperationContext* txn, + const string& dbname, + BSONObj& jsobj, + int, + string& errmsg, + BSONObjBuilder& result) { int scale = 1; if ( jsobj["scale"].isNumber() ) { scale = jsobj["scale"].numberInt(); @@ -1104,7 +1069,12 @@ namespace mongo { virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, std::vector* out) {} // No auth required - virtual bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + virtual bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { result << "you" << txn->getCurOp()->getRemoteString(); return true; } @@ -1130,8 +1100,7 @@ namespace mongo { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool) { + BSONObjBuilder& result) { result << "options" << QueryOption_AllSupported; return true; } @@ -1143,11 +1112,10 @@ namespace mongo { BSONObj& cmdObj, int queryOptions, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { try { - return c->run(txn, dbname, cmdObj, queryOptions, errmsg, result, fromRepl); + return c->run(txn, dbname, cmdObj, queryOptions, errmsg, result); } catch (const SendStaleConfigException& e) { LOG(1) << "command failed because of stale config, can retry" << causedBy(e); @@ -1240,8 +1208,7 @@ namespace mongo { int queryOptions, const char *cmdns, BSONObj& cmdObj, - BSONObjBuilder& result, - bool fromRepl ) { + BSONObjBuilder& result) { std::string dbname = nsToDatabase( cmdns ); scoped_ptr mmSetter; @@ -1285,7 +1252,10 @@ namespace mongo { parsedUserNames, parsedRoleNames); - Status status = _checkAuthorization(c, txn->getClient(), dbname, cmdObj, fromRepl); + Status status = _checkAuthorization(c, + txn->getClient(), + dbname, + cmdObj); if (!status.isOK()) { appendCommandStatus(result, status); return; @@ -1295,8 +1265,8 @@ namespace mongo { bool canRunHere = replCoord->canAcceptWritesForDatabase(dbname) || c->slaveOk() || - ( c->slaveOverrideOk() && ( queryOptions & QueryOption_SlaveOk ) ) || - fromRepl; + ( c->slaveOverrideOk() && ( queryOptions & QueryOption_SlaveOk ) ) || + !txn->writesAreReplicated(); if ( ! canRunHere ) { result.append( "note" , "from execCommand" ); @@ -1329,9 +1299,7 @@ namespace mongo { } if (c->shouldAffectCommandCounter()) { - // If !fromRepl, globalOpCounters need to be incremented. Otherwise, replOpCounters - // need to be incremented. - OpCounters* opCounters = fromRepl ? &replOpCounters : &globalOpCounters; + OpCounters* opCounters = &globalOpCounters; opCounters->gotCommand(); } @@ -1365,7 +1333,7 @@ namespace mongo { c->_commandsExecuted.increment(); - retval = _execCommand(txn, c, dbname, cmdObj, queryOptions, errmsg, result, fromRepl); + retval = _execCommand(txn, c, dbname, cmdObj, queryOptions, errmsg, result); if ( !retval ){ c->_commandsFailed.increment(); @@ -1396,7 +1364,7 @@ namespace mongo { BSONObj& _cmdobj, BufBuilder& b, BSONObjBuilder& anObjBuilder, - bool fromRepl, int queryOptions) { + int queryOptions) { string dbname = nsToDatabase( ns ); const char *p = strchr(ns, '.'); @@ -1439,7 +1407,12 @@ namespace mongo { if ( c ) { LOG(2) << "run command " << ns << ' ' << c->getRedactedCopyForLogging(_cmdobj); - Command::execCommand(txn, c, queryOptions, ns, jsobj, anObjBuilder, fromRepl); + Command::execCommand(txn, + c, + queryOptions, + ns, + jsobj, + anObjBuilder); } else { // In the absence of a Command object, no redaction is possible. Therefore @@ -1466,10 +1439,9 @@ namespace mongo { CurOp& curop, BufBuilder& b, BSONObjBuilder& anObjBuilder, - bool fromRepl, int queryOptions) { try { - return _runCommands(txn, ns, jsobj, b, anObjBuilder, fromRepl, queryOptions); + return _runCommands(txn, ns, jsobj, b, anObjBuilder, queryOptions); } catch (const SendStaleConfigException&){ throw; diff --git a/src/mongo/db/dbcommands_generic.cpp b/src/mongo/db/dbcommands_generic.cpp index 396ccbca7eb..fa640d0fa47 100644 --- a/src/mongo/db/dbcommands_generic.cpp +++ b/src/mongo/db/dbcommands_generic.cpp @@ -70,7 +70,6 @@ namespace mongo { using std::stringstream; using std::vector; - class CmdBuildInfo : public Command { public: CmdBuildInfo() : Command( "buildInfo", true, "buildinfo" ) {} @@ -89,8 +88,7 @@ namespace mongo { BSONObj& jsobj, int, // options std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { appendBuildInfo(result); return true; @@ -108,7 +106,12 @@ namespace mongo { virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, std::vector* out) {} // No auth required - virtual bool run(OperationContext* txn, const string& badns, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + virtual bool run(OperationContext* txn, + const string& badns, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { // IMPORTANT: Don't put anything in here that might lock db - including authentication return true; } @@ -123,7 +126,12 @@ namespace mongo { virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, std::vector* out) {} // No auth required - virtual bool run(OperationContext* txn, const string& ns, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + virtual bool run(OperationContext* txn, + const string& ns, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { if ( globalScriptEngine ) { BSONObjBuilder bb( result.subobjStart( "js" ) ); result.append( "utf8" , globalScriptEngine->utf8Ok() ); @@ -158,7 +166,12 @@ namespace mongo { actions.addAction(ActionType::hostInfo); out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); } - bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { ProcessInfo p; BSONObjBuilder bSys, bOs; @@ -195,7 +208,12 @@ namespace mongo { actions.addAction(ActionType::logRotate); out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); } - virtual bool run(OperationContext* txn, const string& ns, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + virtual bool run(OperationContext* txn, + const string& ns, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { bool didRotate = rotateLogs(serverGlobalParams.logRenameOnRotate); if (didRotate) logProcessDetailsForLogRotate(); @@ -214,7 +232,12 @@ namespace mongo { virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, std::vector* out) {} // No auth required - virtual bool run(OperationContext* txn, const string& ns, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + virtual bool run(OperationContext* txn, + const string& ns, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { BSONObjBuilder b( result.subobjStart( "commands" ) ); for ( CommandMap::const_iterator i=_commands->begin(); i!=_commands->end(); ++i ) { Command * c = i->second; @@ -305,7 +328,12 @@ namespace mongo { const BSONObj& cmdObj, std::vector* out) {} // No auth required CmdForceError() : Command("forceerror") {} - bool run(OperationContext* txn, const string& dbnamne, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + bool run(OperationContext* txn, + const string& dbnamne, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { setLastError(10038, "forced error"); return false; } @@ -329,7 +357,12 @@ namespace mongo { help << "{ getLog : '*' } OR { getLog : 'global' }"; } - virtual bool run(OperationContext* txn, const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + virtual bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { BSONElement val = cmdObj.firstElement(); if (val.type() != String) { return appendCommandStatus(result, Status(ErrorCodes::TypeMismatch, str::stream() @@ -383,7 +416,12 @@ namespace mongo { actions.addAction(ActionType::getCmdLineOpts); out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); } - virtual bool run(OperationContext* txn, const string&, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + virtual bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { result.append("argv", serverGlobalParams.argvArray); result.append("parsed", serverGlobalParams.parsedOpts); return true; diff --git a/src/mongo/db/dbdirectclient.cpp b/src/mongo/db/dbdirectclient.cpp index b20fdf07092..41b75377060 100644 --- a/src/mongo/db/dbdirectclient.cpp +++ b/src/mongo/db/dbdirectclient.cpp @@ -187,8 +187,7 @@ namespace mongo { std::string errmsg; BSONObjBuilder result; - bool fromRepl = false; - bool runRetval = countCmd->run(_txn, dbname, cmdObj, options, errmsg, result, fromRepl); + bool runRetval = countCmd->run(_txn, dbname, cmdObj, options, errmsg, result); if (!runRetval) { Command::appendCommandStatus(result, runRetval, errmsg); Status commandStatus = Command::getStatusFromCommandResult(result.obj()); diff --git a/src/mongo/db/dbeval.cpp b/src/mongo/db/dbeval.cpp index b0852a004b3..2bc695030c5 100644 --- a/src/mongo/db/dbeval.cpp +++ b/src/mongo/db/dbeval.cpp @@ -175,8 +175,7 @@ namespace { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { if (cmdObj["nolock"].trueValue()) { return dbEval(txn, dbname, cmdObj, result, errmsg); diff --git a/src/mongo/db/dbwebserver.cpp b/src/mongo/db/dbwebserver.cpp index d7066322b02..ef14455bcfa 100644 --- a/src/mongo/db/dbwebserver.cpp +++ b/src/mongo/db/dbwebserver.cpp @@ -166,7 +166,7 @@ namespace { string errmsg; BSONObjBuilder sub; - if (!c->run(txn, "admin.$cmd", co, 0, errmsg, sub, false)) + if (!c->run(txn, "admin.$cmd", co, 0, errmsg, sub)) buf.append(cmd, errmsg); else buf.append(cmd, sub.obj()); @@ -253,7 +253,7 @@ namespace { BSONObj cmdObj = BSON(cmd << 1); BSONObjBuilder result; - Command::execCommand(txn, c, 0, "admin.", cmdObj, result, false); + Command::execCommand(txn, c, 0, "admin.", cmdObj, result); responseCode = 200; diff --git a/src/mongo/db/driverHelpers.cpp b/src/mongo/db/driverHelpers.cpp index f3a5cdd05e7..77f04ee2860 100644 --- a/src/mongo/db/driverHelpers.cpp +++ b/src/mongo/db/driverHelpers.cpp @@ -67,7 +67,12 @@ namespace mongo { virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, std::vector* out) {} // No auth required - virtual bool run(OperationContext* txn, const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + virtual bool run(OperationContext* txn, + const string& , + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { if ( cmdObj.firstElement().type() != jstOID ) { errmsg = "not oid"; return false; diff --git a/src/mongo/db/exec/stagedebug_cmd.cpp b/src/mongo/db/exec/stagedebug_cmd.cpp index 0e2bf932edb..9db17d3d920 100644 --- a/src/mongo/db/exec/stagedebug_cmd.cpp +++ b/src/mongo/db/exec/stagedebug_cmd.cpp @@ -110,8 +110,12 @@ namespace mongo { // check needed. } - bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, - bool fromRepl) { + bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { BSONElement argElt = cmdObj["stageDebug"]; if (argElt.eoo() || !argElt.isABSONObj()) { return false; } BSONObj argObj = argElt.Obj(); diff --git a/src/mongo/db/exec/update.cpp b/src/mongo/db/exec/update.cpp index 0430202a241..2b37efb746c 100644 --- a/src/mongo/db/exec/update.cpp +++ b/src/mongo/db/exec/update.cpp @@ -247,7 +247,6 @@ namespace mongo { << " updatedFields: " << updatedFields << " immutableAndSingleValueFields.size:" << (immutableAndSingleValueFields ? immutableAndSingleValueFields->size() : 0) - << " fromRepl: " << opts.fromReplication << " validate:" << opts.enforceOkForStorage; // 1.) Loop through each updated field and validate for storage diff --git a/src/mongo/db/geo/haystack.cpp b/src/mongo/db/geo/haystack.cpp index 0998e610803..531595d8719 100644 --- a/src/mongo/db/geo/haystack.cpp +++ b/src/mongo/db/geo/haystack.cpp @@ -73,8 +73,12 @@ namespace mongo { out->push_back(Privilege(parseResourcePattern(dbname, cmdObj), actions)); } - bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, - string& errmsg, BSONObjBuilder& result, bool fromRepl) { + bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { const std::string ns = parseNsCollectionRequired(dbname, cmdObj); AutoGetCollectionForRead ctx(txn, ns); diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp index a1ddfc65817..4085ffbed55 100644 --- a/src/mongo/db/instance.cpp +++ b/src/mongo/db/instance.cpp @@ -241,7 +241,12 @@ namespace { bb.skip(sizeof(QueryResult::Value)); BSONObjBuilder cmdResBuf; - if (!runCommands(txn, queryMessage.ns, queryMessage.query, *op, bb, cmdResBuf, false, + if (!runCommands(txn, + queryMessage.ns, + queryMessage.query, + *op, + bb, + cmdResBuf, queryMessage.queryOptions)) { uasserted(13530, "bad or malformed command request?"); } @@ -1068,8 +1073,7 @@ namespace { 0, /* what should I use for query option? */ d.getns(), cmdObj, - resultBuilder, - false /* fromRepl */); + resultBuilder); uassertStatusOK(Command::getStatusFromCommandResult(resultBuilder.done())); } catch (const DBException& ex) { diff --git a/src/mongo/db/repl/master_slave.cpp b/src/mongo/db/repl/master_slave.cpp index 10f7eef2088..10497525c89 100644 --- a/src/mongo/db/repl/master_slave.cpp +++ b/src/mongo/db/repl/master_slave.cpp @@ -374,8 +374,7 @@ namespace repl { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { HandshakeArgs handshake; Status status = handshake.initialize(cmdObj); @@ -477,7 +476,6 @@ namespace repl { int errCode = 0; CloneOptions cloneOptions; cloneOptions.fromDB = db; - cloneOptions.logForRepl = false; cloneOptions.slaveOk = true; cloneOptions.useReplAuth = true; cloneOptions.snapshot = true; diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index b4bfd2376d1..08738f70da6 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -43,8 +43,16 @@ #include "mongo/db/auth/authorization_manager_global.h" #include "mongo/db/auth/privilege.h" #include "mongo/db/background.h" +#include "mongo/db/catalog/apply_ops.h" +#include "mongo/db/catalog/capped_utils.h" +#include "mongo/db/catalog/create_collection.h" +#include "mongo/db/catalog/coll_mod.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/collection_catalog_entry.h" +#include "mongo/db/catalog/drop_collection.h" +#include "mongo/db/catalog/drop_database.h" +#include "mongo/db/catalog/drop_indexes.h" +#include "mongo/db/catalog/rename_collection.h" #include "mongo/db/commands.h" #include "mongo/db/commands/dbhash.h" #include "mongo/db/concurrency/write_conflict_exception.h" @@ -440,17 +448,107 @@ namespace { // ------------------------------------- - // @param fromRepl false if from ApplyOpsCmd +namespace { + NamespaceString parseNs(const string& dbname, const BSONObj& cmdObj) { + BSONElement first = cmdObj.firstElement(); + uassert(28631, + "no collection name specified", + first.canonicalType() == canonicalizeBSONType(mongo::String) + && first.valuestrsize() > 0); + std::string coll = first.valuestr(); + return NamespaceString(NamespaceString(dbname).db().toString(), coll); + } + + using opApplyFn = stdx::function; + + std::map opsMap = { + {"create", + [](OperationContext* txn, const char* dbName, BSONObj& cmd) -> Status { + return createCollection(txn, NamespaceString(dbName).db().toString(), cmd); + } + }, + {"collMod", + [](OperationContext* txn, const char* dbName, BSONObj& cmd) -> Status { + BSONObjBuilder resultWeDontCareAbout; + return collMod(txn, parseNs(dbName, cmd), cmd, &resultWeDontCareAbout); + } + }, + {"dropDatabase", + [](OperationContext* txn, const char* dbName, BSONObj& cmd) -> Status { + return dropDatabase(txn, NamespaceString(dbName).db().toString()); + } + }, + {"drop", + [](OperationContext* txn, const char* dbName, BSONObj& cmd) -> Status { + BSONObjBuilder resultWeDontCareAbout; + return dropCollection(txn, parseNs(dbName, cmd), resultWeDontCareAbout); + } + }, + // deleteIndex(es) is deprecated but still works as of April 10, 2015 + {"deleteIndex", + [](OperationContext* txn, const char* dbName, BSONObj& cmd) -> Status { + BSONObjBuilder resultWeDontCareAbout; + return dropIndexes(txn, parseNs(dbName, cmd), cmd, &resultWeDontCareAbout); + } + }, + {"deleteIndexes", + [](OperationContext* txn, const char* dbName, BSONObj& cmd) -> Status { + BSONObjBuilder resultWeDontCareAbout; + return dropIndexes(txn, parseNs(dbName, cmd), cmd, &resultWeDontCareAbout); + } + }, + {"dropIndex", + [](OperationContext* txn, const char* dbName, BSONObj& cmd) -> Status { + BSONObjBuilder resultWeDontCareAbout; + return dropIndexes(txn, parseNs(dbName, cmd), cmd, &resultWeDontCareAbout); + } + }, + {"dropIndexes", + [](OperationContext* txn, const char* dbName, BSONObj& cmd) -> Status { + BSONObjBuilder resultWeDontCareAbout; + return dropIndexes(txn, parseNs(dbName, cmd), cmd, &resultWeDontCareAbout); + } + }, + {"renameCollection", + [](OperationContext* txn, const char* dbName, BSONObj& cmd) -> Status { + return renameCollection(txn, + NamespaceString(cmd.firstElement().valuestrsafe()), + NamespaceString(cmd["to"].valuestrsafe()), + cmd["stayTemp"].trueValue(), + cmd["dropTarget"].trueValue()); + } + }, + {"applyOps", + [](OperationContext* txn, const char* dbName, BSONObj& cmd) -> Status { + BSONObjBuilder resultWeDontCareAbout; + return applyOps(txn, dbName, cmd, &resultWeDontCareAbout); + } + }, + {"convertToCapped", + [](OperationContext* txn, const char* dbName, BSONObj& cmd) -> Status { + return convertToCapped(txn, + parseNs(dbName, cmd), + cmd["size"].number()); + } + }, + {"emptycapped", + [](OperationContext* txn, const char* dbName, BSONObj& cmd) -> Status { + return emptyCapped(txn, parseNs(dbName, cmd)); + } + }, + }; + +} // namespace + // @return failure status if an update should have happened and the document DNE. // See replset initial sync code. Status applyOperation_inlock(OperationContext* txn, Database* db, const BSONObj& op, - bool fromRepl, bool convertUpdateToUpsert) { LOG(3) << "applying op: " << op << endl; - OpCounters * opCounters = fromRepl ? &replOpCounters : &globalOpCounters; + OpCounters * opCounters = txn->writesAreReplicated() ? &globalOpCounters : &replOpCounters; const char *names[] = { "o", "ns", "op", "b", "o2" }; BSONElement fields[5]; @@ -618,18 +716,14 @@ namespace { verify( opType[1] == 'b' ); // "db" advertisement } else if ( *opType == 'c' ) { + // Applying commands in repl is done under Global W-lock, so it is safe to not + // perform the current DB checks after reacquiring the lock. + invariant(txn->lockState()->isW()); + bool done = false; - while (!done) { - BufBuilder bb; - BSONObjBuilder runCommandResult; - // Applying commands in repl is done under Global W-lock, so it is safe to not - // perform the current DB checks after reacquiring the lock. - invariant(txn->lockState()->isW()); - - _runCommands(txn, ns, o, bb, runCommandResult, true, 0); - // _runCommands takes care of adjusting opcounters for command counting. - Status status = Command::getStatusFromCommandResult(runCommandResult.done()); + while (!done) { + Status status = opsMap.find(o.firstElementFieldName())->second(txn, ns, o); switch (status.code()) { case ErrorCodes::WriteConflict: { // Need to throw this up to a higher level where it will be caught and the diff --git a/src/mongo/db/repl/oplog.h b/src/mongo/db/repl/oplog.h index f587ae074df..5d1477ff287 100644 --- a/src/mongo/db/repl/oplog.h +++ b/src/mongo/db/repl/oplog.h @@ -93,14 +93,12 @@ namespace repl { /** * take an op and apply locally * used for applying from an oplog - * @param fromRepl really from replication or for testing/internal/command/etc... * @param convertUpdateToUpsert convert some updates to upserts for idempotency reasons * Returns failure status if the op was an update that could not be applied. */ Status applyOperation_inlock(OperationContext* txn, Database* db, const BSONObj& op, - bool fromRepl = true, bool convertUpdateToUpsert = false); /** diff --git a/src/mongo/db/repl/replication_info.cpp b/src/mongo/db/repl/replication_info.cpp index dfba98f56aa..f4cd02426a2 100644 --- a/src/mongo/db/repl/replication_info.cpp +++ b/src/mongo/db/repl/replication_info.cpp @@ -206,7 +206,12 @@ namespace repl { const BSONObj& cmdObj, std::vector* out) {} // No auth required CmdIsMaster() : Command("isMaster", true, "ismaster") { } - virtual bool run(OperationContext* txn, const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool /*fromRepl*/) { + virtual bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { /* currently request to arbiter is (somewhat arbitrarily) an ismaster request that is not authenticated. */ diff --git a/src/mongo/db/repl/replset_commands.cpp b/src/mongo/db/repl/replset_commands.cpp index 6530c491902..9e187001513 100644 --- a/src/mongo/db/repl/replset_commands.cpp +++ b/src/mongo/db/repl/replset_commands.cpp @@ -94,7 +94,12 @@ namespace repl { return Status::OK(); } CmdReplSetTest() : ReplSetCommand("replSetTest") { } - virtual bool run(OperationContext* txn, const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + virtual bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { log() << "replSetTest command received: " << cmdObj.toString(); if( cmdObj.hasElement("forceInitialSyncFailure") ) { @@ -124,7 +129,12 @@ namespace repl { class CmdReplSetGetRBID : public ReplSetCommand { public: CmdReplSetGetRBID() : ReplSetCommand("replSetGetRBID") {} - virtual bool run(OperationContext* txn, const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + virtual bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { Status status = getGlobalReplicationCoordinator()->checkReplEnabledForCommand(&result); if (!status.isOK()) return appendCommandStatus(result, status); @@ -153,7 +163,12 @@ namespace repl { return Status::OK(); } CmdReplSetGetStatus() : ReplSetCommand("replSetGetStatus", true) { } - virtual bool run(OperationContext* txn, const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + virtual bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { if ( cmdObj["forShell"].trueValue() ) lastError.disableForCommand(); @@ -185,8 +200,12 @@ namespace repl { return Status::OK(); } CmdReplSetGetConfig() : ReplSetCommand("replSetGetConfig", true) { } - virtual bool run(OperationContext* txn, const string& , BSONObj& cmdObj, - int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + virtual bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { Status status = getGlobalReplicationCoordinator()->checkReplEnabledForCommand(&result); if (!status.isOK()) return appendCommandStatus(result, status); @@ -295,9 +314,9 @@ namespace { virtual bool run(OperationContext* txn, const string& , BSONObj& cmdObj, - int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + int, + string& errmsg, + BSONObjBuilder& result) { BSONObj configObj; if( cmdObj["replSetInitiate"].type() == Object ) { @@ -378,7 +397,12 @@ namespace { return Status::OK(); } CmdReplSetReconfig() : ReplSetCommand("replSetReconfig") { } - virtual bool run(OperationContext* txn, const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + virtual bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { Status status = getGlobalReplicationCoordinator()->checkReplEnabledForCommand(&result); if (!status.isOK()) { return appendCommandStatus(result, status); @@ -434,7 +458,12 @@ namespace { return Status::OK(); } CmdReplSetFreeze() : ReplSetCommand("replSetFreeze") { } - virtual bool run(OperationContext* txn, const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + virtual bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { Status status = getGlobalReplicationCoordinator()->checkReplEnabledForCommand(&result); if (!status.isOK()) return appendCommandStatus(result, status); @@ -466,7 +495,12 @@ namespace { return Status::OK(); } CmdReplSetStepDown() : ReplSetCommand("replSetStepDown") { } - virtual bool run(OperationContext* txn, const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + virtual bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { Status status = getGlobalReplicationCoordinator()->checkReplEnabledForCommand(&result); if (!status.isOK()) return appendCommandStatus(result, status); @@ -541,7 +575,12 @@ namespace { return Status::OK(); } CmdReplSetMaintenance() : ReplSetCommand("replSetMaintenance") { } - virtual bool run(OperationContext* txn, const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + virtual bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { Status status = getGlobalReplicationCoordinator()->checkReplEnabledForCommand(&result); if (!status.isOK()) return appendCommandStatus(result, status); @@ -571,12 +610,12 @@ namespace { return Status::OK(); } CmdReplSetSyncFrom() : ReplSetCommand("replSetSyncFrom") { } - virtual bool run(OperationContext* txn, const string&, + virtual bool run(OperationContext* txn, + const string&, BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { Status status = getGlobalReplicationCoordinator()->checkReplEnabledForCommand(&result); if (!status.isOK()) return appendCommandStatus(result, status); @@ -596,8 +635,12 @@ namespace { class CmdReplSetUpdatePosition: public ReplSetCommand { public: CmdReplSetUpdatePosition() : ReplSetCommand("replSetUpdatePosition") { } - virtual bool run(OperationContext* txn, const string& , BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, bool fromRepl) { + virtual bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { Status status = getGlobalReplicationCoordinator()->checkReplEnabledForCommand(&result); if (!status.isOK()) return appendCommandStatus(result, status); @@ -659,7 +702,12 @@ namespace { class CmdReplSetHeartbeat : public ReplSetCommand { public: CmdReplSetHeartbeat() : ReplSetCommand("replSetHeartbeat") { } - virtual bool run(OperationContext* txn, const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + virtual bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { MONGO_FAIL_POINT_BLOCK(rsDelayHeartbeatResponse, delay) { const BSONObj& data = delay.getData(); @@ -713,8 +761,7 @@ namespace { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { Status status = getGlobalReplicationCoordinator()->checkReplEnabledForCommand(&result); if (!status.isOK()) return appendCommandStatus(result, status); @@ -745,8 +792,7 @@ namespace { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { DEV log() << "received elect msg " << cmdObj.toString(); else LOG(2) << "received elect msg " << cmdObj.toString(); diff --git a/src/mongo/db/repl/resync.cpp b/src/mongo/db/repl/resync.cpp index 16e385c9b48..0daa1ef3197 100644 --- a/src/mongo/db/repl/resync.cpp +++ b/src/mongo/db/repl/resync.cpp @@ -68,8 +68,7 @@ namespace repl { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { ScopedTransaction transaction(txn, MODE_X); Lock::GlobalWrite globalWriteLock(txn->lockState()); diff --git a/src/mongo/db/repl/rs_initialsync.cpp b/src/mongo/db/repl/rs_initialsync.cpp index 69cef872dee..d85bef6b746 100644 --- a/src/mongo/db/repl/rs_initialsync.cpp +++ b/src/mongo/db/repl/rs_initialsync.cpp @@ -169,7 +169,6 @@ namespace { int errCode; CloneOptions options; options.fromDB = db; - options.logForRepl = false; options.slaveOk = true; options.useReplAuth = true; options.snapshot = false; diff --git a/src/mongo/db/repl/rs_rollback.cpp b/src/mongo/db/repl/rs_rollback.cpp index 82b1da7a5d5..ed92efd5785 100644 --- a/src/mongo/db/repl/rs_rollback.cpp +++ b/src/mongo/db/repl/rs_rollback.cpp @@ -378,7 +378,7 @@ namespace { uassert(15908, errmsg, tmpConn->connect(HostAndPort(host), errmsg) && replAuthenticate(tmpConn)); - return cloner.copyCollection(txn, ns, BSONObj(), errmsg, true, false, true, false); + return cloner.copyCollection(txn, ns, BSONObj(), errmsg, true, false, true); } void syncFixUp(OperationContext* txn, diff --git a/src/mongo/db/repl/sync_tail.cpp b/src/mongo/db/repl/sync_tail.cpp index fe173e5430d..5a997a32a09 100644 --- a/src/mongo/db/repl/sync_tail.cpp +++ b/src/mongo/db/repl/sync_tail.cpp @@ -199,8 +199,10 @@ namespace repl { // For non-initial-sync, we convert updates to upserts // to suppress errors when replaying oplog entries. + txn->setReplicatedWrites(false); + Status status = - applyOperation_inlock(txn, ctx.db(), op, true, convertUpdateToUpsert); + applyOperation_inlock(txn, ctx.db(), op, convertUpdateToUpsert); opsAppliedStats.increment(); return status.isOK(); } diff --git a/src/mongo/db/stats/top.cpp b/src/mongo/db/stats/top.cpp index 24cd4ef8e65..01bc0ab3da8 100644 --- a/src/mongo/db/stats/top.cpp +++ b/src/mongo/db/stats/top.cpp @@ -194,7 +194,12 @@ namespace mongo { actions.addAction(ActionType::top); out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); } - virtual bool run(OperationContext* txn, const string&, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + virtual bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { { BSONObjBuilder b( result.subobjStart( "totals" ) ); b.append( "note", "all times in microseconds" ); diff --git a/src/mongo/db/storage/mmap_v1/journal_latency_test_cmd.cpp b/src/mongo/db/storage/mmap_v1/journal_latency_test_cmd.cpp index 6f82110b5d3..bbabd11c179 100644 --- a/src/mongo/db/storage/mmap_v1/journal_latency_test_cmd.cpp +++ b/src/mongo/db/storage/mmap_v1/journal_latency_test_cmd.cpp @@ -76,7 +76,12 @@ namespace mongo { virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, std::vector* out) {} - bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { + bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { boost::filesystem::path p = dur::getJournalDir(); p /= "journalLatencyTest"; diff --git a/src/mongo/s/client/shard.cpp b/src/mongo/s/client/shard.cpp index 9f461ff187d..dc2c1ba9ec8 100644 --- a/src/mongo/s/client/shard.cpp +++ b/src/mongo/s/client/shard.cpp @@ -308,7 +308,12 @@ namespace mongo { actions.addAction(ActionType::getShardMap); out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); } - virtual bool run(OperationContext* txn, const string&, mongo::BSONObj&, int, std::string& errmsg , mongo::BSONObjBuilder& result, bool) { + virtual bool run(OperationContext* txn, + const string&, + mongo::BSONObj&, + int, + std::string& errmsg , + mongo::BSONObjBuilder& result) { return staticShardInfo.getShardMap( result , errmsg ); } } cmdGetShardMap; diff --git a/src/mongo/s/client/shard_connection.cpp b/src/mongo/s/client/shard_connection.cpp index aeac40d6eec..50fd2dfae74 100644 --- a/src/mongo/s/client/shard_connection.cpp +++ b/src/mongo/s/client/shard_connection.cpp @@ -107,8 +107,7 @@ namespace { mongo::BSONObj& cmdObj, int options, std::string& errmsg, - mongo::BSONObjBuilder& result, - bool fromRepl) { + mongo::BSONObjBuilder& result) { // Base pool info shardConnectionPool.appendInfo(result); diff --git a/src/mongo/s/commands/cluster_add_shard_cmd.cpp b/src/mongo/s/commands/cluster_add_shard_cmd.cpp index f7882d95863..a3d3933b968 100644 --- a/src/mongo/s/commands/cluster_add_shard_cmd.cpp +++ b/src/mongo/s/commands/cluster_add_shard_cmd.cpp @@ -79,8 +79,7 @@ namespace { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { // get replica set component hosts ConnectionString servers = ConnectionString::parse( diff --git a/src/mongo/s/commands/cluster_count_cmd.cpp b/src/mongo/s/commands/cluster_count_cmd.cpp index f4a367b807c..2ed5124da2a 100644 --- a/src/mongo/s/commands/cluster_count_cmd.cpp +++ b/src/mongo/s/commands/cluster_count_cmd.cpp @@ -100,8 +100,7 @@ namespace { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { long long skip = 0; diff --git a/src/mongo/s/commands/cluster_drop_database_cmd.cpp b/src/mongo/s/commands/cluster_drop_database_cmd.cpp index e701762c69f..0faec0443ec 100644 --- a/src/mongo/s/commands/cluster_drop_database_cmd.cpp +++ b/src/mongo/s/commands/cluster_drop_database_cmd.cpp @@ -75,8 +75,7 @@ namespace { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { // Disallow dropping the config database from mongos if (dbname == "config") { diff --git a/src/mongo/s/commands/cluster_enable_sharding_cmd.cpp b/src/mongo/s/commands/cluster_enable_sharding_cmd.cpp index f9fc4e23938..c32deffc98d 100644 --- a/src/mongo/s/commands/cluster_enable_sharding_cmd.cpp +++ b/src/mongo/s/commands/cluster_enable_sharding_cmd.cpp @@ -97,8 +97,7 @@ namespace { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { const std::string dbname = parseNs("", cmdObj); diff --git a/src/mongo/s/commands/cluster_explain_cmd.cpp b/src/mongo/s/commands/cluster_explain_cmd.cpp index e2289e048e7..4fa094affed 100644 --- a/src/mongo/s/commands/cluster_explain_cmd.cpp +++ b/src/mongo/s/commands/cluster_explain_cmd.cpp @@ -91,19 +91,12 @@ namespace mongo { return commToExplain->checkAuthForCommand(client, dbname, explainObj); } - virtual bool run(OperationContext* txn, const std::string& dbName, + virtual bool run(OperationContext* txn, + const std::string& dbName, BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { - - // Should never get explain commands issued from replication. - if (fromRepl) { - Status commandStat(ErrorCodes::IllegalOperation, - "explain command should not be from repl"); - return appendCommandStatus(result, commandStat); - } + BSONObjBuilder& result) { ExplainCommon::Verbosity verbosity; Status parseStatus = ExplainCommon::parseCmdBSON(cmdObj, &verbosity); diff --git a/src/mongo/s/commands/cluster_find_cmd.cpp b/src/mongo/s/commands/cluster_find_cmd.cpp index e1ddbf568ec..0ce83b267b9 100644 --- a/src/mongo/s/commands/cluster_find_cmd.cpp +++ b/src/mongo/s/commands/cluster_find_cmd.cpp @@ -127,8 +127,7 @@ namespace mongo { const std::string& dbname, BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { // Currently only explains of finds run through the find command. Queries that are not // explained use the legacy OP_QUERY path. diff --git a/src/mongo/s/commands/cluster_flush_router_config_cmd.cpp b/src/mongo/s/commands/cluster_flush_router_config_cmd.cpp index cdc3b0f7daf..19477622b64 100644 --- a/src/mongo/s/commands/cluster_flush_router_config_cmd.cpp +++ b/src/mongo/s/commands/cluster_flush_router_config_cmd.cpp @@ -69,8 +69,7 @@ namespace { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { grid.catalogCache()->invalidateAll(); diff --git a/src/mongo/s/commands/cluster_fsync_cmd.cpp b/src/mongo/s/commands/cluster_fsync_cmd.cpp index b75c56ea34f..d05fdf6b8a0 100644 --- a/src/mongo/s/commands/cluster_fsync_cmd.cpp +++ b/src/mongo/s/commands/cluster_fsync_cmd.cpp @@ -67,8 +67,7 @@ namespace { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { if (cmdObj["lock"].trueValue()) { errmsg = "can't do lock through mongos"; diff --git a/src/mongo/s/commands/cluster_get_last_error_cmd.cpp b/src/mongo/s/commands/cluster_get_last_error_cmd.cpp index 5ef065d8e4e..2ee08b3aab9 100644 --- a/src/mongo/s/commands/cluster_get_last_error_cmd.cpp +++ b/src/mongo/s/commands/cluster_get_last_error_cmd.cpp @@ -69,8 +69,7 @@ namespace { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { // Mongos GLE - finicky. // diff --git a/src/mongo/s/commands/cluster_get_prev_error_cmd.cpp b/src/mongo/s/commands/cluster_get_prev_error_cmd.cpp index bc97b4dbb86..5e04c0471ea 100644 --- a/src/mongo/s/commands/cluster_get_prev_error_cmd.cpp +++ b/src/mongo/s/commands/cluster_get_prev_error_cmd.cpp @@ -66,8 +66,7 @@ namespace { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { errmsg += "getpreverror not supported for sharded environments"; return false; diff --git a/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp b/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp index 48b8068201f..a8268520aa1 100644 --- a/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp +++ b/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp @@ -91,8 +91,7 @@ namespace { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { const NamespaceString nss(parseNs(dbname, cmdObj)); if (nss.size() == 0) { diff --git a/src/mongo/s/commands/cluster_index_filter_cmd.cpp b/src/mongo/s/commands/cluster_index_filter_cmd.cpp index 9115583c2a3..b2549aba733 100644 --- a/src/mongo/s/commands/cluster_index_filter_cmd.cpp +++ b/src/mongo/s/commands/cluster_index_filter_cmd.cpp @@ -87,8 +87,7 @@ namespace mongo { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl ); + BSONObjBuilder& result); public: @@ -113,8 +112,7 @@ namespace mongo { BSONObj& cmdObj, int options, std::string& errMsg, - BSONObjBuilder& result, - bool ) { + BSONObjBuilder& result) { const std::string fullns = parseNs(dbName, cmdObj); NamespaceString nss(fullns); diff --git a/src/mongo/s/commands/cluster_is_db_grid_cmd.cpp b/src/mongo/s/commands/cluster_is_db_grid_cmd.cpp index e84b079937b..d4c958582ac 100644 --- a/src/mongo/s/commands/cluster_is_db_grid_cmd.cpp +++ b/src/mongo/s/commands/cluster_is_db_grid_cmd.cpp @@ -58,8 +58,7 @@ namespace { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { result.append("isdbgrid", 1); result.append("hostname", getHostNameCached()); diff --git a/src/mongo/s/commands/cluster_is_master_cmd.cpp b/src/mongo/s/commands/cluster_is_master_cmd.cpp index 6bc41b14cc3..5f926811a27 100644 --- a/src/mongo/s/commands/cluster_is_master_cmd.cpp +++ b/src/mongo/s/commands/cluster_is_master_cmd.cpp @@ -63,8 +63,7 @@ namespace { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { result.appendBool("ismaster", true); result.append("msg", "isdbgrid"); diff --git a/src/mongo/s/commands/cluster_kill_op.cpp b/src/mongo/s/commands/cluster_kill_op.cpp index c782d4a8811..d007ced2099 100644 --- a/src/mongo/s/commands/cluster_kill_op.cpp +++ b/src/mongo/s/commands/cluster_kill_op.cpp @@ -73,8 +73,7 @@ namespace { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) final { + BSONObjBuilder& result) final { // The format of op is shardid:opid // This is different than the format passed to the mongod killOp command. diff --git a/src/mongo/s/commands/cluster_list_databases_cmd.cpp b/src/mongo/s/commands/cluster_list_databases_cmd.cpp index 8468c9e3cce..1f6af4cc5c0 100644 --- a/src/mongo/s/commands/cluster_list_databases_cmd.cpp +++ b/src/mongo/s/commands/cluster_list_databases_cmd.cpp @@ -84,8 +84,7 @@ namespace { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { vector shards; Shard::getAllShards(shards); diff --git a/src/mongo/s/commands/cluster_list_shards_cmd.cpp b/src/mongo/s/commands/cluster_list_shards_cmd.cpp index 8067a35f633..3cb365710e5 100644 --- a/src/mongo/s/commands/cluster_list_shards_cmd.cpp +++ b/src/mongo/s/commands/cluster_list_shards_cmd.cpp @@ -73,8 +73,7 @@ namespace { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { std::vector shards; Status status = grid.catalogManager()->getAllShards(&shards); diff --git a/src/mongo/s/commands/cluster_merge_chunks_cmd.cpp b/src/mongo/s/commands/cluster_merge_chunks_cmd.cpp index b7e1ae63723..34db493370e 100644 --- a/src/mongo/s/commands/cluster_merge_chunks_cmd.cpp +++ b/src/mongo/s/commands/cluster_merge_chunks_cmd.cpp @@ -96,8 +96,7 @@ namespace { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool ) { + BSONObjBuilder& result) { vector bounds; if ( !FieldParser::extract( cmdObj, boundsField, &bounds, &errmsg ) ) { diff --git a/src/mongo/s/commands/cluster_move_chunk_cmd.cpp b/src/mongo/s/commands/cluster_move_chunk_cmd.cpp index 646b29ea202..d3a2c65b9a2 100644 --- a/src/mongo/s/commands/cluster_move_chunk_cmd.cpp +++ b/src/mongo/s/commands/cluster_move_chunk_cmd.cpp @@ -105,8 +105,7 @@ namespace { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { ShardConnection::sync(); diff --git a/src/mongo/s/commands/cluster_move_primary_cmd.cpp b/src/mongo/s/commands/cluster_move_primary_cmd.cpp index ef050861532..407f032f5d3 100644 --- a/src/mongo/s/commands/cluster_move_primary_cmd.cpp +++ b/src/mongo/s/commands/cluster_move_primary_cmd.cpp @@ -98,8 +98,7 @@ namespace { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { const string dbname = parseNs("admin", cmdObj); diff --git a/src/mongo/s/commands/cluster_netstat_cmd.cpp b/src/mongo/s/commands/cluster_netstat_cmd.cpp index f5e15d55bb1..33411e246b8 100644 --- a/src/mongo/s/commands/cluster_netstat_cmd.cpp +++ b/src/mongo/s/commands/cluster_netstat_cmd.cpp @@ -67,8 +67,7 @@ namespace { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { result.append("configserver", configServer.getPrimary().getConnString()); result.append("isdbgrid", 1); diff --git a/src/mongo/s/commands/cluster_plan_cache_cmd.cpp b/src/mongo/s/commands/cluster_plan_cache_cmd.cpp index 718ab7dab3a..314314cdd51 100644 --- a/src/mongo/s/commands/cluster_plan_cache_cmd.cpp +++ b/src/mongo/s/commands/cluster_plan_cache_cmd.cpp @@ -86,8 +86,7 @@ namespace mongo { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl ); + BSONObjBuilder& result); public: @@ -114,8 +113,7 @@ namespace mongo { BSONObj& cmdObj, int options, std::string& errMsg, - BSONObjBuilder& result, - bool ) { + BSONObjBuilder& result) { const std::string fullns = parseNs(dbName, cmdObj); NamespaceString nss(fullns); diff --git a/src/mongo/s/commands/cluster_remove_shard_cmd.cpp b/src/mongo/s/commands/cluster_remove_shard_cmd.cpp index 418f438df9a..2b00a2403d9 100644 --- a/src/mongo/s/commands/cluster_remove_shard_cmd.cpp +++ b/src/mongo/s/commands/cluster_remove_shard_cmd.cpp @@ -85,8 +85,7 @@ namespace { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { const string target = cmdObj.firstElement().valuestrsafe(); diff --git a/src/mongo/s/commands/cluster_repl_set_get_status_cmd.cpp b/src/mongo/s/commands/cluster_repl_set_get_status_cmd.cpp index 81f34598115..bacb5da705e 100644 --- a/src/mongo/s/commands/cluster_repl_set_get_status_cmd.cpp +++ b/src/mongo/s/commands/cluster_repl_set_get_status_cmd.cpp @@ -69,8 +69,7 @@ namespace { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { if (cmdObj["forShell"].trueValue()) { lastError.disableForCommand(); diff --git a/src/mongo/s/commands/cluster_reset_error_cmd.cpp b/src/mongo/s/commands/cluster_reset_error_cmd.cpp index 9c5b7f271cc..182daedaa66 100644 --- a/src/mongo/s/commands/cluster_reset_error_cmd.cpp +++ b/src/mongo/s/commands/cluster_reset_error_cmd.cpp @@ -64,8 +64,7 @@ namespace { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { LastError* le = lastError.get(); if (le) { diff --git a/src/mongo/s/commands/cluster_shard_collection_cmd.cpp b/src/mongo/s/commands/cluster_shard_collection_cmd.cpp index 07ccd86d424..2f286e696b2 100644 --- a/src/mongo/s/commands/cluster_shard_collection_cmd.cpp +++ b/src/mongo/s/commands/cluster_shard_collection_cmd.cpp @@ -109,8 +109,7 @@ namespace { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { const string ns = parseNs(dbname, cmdObj); if (ns.size() == 0) { diff --git a/src/mongo/s/commands/cluster_shutdown_cmd.cpp b/src/mongo/s/commands/cluster_shutdown_cmd.cpp index 9b5a76e5df7..58fe1d47483 100644 --- a/src/mongo/s/commands/cluster_shutdown_cmd.cpp +++ b/src/mongo/s/commands/cluster_shutdown_cmd.cpp @@ -46,8 +46,7 @@ namespace { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { // Never returns shutdownHelper(); diff --git a/src/mongo/s/commands/cluster_split_collection_cmd.cpp b/src/mongo/s/commands/cluster_split_collection_cmd.cpp index d258ebff2ac..221dba6f492 100644 --- a/src/mongo/s/commands/cluster_split_collection_cmd.cpp +++ b/src/mongo/s/commands/cluster_split_collection_cmd.cpp @@ -103,8 +103,7 @@ namespace { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { ShardConnection::sync(); diff --git a/src/mongo/s/commands/cluster_whats_my_uri_cmd.cpp b/src/mongo/s/commands/cluster_whats_my_uri_cmd.cpp index 565d60e6272..ad4c957e598 100644 --- a/src/mongo/s/commands/cluster_whats_my_uri_cmd.cpp +++ b/src/mongo/s/commands/cluster_whats_my_uri_cmd.cpp @@ -63,8 +63,7 @@ namespace { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { result << "you" << cc().getRemote().toString(); return true; diff --git a/src/mongo/s/commands/cluster_write_cmd.cpp b/src/mongo/s/commands/cluster_write_cmd.cpp index 42a63c1a4b7..925a944eb4d 100644 --- a/src/mongo/s/commands/cluster_write_cmd.cpp +++ b/src/mongo/s/commands/cluster_write_cmd.cpp @@ -142,8 +142,7 @@ namespace { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { BatchedCommandRequest request(_writeType); BatchedCommandResponse response; diff --git a/src/mongo/s/commands/commands_public.cpp b/src/mongo/s/commands/commands_public.cpp index 24d08b5ccac..df708e756d7 100644 --- a/src/mongo/s/commands/commands_public.cpp +++ b/src/mongo/s/commands/commands_public.cpp @@ -229,8 +229,7 @@ namespace { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { const string fullns = parseNs(dbName, cmdObj); @@ -399,7 +398,12 @@ namespace { class ProfileCmd : public PublicGridCommand { public: ProfileCmd() : PublicGridCommand("profile") {} - virtual bool run(OperationContext* txn, const string& dbName , BSONObj& cmdObj, int options, string& errmsg, BSONObjBuilder& result, bool) { + virtual bool run(OperationContext* txn, + const string& dbName, + BSONObj& cmdObj, + int options, + string& errmsg, + BSONObjBuilder& result) { errmsg = "profile currently not supported via mongos"; return false; } @@ -556,8 +560,7 @@ namespace { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool) { + BSONObjBuilder& result) { auto status = grid.implicitCreateDb(dbName); if (!status.isOK()) { @@ -587,8 +590,7 @@ namespace { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { auto status = grid.catalogCache()->getDatabase(dbName); if (!status.isOK()) { @@ -647,7 +649,12 @@ namespace { virtual bool adminOnly() const { return true; } - bool run(OperationContext* txn, const string& dbName, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + bool run(OperationContext* txn, + const string& dbName, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { const string fullnsFrom = cmdObj.firstElement().valuestrsafe(); const string dbNameFrom = nsToDatabase(fullnsFrom); auto confFrom = uassertStatusOK(grid.catalogCache()->getDatabase(dbNameFrom)); @@ -683,10 +690,9 @@ namespace { bool run(OperationContext* txn, const string& dbName, BSONObj& cmdObj, - int options, + int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { const string todb = cmdObj.getStringField("todb"); uassert(ErrorCodes::EmptyFieldName, "missing todb argument", !todb.empty()); @@ -738,7 +744,13 @@ namespace { actions.addAction(ActionType::collStats); out->push_back(Privilege(parseResourcePattern(dbname, cmdObj), actions)); } - bool run(OperationContext* txn, const string& dbName , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + + bool run(OperationContext* txn, + const string& dbName, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { const string fullns = parseNs(dbName, cmdObj); auto conf = uassertStatusOK(grid.catalogCache()->getDatabase(dbName)); @@ -960,10 +972,9 @@ namespace { bool run(OperationContext* txn, const string& dbName, BSONObj& cmdObj, - int options, + int, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { const string ns = parseNsCollectionRequired(dbName, cmdObj); @@ -1055,7 +1066,12 @@ namespace { actions.addAction(ActionType::find); out->push_back(Privilege(parseResourcePattern(dbname, cmdObj), actions)); } - bool run(OperationContext* txn, const string& dbName, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + bool run(OperationContext* txn, + const string& dbName, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { const string fullns = parseNs(dbName, cmdObj); auto conf = uassertStatusOK(grid.catalogCache()->getDatabase(dbName)); @@ -1196,13 +1212,23 @@ namespace { } return Status::OK(); } - virtual bool run(OperationContext* txn, const string& dbName , BSONObj& cmdObj, int options, string& errmsg, BSONObjBuilder& result, bool) { + virtual bool run(OperationContext* txn, + const string& dbName, + BSONObj& cmdObj, + int options, + string& errmsg, + BSONObjBuilder& result) { string x = parseNs(dbName, cmdObj); if ( ! str::startsWith( x , dbName ) ) { errmsg = str::stream() << "doing a splitVector across dbs isn't supported via mongos"; return false; } - return NotAllowedOnShardedCollectionCmd::run( txn, dbName , cmdObj , options , errmsg, result, false ); + return NotAllowedOnShardedCollectionCmd::run(txn, + dbName, + cmdObj, + options, + errmsg, + result); } virtual std::string parseNs(const string& dbname, const BSONObj& cmdObj) const { return parseNsFullyQualified(dbname, cmdObj); @@ -1225,7 +1251,13 @@ namespace { actions.addAction(ActionType::find); out->push_back(Privilege(parseResourcePattern(dbname, cmdObj), actions)); } - bool run(OperationContext* txn, const string& dbName , BSONObj& cmdObj, int options, string& errmsg, BSONObjBuilder& result, bool) { + + bool run(OperationContext* txn, + const string& dbName , + BSONObj& cmdObj, + int options, + string& errmsg, + BSONObjBuilder& result) { const string fullns = parseNs(dbName, cmdObj); auto status = grid.catalogCache()->getDatabase(dbName); @@ -1301,7 +1333,12 @@ namespace { out->push_back(Privilege(parseResourcePattern(dbname, cmdObj), ActionType::find)); } - bool run(OperationContext* txn, const string& dbName , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + bool run(OperationContext* txn, + const string& dbName, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { const string fullns = parseNs(dbName, cmdObj); auto conf = uassertStatusOK(grid.catalogCache()->getDatabase(dbName)); @@ -1414,7 +1451,13 @@ namespace { actions.addAction(ActionType::find); out->push_back(Privilege(parseResourcePattern(dbname, cmdObj), actions)); } - bool run(OperationContext* txn, const string& dbName , BSONObj& cmdObj, int options, string& errmsg, BSONObjBuilder& result, bool) { + + bool run(OperationContext* txn, + const string& dbName, + BSONObj& cmdObj, + int options, + string& errmsg, + BSONObjBuilder& result) { const string fullns = parseNs(dbName, cmdObj); auto conf = uassertStatusOK(grid.catalogCache()->getDatabase(dbName)); @@ -1611,11 +1654,21 @@ namespace { } } - bool run(OperationContext* txn, const string& dbName , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + bool run(OperationContext* txn, + const string& dbName, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { return run( txn, dbName, cmdObj, errmsg, result, 0 ); } - bool run(OperationContext* txn, const string& dbName , BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, int retry ) { + bool run(OperationContext* txn, + const string& dbName, + BSONObj& cmdObj, + string& errmsg, + BSONObjBuilder& result, + int retry) { Timer t; const string collection = cmdObj.firstElement().valuestrsafe(); @@ -1980,7 +2033,7 @@ namespace { // applyOps can do pretty much anything, so require all privileges. RoleGraph::generateUniversalPrivileges(out); } - virtual bool run(OperationContext* txn, const string& dbName , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + virtual bool run(OperationContext* txn, const string& dbName , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result) { errmsg = "applyOps not allowed through mongos"; return false; } @@ -1997,7 +2050,12 @@ namespace { actions.addAction(ActionType::compact); out->push_back(Privilege(parseResourcePattern(dbname, cmdObj), actions)); } - virtual bool run(OperationContext* txn, const string& dbName , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + virtual bool run(OperationContext* txn, + const string& dbName, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { errmsg = "compact not allowed through mongos"; return false; } @@ -2012,12 +2070,12 @@ namespace { // $eval can do pretty much anything, so require all privileges. RoleGraph::generateUniversalPrivileges(out); } - virtual bool run(OperationContext* txn, const string& dbName, + virtual bool run(OperationContext* txn, + const string& dbName, BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool) { + BSONObjBuilder& result) { RARELY { warning() << "the eval command is deprecated" << startupWarningsLog; @@ -2047,9 +2105,12 @@ namespace { virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, std::vector* out); - virtual bool run(OperationContext* txn, const string &dbName , BSONObj &cmdObj, - int options, string &errmsg, - BSONObjBuilder &result, bool fromRepl); + virtual bool run(OperationContext* txn, + const string &dbName, + BSONObj &cmdObj, + int options, + string &errmsg, + BSONObjBuilder &result); private: DocumentSourceMergeCursors::CursorIds parseCursors( @@ -2107,9 +2168,7 @@ namespace { BSONObj &cmdObj, int options, string &errmsg, - BSONObjBuilder &result, - bool fromRepl) { - + BSONObjBuilder &result) { const string fullns = parseNs(dbName, cmdObj); intrusive_ptr pExpCtx = @@ -2465,12 +2524,12 @@ namespace { dbname); } - bool run(OperationContext* txn, const string& dbName, + bool run(OperationContext* txn, + const string& dbName, BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool) { + BSONObjBuilder& result) { auto status = grid.catalogCache()->getDatabase(dbName); if (!status.isOK()) { @@ -2509,8 +2568,7 @@ namespace { BSONObj& cmdObj, int options, string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { + BSONObjBuilder& result) { auto conf = uassertStatusOK(grid.catalogCache()->getDatabase(dbName)); bool retval = passthrough( conf, cmdObj, result ); @@ -2546,8 +2604,7 @@ namespace { BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, - bool) { + BSONObjBuilder& result) { result << "options" << QueryOption_AllSupportedForSharding; return true; } diff --git a/src/mongo/s/commands/run_on_all_shards_cmd.cpp b/src/mongo/s/commands/run_on_all_shards_cmd.cpp index 8029a60e77f..5d36639064e 100644 --- a/src/mongo/s/commands/run_on_all_shards_cmd.cpp +++ b/src/mongo/s/commands/run_on_all_shards_cmd.cpp @@ -75,8 +75,7 @@ namespace mongo { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& output, - bool fromRepl) { + BSONObjBuilder& output) { LOG(1) << "RunOnAllShardsCommand db: " << dbName << " cmd:" << cmdObj; std::set shards; diff --git a/src/mongo/s/commands/run_on_all_shards_cmd.h b/src/mongo/s/commands/run_on_all_shards_cmd.h index f84643d1513..8def03db5bf 100644 --- a/src/mongo/s/commands/run_on_all_shards_cmd.h +++ b/src/mongo/s/commands/run_on_all_shards_cmd.h @@ -84,8 +84,7 @@ namespace mongo { BSONObj& cmdObj, int options, std::string& errmsg, - BSONObjBuilder& output, - bool fromRepl) final; + BSONObjBuilder& output) final; private: bool _useShardConn; // use ShardConnection as opposed to ScopedDbConnection diff --git a/src/mongo/s/cursors.cpp b/src/mongo/s/cursors.cpp index 241299c80b0..dd339627668 100644 --- a/src/mongo/s/cursors.cpp +++ b/src/mongo/s/cursors.cpp @@ -502,7 +502,12 @@ namespace mongo { out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); } virtual bool isWriteCommandForConfigServer() const { return false; } - bool run(OperationContext* txn, const string&, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { + bool run(OperationContext* txn, + const string&, + BSONObj& jsobj, + int, + string& errmsg, + BSONObjBuilder& result) { cursorCache.appendInfo( result ); if ( jsobj["setTimeout"].isNumber() ) CursorCache::TIMEOUT = jsobj["setTimeout"].numberLong(); diff --git a/src/mongo/s/d_migrate.cpp b/src/mongo/s/d_migrate.cpp index f3886d4ed1c..5923b6e9e69 100644 --- a/src/mongo/s/d_migrate.cpp +++ b/src/mongo/s/d_migrate.cpp @@ -931,7 +931,12 @@ namespace mongo { actions.addAction(ActionType::internal); out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); } - bool run(OperationContext* txn, const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { return migrateFromStatus.transferMods(txn, errmsg, result); } } transferModsCommand; @@ -948,7 +953,12 @@ namespace mongo { actions.addAction(ActionType::internal); out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); } - bool run(OperationContext* txn, const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { return migrateFromStatus.clone(txn, errmsg, result); } } initialCloneCommand; @@ -1008,7 +1018,12 @@ namespace mongo { return parseNsFullyQualified(dbname, cmdObj); } - bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { // 1. Parse options // 2. Make sure my view is complete and lock the distributed lock to ensure shard // metadata stability. @@ -2688,7 +2703,12 @@ namespace mongo { actions.addAction(ActionType::internal); out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); } - bool run(OperationContext* txn, const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { // Active state of TO-side migrations (MigrateStatus) is serialized by distributed // collection lock. @@ -2843,7 +2863,12 @@ namespace mongo { actions.addAction(ActionType::internal); out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); } - bool run(OperationContext* txn, const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { migrateStatus.status( result ); return 1; } @@ -2861,7 +2886,12 @@ namespace mongo { actions.addAction(ActionType::internal); out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); } - bool run(OperationContext* txn, const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { bool ok = migrateStatus.startCommit(); migrateStatus.status( result ); return ok; @@ -2880,7 +2910,12 @@ namespace mongo { actions.addAction(ActionType::internal); out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); } - bool run(OperationContext* txn, const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { migrateStatus.abort(); migrateStatus.status( result ); return true; diff --git a/src/mongo/s/d_split.cpp b/src/mongo/s/d_split.cpp index ad36adf6392..e0167c9005e 100644 --- a/src/mongo/s/d_split.cpp +++ b/src/mongo/s/d_split.cpp @@ -87,7 +87,12 @@ namespace mongo { virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, std::vector* out) {} - bool run(OperationContext* txn, const string& dbname, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { + bool run(OperationContext* txn, + const string& dbname, + BSONObj& jsobj, + int, + string& errmsg, + BSONObjBuilder& result) { errmsg = "medianKey command no longer supported. Calling this indicates mismatch between mongo versions."; return false; } @@ -113,7 +118,12 @@ namespace mongo { return parseNsFullyQualified(dbname, cmdObj); } - bool run(OperationContext* txn, const string& dbname, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { + bool run(OperationContext* txn, + const string& dbname, + BSONObj& jsobj, + int, + string& errmsg, + BSONObjBuilder& result) { std::string ns = parseNs(dbname, jsobj); BSONObj keyPattern = jsobj.getObjectField( "keyPattern" ); @@ -255,7 +265,12 @@ namespace mongo { virtual std::string parseNs(const string& dbname, const BSONObj& cmdObj) const { return parseNsFullyQualified(dbname, cmdObj); } - bool run(OperationContext* txn, const string& dbname, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { + bool run(OperationContext* txn, + const string& dbname, + BSONObj& jsobj, + int, + string& errmsg, + BSONObjBuilder& result) { // // 1.a We'll parse the parameters in two steps. First, make sure the we can use the split index to get @@ -521,7 +536,12 @@ namespace mongo { virtual std::string parseNs(const std::string& dbname, const BSONObj& cmdObj) const { return parseNsFullyQualified(dbname, cmdObj); } - bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { + bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { // // 1. check whether parameters passed to splitChunk are sound diff --git a/src/mongo/s/d_state.cpp b/src/mongo/s/d_state.cpp index a25de628cfb..20f970d194e 100644 --- a/src/mongo/s/d_state.cpp +++ b/src/mongo/s/d_state.cpp @@ -923,7 +923,12 @@ namespace mongo { out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); } - bool run(OperationContext* txn, const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { ShardedConnectionInfo::reset(); return true; } @@ -989,7 +994,12 @@ namespace mongo { return checkConfigOrInit(txn, configdb, authoritative, errmsg, result, true); } - bool run(OperationContext* txn, const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { // Compatibility error for < v3.0 mongoses still active in the cluster // TODO: Remove post-3.0 @@ -1241,7 +1251,12 @@ namespace mongo { return parseNsFullyQualified(dbname, cmdObj); } - bool run(OperationContext* txn, const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { const string ns = cmdObj["getShardVersion"].valuestrsafe(); if (ns.size() == 0) { errmsg = "need to specify full namespace"; @@ -1295,7 +1310,12 @@ namespace mongo { out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); } - bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + bool run(OperationContext* txn, + const string& dbname, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { ScopedTransaction transaction(txn, MODE_IX); Lock::DBLock dbXLock(txn->lockState(), dbname, MODE_X); OldClientContext ctx(txn, dbname); diff --git a/src/mongo/s/distlock_test.cpp b/src/mongo/s/distlock_test.cpp index 957ffee505c..bff16905007 100644 --- a/src/mongo/s/distlock_test.cpp +++ b/src/mongo/s/distlock_test.cpp @@ -125,8 +125,12 @@ namespace mongo { } } - bool run(OperationContext* txn, const string&, BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, bool) { + bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { Timer t; DistributedLock lk(ConnectionString(cmdObj["host"].String(), ConnectionString::SYNC), "testdistlockwithsync", 0, 0); @@ -367,8 +371,12 @@ namespace mongo { return; } - bool run(OperationContext* txn, const string&, BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, bool) { + bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { Timer t; @@ -507,8 +515,12 @@ namespace mongo { const BSONObj& cmdObj, std::vector* out) {} - bool run(OperationContext* txn, const string&, BSONObj& cmdObj, int, string& errmsg, - BSONObjBuilder& result, bool) { + bool run(OperationContext* txn, + const string&, + BSONObj& cmdObj, + int, + string& errmsg, + BSONObjBuilder& result) { long long skew = (long long) number_field(cmdObj, "skew", 0); diff --git a/src/mongo/s/s_only.cpp b/src/mongo/s/s_only.cpp index 9b5aab2c495..e33d19a0653 100644 --- a/src/mongo/s/s_only.cpp +++ b/src/mongo/s/s_only.cpp @@ -111,9 +111,8 @@ namespace mongo { int queryOptions, const char *ns, BSONObj& cmdObj, - BSONObjBuilder& result, - bool fromRepl ) { - execCommandClientBasic(txn, c, *txn->getClient(), queryOptions, ns, cmdObj, result, fromRepl); + BSONObjBuilder& result) { + execCommandClientBasic(txn, c, *txn->getClient(), queryOptions, ns, cmdObj, result); } void Command::execCommandClientBasic(OperationContext* txn, @@ -122,8 +121,7 @@ namespace mongo { int queryOptions, const char *ns, BSONObj& cmdObj, - BSONObjBuilder& result, - bool fromRepl ) { + BSONObjBuilder& result) { std::string dbname = nsToDatabase(ns); if (cmdObj.getBoolField("help")) { @@ -136,7 +134,7 @@ namespace mongo { return; } - Status status = _checkAuthorization(c, &client, dbname, cmdObj, fromRepl); + Status status = _checkAuthorization(c, &client, dbname, cmdObj); if (!status.isOK()) { appendCommandStatus(result, status); return; @@ -147,7 +145,7 @@ namespace mongo { std::string errmsg; bool ok; try { - ok = c->run( txn, dbname , cmdObj, queryOptions, errmsg, result, false ); + ok = c->run(txn, dbname , cmdObj, queryOptions, errmsg, result); } catch (const DBException& e) { ok = false; @@ -191,7 +189,7 @@ namespace mongo { } OperationContext* noTxn = NULL; // mongos doesn't use transactions SERVER-13931 - execCommandClientBasic(noTxn, c, cc(), queryOptions, ns, jsobj, anObjBuilder, false); + execCommandClientBasic(noTxn, c, cc(), queryOptions, ns, jsobj, anObjBuilder); } } //namespace mongo -- cgit v1.2.1