diff options
author | Mathias Stearn <mathias@10gen.com> | 2014-04-29 15:23:45 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2014-04-30 10:48:16 -0400 |
commit | 36370def1e19eed5fcabd468253c5be0d2b22366 (patch) | |
tree | d26b73db74a8d2429179f70f438c931e001e985f | |
parent | 6d0f155cdd27b019b2f1ccc4b6b7e8e2c8271b54 (diff) | |
download | mongo-36370def1e19eed5fcabd468253c5be0d2b22366.tar.gz |
SERVER-13643 Kill Command::logTheOp and have Commands log their own ops
This is necessary to ensure that the lopOp is on the same Transaction as the
operation.
26 files changed, 61 insertions, 179 deletions
diff --git a/src/mongo/db/commands.h b/src/mongo/db/commands.h index e311b6b498f..a679dc3e5ff 100644 --- a/src/mongo/db/commands.h +++ b/src/mongo/db/commands.h @@ -110,13 +110,6 @@ namespace mutablebson { return false; } - /* Override and return true to if true,log the operation (logOp()) to the replication log. - (not done if fromRepl of course) - - Note if run() returns false, we do NOT log. - */ - virtual bool logTheOp() { return false; } - /** * Override and return fales if the command opcounters should not be incremented on * behalf of this command. diff --git a/src/mongo/db/commands/authentication_commands.cpp b/src/mongo/db/commands/authentication_commands.cpp index 2bfbe96cba0..532df4c015b 100644 --- a/src/mongo/db/commands/authentication_commands.cpp +++ b/src/mongo/db/commands/authentication_commands.cpp @@ -91,7 +91,6 @@ namespace mongo { _random(SecureRandom::create()) { } - virtual bool logTheOp() { return false; } virtual bool slaveOk() const { return true; } @@ -343,9 +342,6 @@ namespace mongo { class CmdLogout : public Command { public: - virtual bool logTheOp() { - return false; - } virtual bool slaveOk() const { return true; } diff --git a/src/mongo/db/commands/authentication_commands.h b/src/mongo/db/commands/authentication_commands.h index f5b7309036a..909857b3532 100644 --- a/src/mongo/db/commands/authentication_commands.h +++ b/src/mongo/db/commands/authentication_commands.h @@ -40,9 +40,6 @@ namespace mongo { public: static void disableAuthMechanism(std::string authMechanism); - virtual bool logTheOp() { - return false; - } virtual bool slaveOk() const { return true; } diff --git a/src/mongo/db/commands/collection_to_capped.cpp b/src/mongo/db/commands/collection_to_capped.cpp index 7b77f3615e1..2595cc4a1e4 100644 --- a/src/mongo/db/commands/collection_to_capped.cpp +++ b/src/mongo/db/commands/collection_to_capped.cpp @@ -172,10 +172,6 @@ namespace mongo { CmdConvertToCapped() : Command( "convertToCapped" ) {} virtual bool slaveOk() const { return false; } virtual bool isWriteCommandForConfigServer() const { return true; } - virtual bool logTheOp() { - // see CmdRenameCollection::logTheOp as to why this is best - return true; - } virtual void help( stringstream &help ) const { help << "{ convertToCapped:<fromCollectionName>, size:<sizeInBytes> }"; } @@ -243,7 +239,12 @@ namespace mongo { return appendCommandStatus( result, status ); status = db->renameCollection( &txn, longTmpName, longSource, false ); - return appendCommandStatus( result, status ); + if ( !status.isOK() ) + return appendCommandStatus( result, status ); + + if (!fromRepl) + logOp(&txn, "c",(dbname + ".$cmd").c_str(), jsobj); + return true; } } cmdConvertToCapped; diff --git a/src/mongo/db/commands/compact.cpp b/src/mongo/db/commands/compact.cpp index 3526c67dd8f..97508e62b5f 100644 --- a/src/mongo/db/commands/compact.cpp +++ b/src/mongo/db/commands/compact.cpp @@ -56,7 +56,6 @@ namespace mongo { virtual bool adminOnly() const { return false; } virtual bool slaveOk() const { return true; } virtual bool maintenanceMode() const { return true; } - virtual bool logTheOp() { return false; } virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, std::vector<Privilege>* out) { diff --git a/src/mongo/db/commands/connection_status.cpp b/src/mongo/db/commands/connection_status.cpp index a78f13aa15d..56172be081c 100644 --- a/src/mongo/db/commands/connection_status.cpp +++ b/src/mongo/db/commands/connection_status.cpp @@ -36,7 +36,6 @@ namespace mongo { class CmdConnectionStatus : public Command { public: CmdConnectionStatus() : Command("connectionStatus") {} - virtual bool logTheOp() { return false; } virtual bool slaveOk() const { return true; } virtual bool isWriteCommandForConfigServer() const { return false; } virtual void addRequiredPrivileges(const std::string& dbname, diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp index 50d3514e0cb..ae1a67705bb 100644 --- a/src/mongo/db/commands/create_indexes.cpp +++ b/src/mongo/db/commands/create_indexes.cpp @@ -49,7 +49,6 @@ namespace mongo { CmdCreateIndex() : Command( "createIndexes" ){} virtual bool isWriteCommandForConfigServer() const { return false; } - virtual bool logTheOp() { return false; } virtual bool slaveOk() const { return false; } // TODO: this could be made true... virtual Status checkAuthForCommand(ClientBasic* client, diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp index 1936a6e9e07..4be07264893 100644 --- a/src/mongo/db/commands/drop_indexes.cpp +++ b/src/mongo/db/commands/drop_indexes.cpp @@ -38,15 +38,14 @@ #include "mongo/db/catalog/index_catalog.h" #include "mongo/db/catalog/index_key_validate.h" #include "mongo/db/pdfile.h" +#include "mongo/db/repl/oplog.h" +#include "mongo/db/storage/mmap_v1/dur_transaction.h" namespace mongo { /* "dropIndexes" is now the preferred form - "deleteIndexes" deprecated */ class CmdDropIndexes : public Command { public: - virtual bool logTheOp() { - return true; - } virtual bool slaveOk() const { return false; } @@ -93,14 +92,25 @@ namespace mongo { } CmdDropIndexes() : Command("dropIndexes", false, "deleteIndexes") { } - bool run(const string& dbname, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& anObjBuilder, bool /*fromRepl*/) { + bool run(const string& dbname, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& anObjBuilder, bool fromRepl) { + Lock::DBWrite dbXLock(dbname); + DurTransaction txn; + bool ok = wrappedRun(&txn, dbname, jsobj, errmsg, anObjBuilder); + if (ok && !fromRepl) + logOp(&txn, "c",(dbname + ".$cmd").c_str(), jsobj); + return ok; + } + bool wrappedRun(TransactionExperiment* txn, + const string& dbname, + BSONObj& jsobj, + string& errmsg, + BSONObjBuilder& anObjBuilder) { BSONElement e = jsobj.firstElement(); const string toDeleteNs = dbname + '.' + e.valuestr(); if (!serverGlobalParams.quiet) { MONGO_TLOG(0) << "CMD: dropIndexes " << toDeleteNs << endl; } - Lock::DBWrite dbXLock(dbname); Client::Context ctx(toDeleteNs); Database* db = ctx.db(); @@ -181,7 +191,6 @@ namespace mongo { class CmdReIndex : public Command { public: - virtual bool logTheOp() { return false; } // only reindexes on the one node virtual bool slaveOk() const { return true; } // can reindex on a secondary virtual bool isWriteCommandForConfigServer() const { return true; } virtual void help( stringstream& help ) const { diff --git a/src/mongo/db/commands/find_and_modify.cpp b/src/mongo/db/commands/find_and_modify.cpp index 97a39390681..01663346e66 100644 --- a/src/mongo/db/commands/find_and_modify.cpp +++ b/src/mongo/db/commands/find_and_modify.cpp @@ -58,7 +58,6 @@ namespace mongo { } CmdFindAndModify() : Command("findAndModify", false, "findandmodify") { } - virtual bool logTheOp() { return false; } // the modifications will be logged directly virtual bool slaveOk() const { return false; } virtual bool isWriteCommandForConfigServer() const { return true; } virtual void addRequiredPrivileges(const std::string& dbname, diff --git a/src/mongo/db/commands/get_last_error.cpp b/src/mongo/db/commands/get_last_error.cpp index 06bf358730d..2775520ac94 100644 --- a/src/mongo/db/commands/get_last_error.cpp +++ b/src/mongo/db/commands/get_last_error.cpp @@ -47,9 +47,6 @@ namespace mongo { class CmdResetError : public Command { public: virtual bool isWriteCommandForConfigServer() const { return false; } - virtual bool logTheOp() { - return false; - } virtual bool slaveOk() const { return true; } @@ -79,7 +76,6 @@ namespace mongo { public: CmdGetLastError() : Command("getLastError", false, "getlasterror") { } virtual bool isWriteCommandForConfigServer() const { return false; } - virtual bool logTheOp() { return false; } virtual bool slaveOk() const { return true; } virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, @@ -256,9 +252,6 @@ namespace mongo { class CmdGetPrevError : public Command { public: virtual bool isWriteCommandForConfigServer() const { return false; } - virtual bool logTheOp() { - return false; - } virtual void help( stringstream& help ) const { help << "check for errors since last reseterror commandcal"; } diff --git a/src/mongo/db/commands/parallel_collection_scan.cpp b/src/mongo/db/commands/parallel_collection_scan.cpp index 4dacb66f1d9..587dcea13eb 100644 --- a/src/mongo/db/commands/parallel_collection_scan.cpp +++ b/src/mongo/db/commands/parallel_collection_scan.cpp @@ -149,7 +149,6 @@ namespace mongo { ParallelCollectionScanCmd() : Command( "parallelCollectionScan" ){} virtual bool isWriteCommandForConfigServer() const { return false; } - virtual bool logTheOp() { return false; } virtual bool slaveOk() const { return true; } virtual Status checkAuthForCommand(ClientBasic* client, diff --git a/src/mongo/db/commands/rename_collection.cpp b/src/mongo/db/commands/rename_collection.cpp index 6a4e0bd6f89..e7b2def57af 100644 --- a/src/mongo/db/commands/rename_collection.cpp +++ b/src/mongo/db/commands/rename_collection.cpp @@ -39,6 +39,7 @@ #include "mongo/db/instance.h" #include "mongo/db/namespace_string.h" #include "mongo/db/ops/insert.h" +#include "mongo/db/repl/oplog.h" #include "mongo/db/storage/mmap_v1/dur_transaction.h" namespace mongo { @@ -53,9 +54,6 @@ namespace mongo { return false; } virtual bool isWriteCommandForConfigServer() const { return true; } - virtual bool logTheOp() { - return true; // can't log steps when doing fast rename within a db, so always log the op rather than individual steps comprising it. - } virtual Status checkAuthForCommand(ClientBasic* client, const std::string& dbname, const BSONObj& cmdObj) { @@ -94,6 +92,19 @@ namespace mongo { } virtual bool run(const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { + Lock::GlobalWrite globalWriteLock; + DurTransaction txn; + bool ok = wrappedRun(&txn, dbname, cmdObj, errmsg, result, fromRepl); + if (ok && !fromRepl) + logOp(&txn, "c",(dbname + ".$cmd").c_str(), cmdObj); + return ok; + } + virtual bool wrappedRun(DurTransaction* txn, + const string& dbname, + BSONObj& cmdObj, + string& errmsg, + BSONObjBuilder& result, + bool fromRepl) { string source = cmdObj.getStringField( name.c_str() ); string target = cmdObj.getStringField( "to" ); @@ -127,9 +138,6 @@ namespace mongo { long long size = 0; std::vector<BSONObj> indexesInProg; - Lock::GlobalWrite globalWriteLock; - DurTransaction txn; - { Client::Context srcCtx( source ); Collection* sourceColl = srcCtx.db()->getCollection( source ); @@ -184,7 +192,7 @@ namespace mongo { return false; } - Status s = ctx.db()->dropCollection( &txn, target ); + Status s = ctx.db()->dropCollection( txn, target ); if ( !s.isOK() ) { errmsg = s.toString(); restoreIndexBuildsOnSource( indexesInProg, source ); @@ -195,7 +203,7 @@ namespace mongo { // If we are renaming in the same database, just // rename the namespace and we're done. if ( sourceDB == targetDB ) { - Status s = ctx.db()->renameCollection( &txn, source, target, + Status s = ctx.db()->renameCollection( txn, source, target, cmdObj["stayTemp"].trueValue() ); if ( !s.isOK() ) { errmsg = s.toString(); @@ -216,13 +224,13 @@ namespace mongo { options.cappedSize = size; options.setNoIdIndex(); - targetColl = ctx.db()->createCollection( &txn, target, options ); + targetColl = ctx.db()->createCollection( txn, target, options ); } else { CollectionOptions options; options.setNoIdIndex(); // No logOp necessary because the entire renameCollection command is one logOp. - targetColl = ctx.db()->createCollection( &txn, target, options ); + targetColl = ctx.db()->createCollection( txn, target, options ); } if ( !targetColl ) { errmsg = "Failed to create target collection."; @@ -255,7 +263,7 @@ namespace mongo { if ( !targetColl ) targetColl = ctx.db()->getCollection( target ); // No logOp necessary because the entire renameCollection command is one logOp. - Status s = targetColl->insertDocument( &txn, o, true ).getStatus(); + Status s = targetColl->insertDocument( txn, o, true ).getStatus(); if ( !s.isOK() ) { insertSuccessful = false; errmsg = s.toString(); @@ -267,7 +275,7 @@ namespace mongo { // If inserts were unsuccessful, drop the target collection and return false. if ( !insertSuccessful ) { Client::Context ctx( target ); - Status s = ctx.db()->dropCollection( &txn, target ); + Status s = ctx.db()->dropCollection( txn, target ); if ( !s.isOK() ) errmsg = s.toString(); restoreIndexBuildsOnSource( indexesInProg, source ); @@ -320,7 +328,7 @@ namespace mongo { // If indexes were unsuccessful, drop the target collection and return false. if ( !indexSuccessful ) { - Status s = ctx.db()->dropCollection( &txn, target ); + Status s = ctx.db()->dropCollection( txn, target ); if ( !s.isOK() ) errmsg = s.toString(); restoreIndexBuildsOnSource( indexesInProg, source ); @@ -331,7 +339,7 @@ namespace mongo { // Drop the source collection. { Client::Context srcCtx( source ); - Status s = srcCtx.db()->dropCollection( &txn, source ); + Status s = srcCtx.db()->dropCollection( txn, source ); if ( !s.isOK() ) { errmsg = s.toString(); restoreIndexBuildsOnSource( indexesInProg, source ); diff --git a/src/mongo/db/commands/shutdown.h b/src/mongo/db/commands/shutdown.h index f154d507c98..9311ac70f9b 100644 --- a/src/mongo/db/commands/shutdown.h +++ b/src/mongo/db/commands/shutdown.h @@ -40,9 +40,6 @@ namespace mongo { virtual bool requiresAuth() { return true; } virtual bool adminOnly() const { return true; } virtual bool localHostOnlyIfNoAuth(const BSONObj& cmdObj) { return true; } - virtual bool logTheOp() { - return false; - } virtual bool slaveOk() const { return true; } diff --git a/src/mongo/db/commands/test_commands.cpp b/src/mongo/db/commands/test_commands.cpp index 97cde83d144..9a89dadb61c 100644 --- a/src/mongo/db/commands/test_commands.cpp +++ b/src/mongo/db/commands/test_commands.cpp @@ -36,6 +36,7 @@ #include "mongo/db/kill_current_op.h" #include "mongo/db/query/internal_plans.h" #include "mongo/db/catalog/collection.h" +#include "mongo/db/repl/oplog.h" #include "mongo/db/storage/mmap_v1/dur_transaction.h" #include "mongo/db/structure/catalog/namespace_details.h" @@ -46,7 +47,6 @@ namespace mongo { public: GodInsert() : Command( "godinsert" ) { } virtual bool adminOnly() const { return false; } - virtual bool logTheOp() { return false; } virtual bool slaveOk() const { return true; } virtual bool isWriteCommandForConfigServer() const { return false; } // No auth needed because it only works when enabled via command line. @@ -85,7 +85,6 @@ namespace mongo { public: virtual bool isWriteCommandForConfigServer() const { return false; } virtual bool adminOnly() const { return true; } - virtual bool logTheOp() { return false; } virtual bool slaveOk() const { return true; } virtual void help( stringstream& help ) const { help << "internal testing command. Makes db block (in a read lock) for 100 seconds\n"; @@ -184,7 +183,7 @@ namespace mongo { return IndexBuilder::killMatchingIndexBuilds(db->getCollection(ns), criteria); } - virtual bool run(const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + virtual bool run(const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { string coll = cmdObj[ "emptycapped" ].valuestrsafe(); uassert( 13428, "emptycapped must specify a collection", !coll.empty() ); NamespaceString nss( dbname, coll ); @@ -203,6 +202,8 @@ namespace mongo { IndexBuilder::restoreIndexes(indexes); + if (!fromRepl) + logOp(&txn, "c",(dbname + ".$cmd").c_str(), cmdObj); return true; } }; diff --git a/src/mongo/db/commands/touch.cpp b/src/mongo/db/commands/touch.cpp index 83dc0aff893..1f3a64983dc 100644 --- a/src/mongo/db/commands/touch.cpp +++ b/src/mongo/db/commands/touch.cpp @@ -106,7 +106,6 @@ namespace mongo { virtual bool adminOnly() const { return false; } virtual bool slaveOk() const { return true; } virtual bool maintenanceMode() const { return true; } - virtual bool logTheOp() { return false; } virtual void help( stringstream& help ) const { help << "touch collection\n" "Page in all pages of memory containing every extent for the given collection\n" diff --git a/src/mongo/db/commands/user_management_commands.cpp b/src/mongo/db/commands/user_management_commands.cpp index 7a919fbcbfd..0b303ea205a 100644 --- a/src/mongo/db/commands/user_management_commands.cpp +++ b/src/mongo/db/commands/user_management_commands.cpp @@ -306,10 +306,6 @@ namespace mongo { CmdCreateUser() : Command("createUser") {} - virtual bool logTheOp() { - return false; - } - virtual bool slaveOk() const { return false; } @@ -470,10 +466,6 @@ namespace mongo { CmdUpdateUser() : Command("updateUser") {} - virtual bool logTheOp() { - return false; - } - virtual bool slaveOk() const { return false; } @@ -625,10 +617,6 @@ namespace mongo { CmdDropUser() : Command("dropUser") {} - virtual bool logTheOp() { - return false; - } - virtual bool slaveOk() const { return false; } @@ -725,10 +713,6 @@ namespace mongo { CmdDropAllUsersFromDatabase() : Command("dropAllUsersFromDatabase") {} - virtual bool logTheOp() { - return false; - } - virtual bool slaveOk() const { return false; } @@ -804,10 +788,6 @@ namespace mongo { CmdGrantRolesToUser() : Command("grantRolesToUser") {} - virtual bool logTheOp() { - return false; - } - virtual bool slaveOk() const { return false; } @@ -906,10 +886,6 @@ namespace mongo { CmdRevokeRolesFromUser() : Command("revokeRolesFromUser") {} - virtual bool logTheOp() { - return false; - } - virtual bool slaveOk() const { return false; } @@ -1006,10 +982,6 @@ namespace mongo { class CmdUsersInfo: public Command { public: - virtual bool logTheOp() { - return false; - } - virtual bool slaveOk() const { return false; } @@ -1163,10 +1135,6 @@ namespace mongo { CmdCreateRole() : Command("createRole") {} - virtual bool logTheOp() { - return false; - } - virtual bool slaveOk() const { return false; } @@ -1312,10 +1280,6 @@ namespace mongo { CmdUpdateRole() : Command("updateRole") {} - virtual bool logTheOp() { - return false; - } - virtual bool slaveOk() const { return false; } @@ -1446,10 +1410,6 @@ namespace mongo { CmdGrantPrivilegesToRole() : Command("grantPrivilegesToRole") {} - virtual bool logTheOp() { - return false; - } - virtual bool slaveOk() const { return false; } @@ -1586,10 +1546,6 @@ namespace mongo { CmdRevokePrivilegesFromRole() : Command("revokePrivilegesFromRole") {} - virtual bool logTheOp() { - return false; - } - virtual bool slaveOk() const { return false; } @@ -1728,10 +1684,6 @@ namespace mongo { CmdGrantRolesToRole() : Command("grantRolesToRole") {} - virtual bool logTheOp() { - return false; - } - virtual bool slaveOk() const { return false; } @@ -1851,10 +1803,6 @@ namespace mongo { CmdRevokeRolesFromRole() : Command("revokeRolesFromRole") {} - virtual bool logTheOp() { - return false; - } - virtual bool slaveOk() const { return false; } @@ -1968,10 +1916,6 @@ namespace mongo { CmdDropRole() : Command("dropRole") {} - virtual bool logTheOp() { - return false; - } - virtual bool slaveOk() const { return false; } @@ -2149,10 +2093,6 @@ namespace mongo { CmdDropAllRolesFromDatabase() : Command("dropAllRolesFromDatabase") {} - virtual bool logTheOp() { - return false; - } - virtual bool slaveOk() const { return false; } @@ -2283,10 +2223,6 @@ namespace mongo { class CmdRolesInfo: public Command { public: - virtual bool logTheOp() { - return false; - } - virtual bool slaveOk() const { return false; } @@ -2392,10 +2328,6 @@ namespace mongo { class CmdInvalidateUserCache: public Command { public: - virtual bool logTheOp() { - return false; - } - virtual bool slaveOk() const { return true; } @@ -2448,10 +2380,6 @@ namespace mongo { CmdMergeAuthzCollections() : Command("_mergeAuthzCollections") {} - virtual bool logTheOp() { - return false; - } - virtual bool slaveOk() const { return false; } diff --git a/src/mongo/db/commands/write_commands/write_commands.cpp b/src/mongo/db/commands/write_commands/write_commands.cpp index a4fa9ea917d..f64c1fa7545 100644 --- a/src/mongo/db/commands/write_commands/write_commands.cpp +++ b/src/mongo/db/commands/write_commands/write_commands.cpp @@ -77,9 +77,6 @@ namespace mongo { } } - // Write commands are fanned out in oplog as single writes. - bool WriteCmd::logTheOp() { return false; } - // Slaves can't perform writes. bool WriteCmd::slaveOk() const { return false; } diff --git a/src/mongo/db/commands/write_commands/write_commands.h b/src/mongo/db/commands/write_commands/write_commands.h index f5ecfa24434..f8fccacc439 100644 --- a/src/mongo/db/commands/write_commands/write_commands.h +++ b/src/mongo/db/commands/write_commands/write_commands.h @@ -61,8 +61,6 @@ namespace mongo { static void redactTooLongLog( mutablebson::Document* cmdObj, const StringData& fieldName ); private: - virtual bool logTheOp(); - virtual bool slaveOk() const; virtual bool isWriteCommandForConfigServer() const; diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp index a0ad3cec77b..a19f7146b6c 100644 --- a/src/mongo/db/dbcommands.cpp +++ b/src/mongo/db/dbcommands.cpp @@ -149,9 +149,6 @@ namespace mongo { class CmdDropDatabase : public Command { public: - virtual bool logTheOp() { - return true; - } virtual void help( stringstream& help ) const { help << "drop (delete) this database"; } @@ -212,26 +209,28 @@ namespace mongo { // this is suboptimal but syncDataAndTruncateJournal is called from dropDatabase, // and that may need a global lock. Lock::GlobalWrite lk; + Client::Context context(dbname); + DurTransaction txn; log() << "dropDatabase " << dbname << " starting" << endl; - Client::Context context(dbname); stopIndexBuilds(context.db(), cmdObj); dropDatabase(context.db()); log() << "dropDatabase " << dbname << " finished"; + + if (!fromRepl) + logOp(&txn, "c",(dbname + ".$cmd").c_str(), cmdObj); } result.append( "dropped" , dbname ); + return true; } } cmdDropDatabase; class CmdRepairDatabase : public Command { public: - virtual bool logTheOp() { - return false; - } virtual bool slaveOk() const { return true; } @@ -444,9 +443,6 @@ namespace mongo { class CmdDrop : public Command { public: CmdDrop() : Command("drop") { } - virtual bool logTheOp() { - return true; - } virtual bool slaveOk() const { return false; } @@ -473,7 +469,7 @@ namespace mongo { return IndexBuilder::killMatchingIndexBuilds(db->getCollection(nsToDrop), criteria); } - virtual bool run(const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) { + virtual bool run(const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { const string nsToDrop = dbname + '.' + cmdObj.firstElement().valuestr(); if (!serverGlobalParams.quiet) { MONGO_TLOG(0) << "CMD: drop " << nsToDrop << endl; @@ -505,8 +501,11 @@ namespace mongo { Status s = db->dropCollection( &txn, nsToDrop ); - if ( s.isOK() ) + if ( s.isOK() ) { + if (!fromRepl) + logOp(&txn, "c",(dbname + ".$cmd").c_str(), cmdObj); return true; + } appendCommandStatus( result, s ); @@ -519,7 +518,6 @@ namespace mongo { public: virtual bool isWriteCommandForConfigServer() const { return false; } CmdCount() : Command("count") { } - virtual bool logTheOp() { return false; } virtual bool slaveOk() const { // ok on --slave setups return replSettings.slave == SimpleSlave; @@ -585,9 +583,6 @@ namespace mongo { class CmdCreate : public Command { public: CmdCreate() : Command("create") { } - virtual bool logTheOp() { - return false; - } virtual bool slaveOk() const { return false; } @@ -1195,7 +1190,6 @@ namespace mongo { virtual bool slaveOk() const { return false; } virtual bool isWriteCommandForConfigServer() const { return true; } - virtual bool logTheOp() { return true; } virtual void help( stringstream &help ) const { help << "Sets collection options.\n" @@ -1303,6 +1297,9 @@ namespace mongo { } } + if (ok && !fromRepl) + logOp(&txn, "c",(dbname + ".$cmd").c_str(), jsobj); + return ok; } @@ -1644,10 +1641,6 @@ namespace mongo { client.curop()->ensureStarted(); retval = _execCommand(c, dbname, cmdObj, queryOptions, errmsg, result, fromRepl); - if ( retval && c->logTheOp() && ! fromRepl ) { - DurTransaction txn; // XXX - logOp(&txn, "c", cmdns, cmdObj); - } appendCommandStatus(result, retval, errmsg); diff --git a/src/mongo/db/dbcommands_generic.cpp b/src/mongo/db/dbcommands_generic.cpp index 10480cc7f20..ba351270be1 100644 --- a/src/mongo/db/dbcommands_generic.cpp +++ b/src/mongo/db/dbcommands_generic.cpp @@ -330,9 +330,6 @@ namespace mongo { virtual void help( stringstream& help ) const { help << "for testing purposes only. forces a user assertion exception"; } - virtual bool logTheOp() { - return false; - } virtual bool slaveOk() const { return true; } diff --git a/src/mongo/db/repl/replset_commands.h b/src/mongo/db/repl/replset_commands.h index 243e57a95f6..e303ae13890 100644 --- a/src/mongo/db/repl/replset_commands.h +++ b/src/mongo/db/repl/replset_commands.h @@ -47,7 +47,6 @@ namespace mongo { ReplSetCommand(const char * s, bool show=false) : Command(s, show) { } virtual bool slaveOk() const { return true; } virtual bool adminOnly() const { return true; } - virtual bool logTheOp() { return false; } virtual bool isWriteCommandForConfigServer() const { return false; } virtual void help( stringstream &help ) const { help << "internal"; } diff --git a/src/mongo/db/repl/resync.cpp b/src/mongo/db/repl/resync.cpp index 3ab88bd4f6c..0e59665b3f7 100644 --- a/src/mongo/db/repl/resync.cpp +++ b/src/mongo/db/repl/resync.cpp @@ -42,7 +42,6 @@ namespace mongo { virtual bool adminOnly() const { return true; } - virtual bool logTheOp() { return false; } virtual bool isWriteCommandForConfigServer() const { return true; } virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, diff --git a/src/mongo/s/commands/cluster_index_filter_cmd.cpp b/src/mongo/s/commands/cluster_index_filter_cmd.cpp index 5544ad6aa90..5b46edb4e99 100644 --- a/src/mongo/s/commands/cluster_index_filter_cmd.cpp +++ b/src/mongo/s/commands/cluster_index_filter_cmd.cpp @@ -54,10 +54,6 @@ namespace mongo { virtual ~ClusterIndexFilterCmd() { } - bool logTheOp() { - return false; - } - bool slaveOk() const { return false; } diff --git a/src/mongo/s/commands/cluster_plan_cache_cmd.cpp b/src/mongo/s/commands/cluster_plan_cache_cmd.cpp index 459575ba3f0..3aa47aff4dd 100644 --- a/src/mongo/s/commands/cluster_plan_cache_cmd.cpp +++ b/src/mongo/s/commands/cluster_plan_cache_cmd.cpp @@ -54,10 +54,6 @@ namespace mongo { virtual ~ClusterPlanCacheCmd() { } - bool logTheOp() { - return false; - } - bool slaveOk() const { return false; } diff --git a/src/mongo/s/commands/cluster_write_cmd.cpp b/src/mongo/s/commands/cluster_write_cmd.cpp index 18e886167ed..fba1c70d994 100644 --- a/src/mongo/s/commands/cluster_write_cmd.cpp +++ b/src/mongo/s/commands/cluster_write_cmd.cpp @@ -56,10 +56,6 @@ namespace mongo { virtual ~ClusterWriteCmd() { } - bool logTheOp() { - return false; - } - bool slaveOk() const { return false; } diff --git a/src/mongo/s/commands_admin.cpp b/src/mongo/s/commands_admin.cpp index 72ac64b8b44..754850fa553 100644 --- a/src/mongo/s/commands_admin.cpp +++ b/src/mongo/s/commands_admin.cpp @@ -1484,9 +1484,6 @@ namespace mongo { class CmdWhatsMyUri : public Command { public: CmdWhatsMyUri() : Command("whatsmyuri") { } - virtual bool logTheOp() { - return false; // the modification will be logged directly - } virtual bool slaveOk() const { return true; } @@ -1715,7 +1712,6 @@ namespace mongo { public: CmdListDatabases() : Command("listDatabases", true , "listdatabases" ) {} - virtual bool logTheOp() { return false; } virtual bool slaveOk() const { return true; } virtual bool slaveOverrideOk() const { return true; } virtual bool adminOnly() const { return true; } @@ -1843,7 +1839,6 @@ namespace mongo { class CmdCloseAllDatabases : public Command { public: CmdCloseAllDatabases() : Command("closeAllDatabases", false , "closeAllDatabases" ) {} - virtual bool logTheOp() { return false; } virtual bool slaveOk() const { return true; } virtual bool slaveOverrideOk() const { return true; } virtual bool adminOnly() const { return true; } @@ -1867,7 +1862,6 @@ namespace mongo { class CmdReplSetGetStatus : public Command { public: CmdReplSetGetStatus() : Command("replSetGetStatus"){} - virtual bool logTheOp() { return false; } virtual bool slaveOk() const { return true; } virtual bool adminOnly() const { return true; } virtual bool isWriteCommandForConfigServer() const { return false; } |