diff options
author | matt dannenberg <matt.dannenberg@10gen.com> | 2014-05-19 13:28:28 -0400 |
---|---|---|
committer | matt dannenberg <matt.dannenberg@10gen.com> | 2014-05-22 12:18:42 -0400 |
commit | 3cb9955b05bdef78cb8f72f63e657d920c0fa0bb (patch) | |
tree | 7768ef10ba9b219e22a04905ffa090d56ed1592d | |
parent | 0d088b82f1490aa7053fdf2748a55162b30970c4 (diff) | |
download | mongo-3cb9955b05bdef78cb8f72f63e657d920c0fa0bb.tar.gz |
SERVER-14021 move all replication code into namespace replset
102 files changed, 442 insertions, 291 deletions
diff --git a/src/mongo/db/catalog/collection.cpp b/src/mongo/db/catalog/collection.cpp index 2708ff9e074..27d0e98dda8 100644 --- a/src/mongo/db/catalog/collection.cpp +++ b/src/mongo/db/catalog/collection.cpp @@ -329,7 +329,7 @@ namespace mongo { options.logIfError = false; options.dupsAllowed = !(KeyPattern::isIdKeyPattern(descriptor->keyPattern()) || descriptor->unique()) - || ignoreUniqueIndex(descriptor); + || replset::ignoreUniqueIndex(descriptor); UpdateTicket* updateTicket = new UpdateTicket(); updateTickets.mutableMap()[descriptor] = updateTicket; Status ret = iam->validateUpdate(objOld, objNew, oldLocation, options, updateTicket ); diff --git a/src/mongo/db/catalog/index_catalog.cpp b/src/mongo/db/catalog/index_catalog.cpp index 9a804f7e5ae..cfae22a3769 100644 --- a/src/mongo/db/catalog/index_catalog.cpp +++ b/src/mongo/db/catalog/index_catalog.cpp @@ -534,7 +534,7 @@ namespace mongo { if ( !IndexDescriptor::isIdIndexPattern( key ) ) { // for non _id indexes, we check to see if replication has turned off all indexes // we _always_ created _id index - if( theReplSet && !theReplSet->buildIndexes() ) { + if (replset::theReplSet && !replset::theReplSet->buildIndexes()) { // this is not exactly the right error code, but I think will make the most sense return Status( ErrorCodes::IndexAlreadyExists, "no indexes per repl" ); } @@ -999,7 +999,7 @@ namespace mongo { KeyPattern::isIdKeyPattern(index->descriptor()->keyPattern()) || index->descriptor()->unique(); - options.dupsAllowed = ignoreUniqueIndex( index->descriptor() ) || !isUnique; + options.dupsAllowed = replset::ignoreUniqueIndex(index->descriptor()) || !isUnique; int64_t inserted; return index->accessMethod()->insert(txn, obj, loc, options, &inserted); @@ -1092,7 +1092,7 @@ namespace mongo { if ( !descriptor->unique() ) continue; - if ( ignoreUniqueIndex(descriptor) ) + if (replset::ignoreUniqueIndex(descriptor)) continue; IndexAccessMethod* iam = getIndex( descriptor ); diff --git a/src/mongo/db/catalog/index_create.cpp b/src/mongo/db/catalog/index_create.cpp index b2b89d74722..a17b9a7e85b 100644 --- a/src/mongo/db/catalog/index_create.cpp +++ b/src/mongo/db/catalog/index_create.cpp @@ -63,7 +63,7 @@ namespace mongo { options.dupsAllowed = true; if ( descriptor->isIdIndex() || descriptor->unique() ) { - if ( !ignoreUniqueIndex( descriptor ) ) { + if (!replset::ignoreUniqueIndex(descriptor)) { options.dupsAllowed = false; } } @@ -132,7 +132,7 @@ namespace mongo { runner->saveState(); BSONObj toDelete; collection->deleteDocument( txn, loc, false, true, &toDelete ); - logOp( txn, "d", ns.c_str(), toDelete ); + replset::logOp(txn, "d", ns.c_str(), toDelete); if (!runner->restoreState(txn)) { // Runner got killed somehow. This probably shouldn't happen. @@ -272,8 +272,8 @@ namespace mongo { false /* cappedOk */, true /* noWarn */, &toDelete ); - if (isMasterNs(ns.c_str())) { - logOp( txn, "d", ns.c_str(), toDelete ); + if (replset::isMasterNs(ns.c_str())) { + replset::logOp(txn, "d", ns.c_str(), toDelete); } txn->recoveryUnit()->commitIfNeeded(); diff --git a/src/mongo/db/client.cpp b/src/mongo/db/client.cpp index f3bf5e3526d..1aed73b1087 100644 --- a/src/mongo/db/client.cpp +++ b/src/mongo/db/client.cpp @@ -309,7 +309,7 @@ namespace mongo { void Client::appendLastOp( BSONObjBuilder& b ) const { // _lastOp is never set if replication is off - if( theReplSet || ! _lastOp.isNull() ) { + if (replset::theReplSet || !_lastOp.isNull()) { b.appendTimestamp( "lastOp" , _lastOp.asDate() ); } } @@ -351,11 +351,11 @@ namespace mongo { _handshake = b.obj(); - if (!theReplSet || !o.hasField("member")) { + if (!replset::theReplSet || !o.hasField("member")) { return false; } - return theReplSet->registerSlave(_remoteId, o["member"].Int()); + return replset::theReplSet->registerSlave(_remoteId, o["member"].Int()); } bool ClientBasic::hasCurrent() { diff --git a/src/mongo/db/client.h b/src/mongo/db/client.h index 996d4d8b382..6d4179c506a 100644 --- a/src/mongo/db/client.h +++ b/src/mongo/db/client.h @@ -42,6 +42,7 @@ #include "mongo/db/d_concurrency.h" #include "mongo/db/lasterror.h" #include "mongo/db/lockstate.h" +#include "mongo/db/repl/rs.h" #include "mongo/db/stats/top.h" #include "mongo/db/storage_options.h" #include "mongo/util/concurrency/rwlock.h" @@ -50,7 +51,6 @@ namespace mongo { - extern class ReplSet *theReplSet; class AuthenticationInfo; class Database; class CurOp; diff --git a/src/mongo/db/clientcursor.cpp b/src/mongo/db/clientcursor.cpp index 65e79b52c5b..2b553fafb3f 100644 --- a/src/mongo/db/clientcursor.cpp +++ b/src/mongo/db/clientcursor.cpp @@ -164,7 +164,7 @@ namespace mongo { void ClientCursor::updateSlaveLocation( CurOp& curop ) { if ( _slaveReadTill.isNull() ) return; - mongo::updateSlaveLocation( curop , _ns.c_str() , _slaveReadTill ); + mongo::replset::updateSlaveLocation(curop, _ns.c_str(), _slaveReadTill); } // diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp index 99a7d31a766..d733c599c5e 100644 --- a/src/mongo/db/cloner.cpp +++ b/src/mongo/db/cloner.cpp @@ -163,8 +163,8 @@ namespace mongo { << ' ' << loc.toString() << " obj:" << js; } uassertStatusOK( loc.getStatus() ); - if ( logForRepl ) - logOp(txn, "i", to_collection, js); + if (logForRepl) + replset::logOp(txn, "i", to_collection, js); txn->recoveryUnit()->commitIfNeeded(); @@ -249,8 +249,8 @@ namespace mongo { uassertStatusOK( status ); } - if ( logForRepl ) - logOp(txn, "i", to_collection, spec); + if (logForRepl) + replset::logOp(txn, "i", to_collection, spec); txn->recoveryUnit()->commitIfNeeded(); @@ -286,7 +286,8 @@ namespace mongo { DBClientConnection *tmpConn = new DBClientConnection(); // cloner owns _conn in auto_ptr cloner.setConnection(tmpConn); - uassert(15908, errmsg, tmpConn->connect(host, errmsg) && replAuthenticate(tmpConn)); + uassert(15908, errmsg, + tmpConn->connect(host, errmsg) && replset::replAuthenticate(tmpConn)); return cloner.copyCollection(txn, ns, BSONObj(), errmsg, true, false, true, false); } @@ -370,7 +371,7 @@ namespace mongo { auto_ptr<DBClientBase> con( cs.connect( errmsg )); if ( !con.get() ) return false; - if( !replAuthenticate(con.get())) + if (!replset::replAuthenticate(con.get())) return false; _conn = con; diff --git a/src/mongo/db/commands/apply_ops.cpp b/src/mongo/db/commands/apply_ops.cpp index 82e0b4d5c4d..ed8d788d650 100644 --- a/src/mongo/db/commands/apply_ops.cpp +++ b/src/mongo/db/commands/apply_ops.cpp @@ -131,7 +131,11 @@ namespace mongo { invariant(Lock::nested()); Client::Context ctx(ns); - bool failed = applyOperation_inlock(txn, ctx.db(), temp, false, alwaysUpsert); + bool failed = replset::applyOperation_inlock(txn, + ctx.db(), + temp, + false, + alwaysUpsert); ab.append(!failed); if ( failed ) errors++; @@ -162,7 +166,7 @@ namespace mongo { } } - logOp(txn, "c", tempNS.c_str(), cmdBuilder.done()); + replset::logOp(txn, "c", tempNS.c_str(), cmdBuilder.done()); } return errors == 0; diff --git a/src/mongo/db/commands/auth_schema_upgrade_d.cpp b/src/mongo/db/commands/auth_schema_upgrade_d.cpp index 90384c524fa..b6874f1549e 100644 --- a/src/mongo/db/commands/auth_schema_upgrade_d.cpp +++ b/src/mongo/db/commands/auth_schema_upgrade_d.cpp @@ -43,20 +43,20 @@ namespace mongo { namespace { Status checkReplicaMemberVersions() { - if (!theReplSet) + if (!replset::theReplSet) return Status::OK(); - std::list<Target> rsMembers; + std::list<replset::Target> rsMembers; try { - const unsigned rsSelfId = theReplSet->selfId(); - const std::vector<ReplSetConfig::MemberCfg>& rsMemberConfigs = - theReplSet->config().members; + const unsigned rsSelfId = replset::theReplSet->selfId(); + const std::vector<replset::ReplSetConfig::MemberCfg>& rsMemberConfigs = + replset::theReplSet->config().members; for (size_t i = 0; i < rsMemberConfigs.size(); ++i) { const unsigned otherId = rsMemberConfigs[i]._id; if (rsSelfId == otherId) continue; - const Member* other = theReplSet->findById(otherId); + const replset::Member* other = replset::theReplSet->findById(otherId); if (!other) { log() << "During authSchemaUpgrade, no information about replica set member " "with id " << otherId << "; ignoring."; @@ -67,7 +67,7 @@ namespace { " is down; ignoring."; continue; } - rsMembers.push_back(Target(other->fullName())); + rsMembers.push_back(replset::Target(other->fullName())); } multiCommand(BSON("buildInfo" << 1), rsMembers); @@ -76,8 +76,8 @@ namespace { return ex.toStatus(); } - for (std::list<Target>::const_iterator iter = rsMembers.begin(), end = rsMembers.end(); - iter != end; + for (std::list<replset::Target>::const_iterator iter = rsMembers.begin(); + iter != rsMembers.end(); ++iter) { if (!iter->ok) { diff --git a/src/mongo/db/commands/collection_to_capped.cpp b/src/mongo/db/commands/collection_to_capped.cpp index 65cb87d165f..e2f6c29c940 100644 --- a/src/mongo/db/commands/collection_to_capped.cpp +++ b/src/mongo/db/commands/collection_to_capped.cpp @@ -107,7 +107,7 @@ namespace mongo { toCollection->insertDocument( txn, obj, true ); if ( logForReplication ) - logOp( txn, "i", toNs.c_str(), obj ); + replset::logOp(txn, "i", toNs.c_str(), obj); txn->recoveryUnit()->commitIfNeeded(); } } @@ -241,7 +241,7 @@ namespace mongo { return appendCommandStatus( result, status ); if (!fromRepl) - logOp(txn, "c",(dbname + ".$cmd").c_str(), jsobj); + replset::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 4e51b92e930..a9384134c3a 100644 --- a/src/mongo/db/commands/compact.cpp +++ b/src/mongo/db/commands/compact.cpp @@ -35,21 +35,19 @@ #include "mongo/db/auth/action_type.h" #include "mongo/db/auth/privilege.h" #include "mongo/db/background.h" -#include "mongo/db/commands.h" +#include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" -#include "mongo/db/d_concurrency.h" +#include "mongo/db/commands.h" #include "mongo/db/curop.h" +#include "mongo/db/d_concurrency.h" #include "mongo/db/index_builder.h" #include "mongo/db/jsobj.h" #include "mongo/db/kill_current_op.h" -#include "mongo/db/catalog/collection.h" #include "mongo/db/operation_context_impl.h" +#include "mongo/db/repl/rs.h" namespace mongo { - // from repl/rs.cpp - bool isCurrentlyAReplSetPrimary(); - class CompactCmd : public Command { public: virtual bool isWriteCommandForConfigServer() const { return false; } @@ -90,7 +88,7 @@ namespace mongo { return false; } - if( isCurrentlyAReplSetPrimary() && !cmdObj["force"].trueValue() ) { + if (replset::isCurrentlyAReplSetPrimary() && !cmdObj["force"].trueValue()) { errmsg = "will not run compact on an active replica set primary as this is a slow blocking operation. use force:true to force"; return false; } diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp index 978f0268863..3917cd8cfb8 100644 --- a/src/mongo/db/commands/create_indexes.cpp +++ b/src/mongo/db/commands/create_indexes.cpp @@ -204,7 +204,7 @@ namespace mongo { if ( !fromRepl ) { std::string systemIndexes = ns.getSystemIndexesCollection(); - logOp( txn, "i", systemIndexes.c_str(), spec ); + replset::logOp(txn, "i", systemIndexes.c_str(), spec); } } diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp index 332da8c6e3e..98ad677ea93 100644 --- a/src/mongo/db/commands/drop_indexes.cpp +++ b/src/mongo/db/commands/drop_indexes.cpp @@ -96,7 +96,7 @@ namespace mongo { Lock::DBWrite dbXLock(dbname); bool ok = wrappedRun(txn, dbname, jsobj, errmsg, anObjBuilder); if (ok && !fromRepl) - logOp(txn, "c",(dbname + ".$cmd").c_str(), jsobj); + replset::logOp(txn, "c",(dbname + ".$cmd").c_str(), jsobj); return ok; } bool wrappedRun(OperationContext* txn, diff --git a/src/mongo/db/commands/get_last_error.cpp b/src/mongo/db/commands/get_last_error.cpp index 30aaede898b..2e552c97e92 100644 --- a/src/mongo/db/commands/get_last_error.cpp +++ b/src/mongo/db/commands/get_last_error.cpp @@ -28,6 +28,8 @@ * it in the license file. */ +#include "mongo/db/commands/get_last_error.h" + #include "mongo/db/client.h" #include "mongo/db/curop.h" #include "mongo/db/commands.h" @@ -210,7 +212,7 @@ namespace mongo { // If we got an electionId, make sure it matches if (electionIdPresent) { - if (!theReplSet) { + if (!replset::theReplSet) { // Ignore electionIds of 0 from mongos. if (electionId != OID()) { errmsg = "wElectionId passed but no replication active"; @@ -219,9 +221,9 @@ namespace mongo { } } else { - if (electionId != theReplSet->getElectionId()) { + if (electionId != replset::theReplSet->getElectionId()) { LOG(3) << "oid passed in is " << electionId - << ", but our id is " << theReplSet->getElectionId(); + << ", but our id is " << replset::theReplSet->getElectionId(); errmsg = "election occurred after write"; result.append("code", ErrorCodes::WriteConcernFailed); return false; diff --git a/src/mongo/db/commands/get_last_error.h b/src/mongo/db/commands/get_last_error.h new file mode 100644 index 00000000000..6203141f9d6 --- /dev/null +++ b/src/mongo/db/commands/get_last_error.h @@ -0,0 +1,35 @@ +/** + * Copyright (C) 2014 MongoDB Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#pragma once + +namespace mongo { + class BSONObj; + + extern BSONObj *getLastErrorDefault; +} // namespace mongo diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp index ff90e6e4b67..0ed360ca385 100644 --- a/src/mongo/db/commands/mr.cpp +++ b/src/mongo/db/commands/mr.cpp @@ -404,7 +404,7 @@ namespace mongo { b.append( "create", nsToCollectionSubstring( _config.tempNamespace )); b.appendElements( options.toBSON() ); string logNs = nsToDatabase( _config.tempNamespace ) + ".$cmd"; - logOp( _txn, "c", logNs.c_str(), b.obj() ); + replset::logOp(_txn, "c", logNs.c_str(), b.obj()); } for ( vector<BSONObj>::iterator it = indexesToInsert.begin(); @@ -412,7 +412,7 @@ namespace mongo { tempColl->getIndexCatalog()->createIndex(_txn, *it, false ); // Log the createIndex operation. string logNs = nsToDatabase( _config.tempNamespace ) + ".system.indexes"; - logOp( _txn, "i", logNs.c_str(), *it ); + replset::logOp(_txn, "i", logNs.c_str(), *it); } } @@ -636,7 +636,7 @@ namespace mongo { BSONObj bo = b.obj(); coll->insertDocument( _txn, bo, true ); - logOp( _txn, "i", ns.c_str(), bo ); + replset::logOp(_txn, "i", ns.c_str(), bo); } /** @@ -1182,7 +1182,7 @@ namespace mongo { /* why !replset ? bad things happen with --slave (i think because of this) */ - virtual bool slaveOk() const { return !replSet; } + virtual bool slaveOk() const { return !replset::replSet; } virtual bool slaveOverrideOk() const { return true; } @@ -1238,10 +1238,10 @@ namespace mongo { return false; } - if (replSet && state.isOnDisk()) { + if (replset::replSet && state.isOnDisk()) { // this means that it will be doing a write operation, make sure we are on Master // ideally this check should be in slaveOk(), but at that point config is not known - if (!isMasterNs(dbname.c_str())) { + if (!replset::isMasterNs(dbname.c_str())) { errmsg = "not master"; return false; } @@ -1428,7 +1428,7 @@ namespace mongo { public: void help(stringstream& h) const { h << "internal"; } MapReduceFinishCommand() : Command( "mapreduce.shardedfinish" ) {} - virtual bool slaveOk() const { return !replSet; } + virtual bool slaveOk() const { return !replset::replSet; } virtual bool slaveOverrideOk() const { return true; } virtual bool isWriteCommandForConfigServer() const { return false; } virtual void addRequiredPrivileges(const std::string& dbname, diff --git a/src/mongo/db/commands/oplog_note.cpp b/src/mongo/db/commands/oplog_note.cpp index e4d8924408e..ef4b9bb3fa0 100644 --- a/src/mongo/db/commands/oplog_note.cpp +++ b/src/mongo/db/commands/oplog_note.cpp @@ -62,7 +62,7 @@ namespace mongo { string& errmsg, BSONObjBuilder& result, bool fromRepl) { - if (!replSettings.master) { + if (!replset::replSettings.master) { return appendCommandStatus(result, Status( ErrorCodes::NoReplicationEnabled, "Must have replication set up to run \"appendOplogNote\"")); @@ -73,7 +73,7 @@ namespace mongo { return appendCommandStatus(result, status); } - logOpComment(dataElement.Obj()); + replset::logOpComment(dataElement.Obj()); return true; } diff --git a/src/mongo/db/commands/rename_collection.cpp b/src/mongo/db/commands/rename_collection.cpp index 9f173c03d72..f4ed505cb63 100644 --- a/src/mongo/db/commands/rename_collection.cpp +++ b/src/mongo/db/commands/rename_collection.cpp @@ -95,7 +95,7 @@ namespace mongo { Lock::GlobalWrite globalWriteLock; bool ok = wrappedRun(txn, dbname, cmdObj, errmsg, result, fromRepl); if (ok && !fromRepl) - logOp(txn, "c",(dbname + ".$cmd").c_str(), cmdObj); + replset::logOp(txn, "c",(dbname + ".$cmd").c_str(), cmdObj); return ok; } virtual bool wrappedRun(OperationContext* txn, diff --git a/src/mongo/db/commands/test_commands.cpp b/src/mongo/db/commands/test_commands.cpp index 91364dbba3a..cd41ad17488 100644 --- a/src/mongo/db/commands/test_commands.cpp +++ b/src/mongo/db/commands/test_commands.cpp @@ -199,7 +199,7 @@ namespace mongo { IndexBuilder::restoreIndexes(indexes); if (!fromRepl) - logOp(txn, "c",(dbname + ".$cmd").c_str(), cmdObj); + replset::logOp(txn, "c",(dbname + ".$cmd").c_str(), cmdObj); return true; } }; diff --git a/src/mongo/db/commands/write_commands/batch_executor.cpp b/src/mongo/db/commands/write_commands/batch_executor.cpp index 8d56a43d647..9e936a54275 100644 --- a/src/mongo/db/commands/write_commands/batch_executor.cpp +++ b/src/mongo/db/commands/write_commands/batch_executor.cpp @@ -353,10 +353,10 @@ namespace mongo { response->setWriteConcernError( wcError.release() ); } - if ( anyReplEnabled() ) { + if (replset::anyReplEnabled()) { response->setLastOp( _client->getLastOp() ); - if (theReplSet) { - response->setElectionId( theReplSet->getElectionId() ); + if (replset::theReplSet) { + response->setElectionId(replset::theReplSet->getElectionId()); } } @@ -434,7 +434,7 @@ namespace mongo { } static bool checkIsMasterForCollection(const std::string& ns, WriteOpResult* result) { - if (!isMasterNs(ns.c_str())) { + if (!replset::isMasterNs(ns.c_str())) { WriteErrorDetail* errorDetail = new WriteErrorDetail; result->setError(errorDetail); errorDetail->setErrCode(ErrorCodes::NotMaster); @@ -1030,7 +1030,7 @@ namespace mongo { result->setError(toWriteError(status.getStatus())); } else { - logOp( txn, "i", insertNS.c_str(), docToInsert ); + replset::logOp( txn, "i", insertNS.c_str(), docToInsert ); txn->recoveryUnit()->commitIfNeeded(); result->getStats().n = 1; } @@ -1060,7 +1060,7 @@ namespace mongo { result->setError(toWriteError(status)); } else { - logOp( txn, "i", indexNS.c_str(), indexDesc ); + replset::logOp( txn, "i", indexNS.c_str(), indexDesc ); result->getStats().n = 1; } } diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp index 290c1137e8b..318c9b740a6 100644 --- a/src/mongo/db/db.cpp +++ b/src/mongo/db/db.cpp @@ -279,7 +279,7 @@ namespace mongo { server->setupSockets(); logStartup(); - startReplication(); + replset::startReplication(); if (serverGlobalParams.isHttpInterfaceEnabled) boost::thread web( stdx::bind(&webServerThread, new RestAdminAccess(), // takes ownership @@ -371,7 +371,7 @@ namespace mongo { DataFile *p = ctx.db()->getExtentManager()->getFile( &txn, 0 ); DataFileHeader *h = p->getHeader(); - if ( replSettings.usingReplSets() ) { + if (replset::replSettings.usingReplSets()) { // we only care about the _id index if we are in a replset checkForIdIndexes(ctx.db()); } @@ -478,7 +478,7 @@ namespace mongo { */ unsigned long long checkIfReplMissingFromCommandLine() { Lock::GlobalWrite lk; // this is helpful for the query below to work as you can't open files when readlocked - if (!replSettings.usingReplSets()) { + if (!replset::replSettings.usingReplSets()) { DBDirectClient c; return c.count("local.system.replset"); } @@ -653,8 +653,8 @@ namespace mongo { l << "MongoDB starting : pid=" << pid << " port=" << serverGlobalParams.port << " dbpath=" << storageGlobalParams.dbpath; - if( replSettings.master ) l << " master=" << replSettings.master; - if( replSettings.slave ) l << " slave=" << (int) replSettings.slave; + if( replset::replSettings.master ) l << " master=" << replset::replSettings.master; + if( replset::replSettings.slave ) l << " slave=" << (int) replset::replSettings.slave; l << ( is32bit ? " 32" : " 64" ) << "-bit host=" << getHostNameCached() << endl; } DEV log() << "_DEBUG build (which is slower)" << endl; @@ -722,9 +722,9 @@ namespace mongo { // On replica set members we only clear temp collections on DBs other than "local" during // promotion to primary. On pure slaves, they are only cleared when the oplog tells them to. // The local DB is special because it is not replicated. See SERVER-10927 for more details. - const bool shouldClearNonLocalTmpCollections = !(missingRepl - || replSettings.usingReplSets() - || replSettings.slave == SimpleSlave); + const bool shouldClearNonLocalTmpCollections =!(missingRepl + || replset::replSettings.usingReplSets() + || replset::replSettings.slave == replset::SimpleSlave); repairDatabasesAndCheckVersion(shouldClearNonLocalTmpCollections); if (mongodGlobalParams.upgrade) diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp index f59c62c4cf9..814fcdee079 100644 --- a/src/mongo/db/dbcommands.cpp +++ b/src/mongo/db/dbcommands.cpp @@ -96,24 +96,24 @@ namespace mongo { bool force = cmdObj.hasField("force") && cmdObj["force"].trueValue(); if (!force && - theReplSet && - theReplSet->getConfig().members.size() > 1 && - theReplSet->isPrimary()) { + replset::theReplSet && + replset::theReplSet->getConfig().members.size() > 1 && + replset::theReplSet->isPrimary()) { long long timeout, now, start; timeout = now = start = curTimeMicros64()/1000000; if (cmdObj.hasField("timeoutSecs")) { timeout += cmdObj["timeoutSecs"].numberLong(); } - OpTime lastOp = theReplSet->lastOpTimeWritten; - OpTime closest = theReplSet->lastOtherOpTime(); + OpTime lastOp = replset::theReplSet->lastOpTimeWritten; + OpTime closest = replset::theReplSet->lastOtherOpTime(); long long int diff = lastOp.getSecs() - closest.getSecs(); while (now <= timeout && (diff < 0 || diff > 10)) { sleepsecs(1); now++; - lastOp = theReplSet->lastOpTimeWritten; - closest = theReplSet->lastOtherOpTime(); + lastOp = replset::theReplSet->lastOpTimeWritten; + closest = replset::theReplSet->lastOtherOpTime(); diff = lastOp.getSecs() - closest.getSecs(); } @@ -125,13 +125,13 @@ namespace mongo { } // step down - theReplSet->stepDown(120); + replset::theReplSet->stepDown(120); log() << "waiting for secondaries to catch up" << endl; - lastOp = theReplSet->lastOpTimeWritten; + lastOp = replset::theReplSet->lastOpTimeWritten; while (lastOp != closest && now - start < 60) { - closest = theReplSet->lastOtherOpTime(); + closest = replset::theReplSet->lastOtherOpTime(); now++; sleepsecs(1); @@ -217,7 +217,7 @@ namespace mongo { log() << "dropDatabase " << dbname << " finished"; if (!fromRepl) - logOp(txn, "c",(dbname + ".$cmd").c_str(), cmdObj); + replset::logOp(txn, "c",(dbname + ".$cmd").c_str(), cmdObj); } result.append( "dropped" , dbname ); @@ -479,7 +479,7 @@ namespace mongo { if ( s.isOK() ) { if (!fromRepl) - logOp(txn, "c",(dbname + ".$cmd").c_str(), cmdObj); + replset::logOp(txn, "c",(dbname + ".$cmd").c_str(), cmdObj); return true; } @@ -496,7 +496,7 @@ namespace mongo { CmdCount() : Command("count") { } virtual bool slaveOk() const { // ok on --slave setups - return replSettings.slave == SimpleSlave; + return replset::replSettings.slave == replset::SimpleSlave; } virtual bool slaveOverrideOk() const { return true; } virtual bool maintenanceOk() const { return false; } @@ -1198,7 +1198,7 @@ namespace mongo { } if (ok && !fromRepl) - logOp(txn, "c",(dbname + ".$cmd").c_str(), jsobj); + replset::logOp(txn, "c",(dbname + ".$cmd").c_str(), jsobj); return ok; } @@ -1310,10 +1310,11 @@ namespace mongo { assumption needs to be audited and documented. */ class MaintenanceModeSetter { public: - MaintenanceModeSetter() : maintenanceModeSet(theReplSet->setMaintenanceMode(true)) {} + MaintenanceModeSetter() : maintenanceModeSet(replset::theReplSet->setMaintenanceMode(true)) + {} ~MaintenanceModeSetter() { if(maintenanceModeSet) - theReplSet->setMaintenanceMode(false); + replset::theReplSet->setMaintenanceMode(false); } private: bool maintenanceModeSet; @@ -1407,7 +1408,7 @@ namespace mongo { } bool canRunHere = - isMasterNs(dbname.c_str()) || + replset::isMasterNs(dbname.c_str()) || c->slaveOk() || ( c->slaveOverrideOk() && ( queryOptions & QueryOption_SlaveOk ) ) || fromRepl; @@ -1418,7 +1419,10 @@ namespace mongo { return; } - if ( ! c->maintenanceOk() && theReplSet && ! isMasterNs( dbname.c_str() ) && ! theReplSet->isSecondary() ) { + if (!c->maintenanceOk() + && replset::theReplSet + && !replset::isMasterNs(dbname.c_str()) + && !replset::theReplSet->isSecondary()) { result.append( "note" , "from execCommand" ); appendCommandStatus(result, false, "node is recovering"); return; @@ -1430,7 +1434,7 @@ namespace mongo { client.curop()->setCommand(c); - if (c->maintenanceMode() && theReplSet) { + if (c->maintenanceMode() && replset::theReplSet) { mmSetter.reset(new MaintenanceModeSetter()); } @@ -1474,11 +1478,12 @@ namespace mongo { appendCommandStatus(result, retval, errmsg); // For commands from mongos, append some info to help getLastError(w) work. - if (theReplSet) { + if (replset::theReplSet) { // Detect mongos connections by looking for setShardVersion to have been run previously // on this connection. if (shardingState.needCollectionMetadata(dbname)) { - appendGLEHelperData(result, client.getLastOp(), theReplSet->getElectionId()); + appendGLEHelperData(result, client.getLastOp(), + replset::theReplSet->getElectionId()); } } return; diff --git a/src/mongo/db/dbhelpers.cpp b/src/mongo/db/dbhelpers.cpp index 369101eddd8..b2cd7e0b413 100644 --- a/src/mongo/db/dbhelpers.cpp +++ b/src/mongo/db/dbhelpers.cpp @@ -440,14 +440,14 @@ namespace mongo { BSONObj deletedId; collection->deleteDocument( txn, rloc, false, false, &deletedId ); // The above throws on failure, and so is not logged - logOp(txn, "d", ns.c_str(), deletedId, 0, 0, fromMigrate); + replset::logOp(txn, "d", ns.c_str(), deletedId, 0, 0, fromMigrate); numDeleted++; } Timer secondaryThrottleTime; if ( secondaryThrottle && numDeleted > 0 ) { - if ( ! waitForReplication( c.getLastOp(), 2, 60 /* seconds to wait */ ) ) { + if (!replset::waitForReplication(c.getLastOp(), 2, 60 /* seconds to wait */)) { warning() << "replication to secondaries for removeRange at least 60 seconds behind" << endl; } millisWaitingForReplication += secondaryThrottleTime.millis(); diff --git a/src/mongo/db/index/btree_based_bulk_access_method.cpp b/src/mongo/db/index/btree_based_bulk_access_method.cpp index 591d49b86c6..c750b1097ed 100644 --- a/src/mongo/db/index/btree_based_bulk_access_method.cpp +++ b/src/mongo/db/index/btree_based_bulk_access_method.cpp @@ -129,7 +129,7 @@ namespace mongo { IndexCatalogEntry* entry = _real->_btreeState; bool dupsAllowed = !entry->descriptor()->unique() - || ignoreUniqueIndex(entry->descriptor()); + || replset::ignoreUniqueIndex(entry->descriptor()); bool dropDups = entry->descriptor()->dropDups() || inDBRepair; diff --git a/src/mongo/db/index_builder.cpp b/src/mongo/db/index_builder.cpp index 0def5596b82..c5a0c6ab3f1 100644 --- a/src/mongo/db/index_builder.cpp +++ b/src/mongo/db/index_builder.cpp @@ -58,7 +58,7 @@ namespace mongo { Client::initThread(name().c_str()); Lock::ParallelBatchWriterMode::iAmABatchParticipant(); - replLocalAuth(); + replset::replLocalAuth(); cc().curop()->reset(HostAndPort(), dbInsert); NamespaceString ns(_index["ns"].String()); diff --git a/src/mongo/db/index_rebuilder.cpp b/src/mongo/db/index_rebuilder.cpp index 426240390e4..d158115f261 100644 --- a/src/mongo/db/index_rebuilder.cpp +++ b/src/mongo/db/index_rebuilder.cpp @@ -72,9 +72,9 @@ namespace mongo { catch (const DBException& e) { warning() << "Index rebuilding did not complete: " << e.what() << endl; } - boost::unique_lock<boost::mutex> lk(ReplSet::rss.mtx); - ReplSet::rss.indexRebuildDone = true; - ReplSet::rss.cond.notify_all(); + boost::unique_lock<boost::mutex> lk(replset::ReplSet::rss.mtx); + replset::ReplSet::rss.indexRebuildDone = true; + replset::ReplSet::rss.cond.notify_all(); LOG(1) << "checking complete" << endl; } diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp index b0f38faa22b..cb34efb0810 100644 --- a/src/mongo/db/instance.cpp +++ b/src/mongo/db/instance.cpp @@ -548,7 +548,7 @@ namespace mongo { Database *database = ctx->db(); verify( database->name() == db ); - oplogCheckCloseDatabase( database ); // oplog caches some things, dirty its caches + replset::oplogCheckCloseDatabase(database); // oplog caches some things, dirty its caches if( BackgroundOperation::inProgForDb(db) ) { log() << "warning: bg op in prog during close db? " << db << endl; @@ -697,7 +697,7 @@ namespace mongo { last = getLastSetOptime(); } else { - waitForOptimeChange(last, 1000/*ms*/); + replset::waitForOptimeChange(last, 1000/*ms*/); } } @@ -811,7 +811,7 @@ namespace mongo { return; uassertStatusOK( status ); - logOp( txn, "i", ns, js ); + replset::logOp(txn, "i", ns, js); return; } @@ -828,7 +828,7 @@ namespace mongo { StatusWith<DiskLoc> status = collection->insertDocument( txn, js, true ); uassertStatusOK( status.getStatus() ); - logOp(txn, "i", ns, js); + replset::logOp(txn, "i", ns, js); } NOINLINE_DECL void insertMulti(OperationContext* txn, @@ -884,7 +884,7 @@ namespace mongo { // CONCURRENCY TODO: is being read locked in big log sufficient here? // writelock is used to synchronize stepdowns w/ writes - uassert( 10058 , "not master", isMasterNs(ns) ); + uassert(10058 , "not master", replset::isMasterNs(ns)); if ( handlePossibleShardedMessage( m , 0 ) ) return; @@ -933,9 +933,9 @@ namespace mongo { return true; // we have a local database. return true if oplog isn't empty { - Lock::DBRead lk(rsoplog); + Lock::DBRead lk(replset::rsoplog); BSONObj o; - if( Helpers::getFirst(rsoplog, o) ) + if( Helpers::getFirst(replset::rsoplog, o) ) return true; } } @@ -1115,8 +1115,8 @@ namespace { void exitCleanly( ExitCode code ) { killCurrentOp.killAll(); - if (theReplSet) { - theReplSet->shutdown(); + if (replset::theReplSet) { + replset::theReplSet->shutdown(); } { diff --git a/src/mongo/db/mongod_options.cpp b/src/mongo/db/mongod_options.cpp index 66462ef2e03..3d05338729b 100644 --- a/src/mongo/db/mongod_options.cpp +++ b/src/mongo/db/mongod_options.cpp @@ -1002,36 +1002,36 @@ namespace mongo { storageGlobalParams.noTableScan = params["notablescan"].as<bool>(); } if (params.count("master")) { - replSettings.master = params["master"].as<bool>(); + replset::replSettings.master = params["master"].as<bool>(); } if (params.count("slave") && params["slave"].as<bool>() == true) { - replSettings.slave = SimpleSlave; + replset::replSettings.slave = replset::SimpleSlave; } if (params.count("slavedelay")) { - replSettings.slavedelay = params["slavedelay"].as<int>(); + replset::replSettings.slavedelay = params["slavedelay"].as<int>(); } if (params.count("fastsync")) { - replSettings.fastsync = params["fastsync"].as<bool>(); + replset::replSettings.fastsync = params["fastsync"].as<bool>(); } if (params.count("autoresync")) { - replSettings.autoresync = params["autoresync"].as<bool>(); + replset::replSettings.autoresync = params["autoresync"].as<bool>(); } if (params.count("source")) { /* specifies what the source in local.sources should be */ - replSettings.source = params["source"].as<string>().c_str(); + replset::replSettings.source = params["source"].as<string>().c_str(); } if( params.count("pretouch") ) { - replSettings.pretouch = params["pretouch"].as<int>(); + replset::replSettings.pretouch = params["pretouch"].as<int>(); } if (params.count("replication.replSetName")) { - replSettings.replSet = params["replication.replSetName"].as<string>().c_str(); + replset::replSettings.replSet = params["replication.replSetName"].as<string>().c_str(); } if (params.count("replication.replSet")) { /* seed list of hosts for the repl set */ - replSettings.replSet = params["replication.replSet"].as<string>().c_str(); + replset::replSettings.replSet = params["replication.replSet"].as<string>().c_str(); } if (params.count("replication.secondaryIndexPrefetch")) { - replSettings.rsIndexPrefetch = + replset::replSettings.rsIndexPrefetch = params["replication.secondaryIndexPrefetch"].as<std::string>(); } @@ -1040,7 +1040,7 @@ namespace mongo { } if (params.count("only")) { - replSettings.only = params["only"].as<string>().c_str(); + replset::replSettings.only = params["only"].as<string>().c_str(); } if( params.count("storage.nsSize") ) { int x = params["storage.nsSize"].as<int>(); @@ -1062,8 +1062,8 @@ namespace mongo { << "MB is too big for 32 bit version. Use 64 bit build instead."; return Status(ErrorCodes::BadValue, sb.str()); } - replSettings.oplogSize = x * 1024 * 1024; - verify(replSettings.oplogSize > 0); + replset::replSettings.oplogSize = x * 1024 * 1024; + verify(replset::replSettings.oplogSize > 0); } if (params.count("cacheSize")) { long x = params["cacheSize"].as<long>(); @@ -1098,7 +1098,9 @@ namespace mongo { params["sharding.clusterRole"].as<std::string>() == "configsvr") { serverGlobalParams.configsvr = true; storageGlobalParams.smallfiles = true; // config server implies small files - if (replSettings.usingReplSets() || replSettings.master || replSettings.slave) { + if (replset::replSettings.usingReplSets() + || replset::replSettings.master + || replset::replSettings.slave) { return Status(ErrorCodes::BadValue, "replication should not be enabled on a config server"); } @@ -1111,9 +1113,9 @@ namespace mongo { if (!params.count("storage.dbPath")) storageGlobalParams.dbpath = "/data/configdb"; - replSettings.master = true; + replset::replSettings.master = true; if (!params.count("replication.oplogSizeMB")) - replSettings.oplogSize = 5 * 1024 * 1024; + replset::replSettings.oplogSize = 5 * 1024 * 1024; } if (params.count("sharding.archiveMovedChunks")) { @@ -1148,8 +1150,8 @@ namespace mongo { storageGlobalParams.repairpath = storageGlobalParams.dbpath; } - if (replSettings.pretouch) - log() << "--pretouch " << replSettings.pretouch << endl; + if (replset::replSettings.pretouch) + log() << "--pretouch " << replset::replSettings.pretouch; // Check if we are 32 bit and have not explicitly specified any journaling options if (sizeof(void*) == 4 && !params.count("storage.journal.enabled")) { diff --git a/src/mongo/db/operation_context_impl.cpp b/src/mongo/db/operation_context_impl.cpp index 2dc5e5be1f1..567f487467c 100644 --- a/src/mongo/db/operation_context_impl.cpp +++ b/src/mongo/db/operation_context_impl.cpp @@ -71,7 +71,7 @@ namespace mongo { bool OperationContextImpl::isPrimaryFor( const StringData& ns ) { string s = ns.toString(); // TODO: fix copy - return isMasterNs( s.c_str() ); + return replset::isMasterNs(s.c_str()); } OperationContext* OperationContextImpl::factory() { diff --git a/src/mongo/db/ops/delete_executor.cpp b/src/mongo/db/ops/delete_executor.cpp index a28d86a9dc8..66c26bf8e3d 100644 --- a/src/mongo/db/ops/delete_executor.cpp +++ b/src/mongo/db/ops/delete_executor.cpp @@ -110,7 +110,7 @@ namespace mongo { uassert(ErrorCodes::NotMaster, str::stream() << "Not primary while removing from " << ns.ns(), - !logop || isMasterNs(ns.ns().c_str())); + !logop || replset::isMasterNs(ns.ns().c_str())); long long nDeleted = 0; @@ -138,7 +138,7 @@ namespace mongo { if (oldYieldCount != curOp->numYields()) { uassert(ErrorCodes::NotMaster, str::stream() << "No longer primary while removing from " << ns.ns(), - !logop || isMasterNs(ns.ns().c_str())); + !logop || replset::isMasterNs(ns.ns().c_str())); oldYieldCount = curOp->numYields(); } BSONObj toDelete; @@ -158,7 +158,7 @@ namespace mongo { } else { bool replJustOne = true; - logOp(txn, "d", ns.ns().c_str(), toDelete, 0, &replJustOne); + replset::logOp(txn, "d", ns.ns().c_str(), toDelete, 0, &replJustOne); } } diff --git a/src/mongo/db/ops/update.cpp b/src/mongo/db/ops/update.cpp index 872a1253a35..c1d45a2a890 100644 --- a/src/mongo/db/ops/update.cpp +++ b/src/mongo/db/ops/update.cpp @@ -511,7 +511,7 @@ namespace mongo { uassert(ErrorCodes::NotMaster, mongoutils::str::stream() << "Not primary while updating " << nsString.ns(), - !request.shouldCallLogOp() || isMasterNs(nsString.ns().c_str())); + !request.shouldCallLogOp() || replset::isMasterNs(nsString.ns().c_str())); while (true) { // Get next doc, and location @@ -668,7 +668,7 @@ namespace mongo { // Call logOp if requested. if (request.shouldCallLogOp() && !logObj.isEmpty()) { BSONObj idQuery = driver->makeOplogEntryQuery(newObj, request.isMulti()); - logOp(txn, "u", nsString.ns().c_str(), logObj , &idQuery, + replset::logOp(txn, "u", nsString.ns().c_str(), logObj , &idQuery, NULL, request.isFromMigration()); } @@ -782,8 +782,8 @@ namespace mongo { !request.isGod() /*enforceQuota*/); uassertStatusOK(newLoc.getStatus()); if (request.shouldCallLogOp()) { - logOp(txn, "i", nsString.ns().c_str(), newObj, - NULL, NULL, request.isFromMigration()); + replset::logOp(txn, "i", nsString.ns().c_str(), newObj, + NULL, NULL, request.isFromMigration()); } opDebug->nMatched = 1; diff --git a/src/mongo/db/pdfile.cpp b/src/mongo/db/pdfile.cpp index b837678fc9f..2898f921ace 100644 --- a/src/mongo/db/pdfile.cpp +++ b/src/mongo/db/pdfile.cpp @@ -132,7 +132,7 @@ namespace mongo { options = b.obj(); } string logNs = nsToDatabase(ns) + ".$cmd"; - logOp(txn, "c", logNs.c_str(), options); + replset::logOp(txn, "c", logNs.c_str(), options); } return Status::OK(); diff --git a/src/mongo/db/pdfile.h b/src/mongo/db/pdfile.h index 92848f13afc..9544d999840 100644 --- a/src/mongo/db/pdfile.h +++ b/src/mongo/db/pdfile.h @@ -49,6 +49,8 @@ namespace mongo { void dropDatabase(OperationContext* txn, Database* db); + void dropAllDatabasesExceptLocal(); + Status userCreateNS( OperationContext* txn, Database* db, const StringData& ns, diff --git a/src/mongo/db/prefetch.cpp b/src/mongo/db/prefetch.cpp index f478b3d8479..14a1d5a1bd1 100644 --- a/src/mongo/db/prefetch.cpp +++ b/src/mongo/db/prefetch.cpp @@ -117,15 +117,16 @@ namespace mongo { void prefetchIndexPages(Collection* collection, const BSONObj& obj) { DiskLoc unusedDl; // unused BSONObjSet unusedKeys; - ReplSetImpl::IndexPrefetchConfig prefetchConfig = theReplSet->getIndexPrefetchConfig(); + replset::ReplSetImpl::IndexPrefetchConfig prefetchConfig = + replset::theReplSet->getIndexPrefetchConfig(); // do we want prefetchConfig to be (1) as-is, (2) for update ops only, or (3) configured per op type? // One might want PREFETCH_NONE for updates, but it's more rare that it is a bad idea for inserts. // #3 (per op), a big issue would be "too many knobs". switch (prefetchConfig) { - case ReplSetImpl::PREFETCH_NONE: + case replset::ReplSetImpl::PREFETCH_NONE: return; - case ReplSetImpl::PREFETCH_ID_ONLY: + case replset::ReplSetImpl::PREFETCH_ID_ONLY: { TimerHolder timer( &prefetchIndexStats); // on the update op case, the call to prefetchRecordPages will touch the _id index. @@ -143,7 +144,7 @@ namespace mongo { } break; } - case ReplSetImpl::PREFETCH_ALL: + case replset::ReplSetImpl::PREFETCH_ALL: { // indexCount includes all indexes, including ones // in the process of being built diff --git a/src/mongo/db/query/new_find.cpp b/src/mongo/db/query/new_find.cpp index 421791859b5..a22eeb31eb5 100644 --- a/src/mongo/db/query/new_find.cpp +++ b/src/mongo/db/query/new_find.cpp @@ -162,7 +162,7 @@ namespace mongo { // passing in a query object (necessary to check SlaveOK query option), the only state where // reads are allowed is PRIMARY (or master in master/slave). This function uasserts if // reads are not okay. - replVerifyReadsOk(ns, NULL); + replset::replVerifyReadsOk(ns, NULL); // A pin performs a CC lookup and if there is a CC, increments the CC's pin value so it // doesn't time out. Also informs ClientCursor that there is somebody actively holding the @@ -525,7 +525,7 @@ namespace mongo { txn->checkForInterrupt(); // May trigger maxTimeAlwaysTimeOut fail point. // uassert if we are not on a primary, and not a secondary with SlaveOk query parameter set. - replVerifyReadsOk(cq->ns(), &pq); + replset::replVerifyReadsOk(cq->ns(), &pq); // If this exists, the collection is sharded. // If it doesn't exist, we can assume we're not sharded. diff --git a/src/mongo/db/range_deleter_db_env.cpp b/src/mongo/db/range_deleter_db_env.cpp index 44dd93e0c06..d3027a3f7ff 100644 --- a/src/mongo/db/range_deleter_db_env.cpp +++ b/src/mongo/db/range_deleter_db_env.cpp @@ -87,7 +87,7 @@ namespace mongo { exclusiveUpper, keyPattern), false, /*maxInclusive*/ - replSet? secondaryThrottle : false, + replset::replSet ? secondaryThrottle : false, serverGlobalParams.moveParanoia ? &removeSaver : NULL, true, /*fromMigrate*/ true); /*onlyRemoveOrphans*/ @@ -124,10 +124,10 @@ namespace mongo { } } - if (replSet) { + if (replset::replSet) { Timer elapsedTime; ReplTime lastOpApplied = cc().getLastOp().asDate(); - while (!opReplicatedEnough(lastOpApplied, + while (!replset::opReplicatedEnough(lastOpApplied, BSON("w" << "majority").firstElement())) { if (elapsedTime.seconds() >= 3600) { *errMsg = str::stream() << "rangeDeleter timed out after " diff --git a/src/mongo/db/repl/connections.h b/src/mongo/db/repl/connections.h index a32c77ed924..ec5eca84816 100644 --- a/src/mongo/db/repl/connections.h +++ b/src/mongo/db/repl/connections.h @@ -39,6 +39,7 @@ #include "mongo/db/repl/rs_config.h" namespace mongo { +namespace replset { /** here we keep a single connection (with reconnect) for a set of hosts, one each, and allow one user at a time per host. if in use already for that @@ -176,4 +177,5 @@ namespace mongo { // Keep trying to connect if we're not yet connected connect(); } -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/consensus.cpp b/src/mongo/db/repl/consensus.cpp index 86bcc17f9df..d6c5ae1883d 100644 --- a/src/mongo/db/repl/consensus.cpp +++ b/src/mongo/db/repl/consensus.cpp @@ -33,6 +33,7 @@ #include "mongo/db/repl/replset_commands.h" namespace mongo { +namespace replset { /** the first cmd called by a node seeking election and it's a basic sanity test: do any of the nodes it can reach know that it can't be the primary? @@ -357,7 +358,7 @@ namespace mongo { void Consensus::_multiCommand(BSONObj cmd, list<Target>& L) { verify( !rs.lockedByMe() ); - mongo::multiCommand(cmd, L); + multiCommand(cmd, L); } void Consensus::_electSelf() { @@ -487,4 +488,5 @@ namespace mongo { } } -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/consensus.h b/src/mongo/db/repl/consensus.h index becdabd64e1..87ce96c8bb3 100644 --- a/src/mongo/db/repl/consensus.h +++ b/src/mongo/db/repl/consensus.h @@ -37,6 +37,7 @@ #include "mongo/bson/bsonobj.h" namespace mongo { +namespace replset { class ReplSetImpl; struct Target; @@ -86,4 +87,5 @@ namespace mongo { OpTime getElectionTime() const { return _electionTime; } void setElectionTime(OpTime electionTime) { _electionTime = electionTime; } }; +} // namespace replset } // namespace mongo diff --git a/src/mongo/db/repl/health.cpp b/src/mongo/db/repl/health.cpp index 62c573a9428..420200c9a25 100644 --- a/src/mongo/db/repl/health.cpp +++ b/src/mongo/db/repl/health.cpp @@ -47,12 +47,10 @@ #include "mongo/util/ramlog.h" namespace mongo { +namespace replset { /* decls for connections.h */ ScopedConn::M& ScopedConn::_map = *(new ScopedConn::M()); mutex ScopedConn::mapMutex("ScopedConn::mapMutex"); -} - -namespace mongo { using namespace mongoutils::html; using namespace bson; @@ -468,4 +466,5 @@ namespace mongo { if( replSetBlind ) b.append("blind",true); // to avoid confusion if set...normally never set except for testing. } -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/health.h b/src/mongo/db/repl/health.h index 1159764f45e..64f48a8de21 100644 --- a/src/mongo/db/repl/health.h +++ b/src/mongo/db/repl/health.h @@ -34,10 +34,14 @@ #include "mongo/logger/tee.h" namespace mongo { +namespace replset { + + void fillRsLog(std::stringstream&); // ramlog used for replSet actions extern logger::Tee* rsLog; // helper function needed by member.cpp std::string ago(time_t t); -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/heartbeat.cpp b/src/mongo/db/repl/heartbeat.cpp index 3606b26a22a..245ca56806d 100644 --- a/src/mongo/db/repl/heartbeat.cpp +++ b/src/mongo/db/repl/heartbeat.cpp @@ -48,6 +48,7 @@ #include "mongo/util/ramlog.h" namespace mongo { +namespace replset { using namespace bson; @@ -257,7 +258,8 @@ namespace mongo { // member heartbeats are started in ReplSetImpl::initFromConfig } -} +} // namespace replset +} // namespace mongo /* todo: stop bg job and delete on removefromset diff --git a/src/mongo/db/repl/heartbeat.h b/src/mongo/db/repl/heartbeat.h index 3c16feb213d..fc8544863d4 100644 --- a/src/mongo/db/repl/heartbeat.h +++ b/src/mongo/db/repl/heartbeat.h @@ -31,9 +31,10 @@ #include <string> namespace mongo { - class BSONObj; +namespace replset { + /* throws */ bool requestHeartbeat(const std::string& setname, const std::string& fromHost, @@ -42,4 +43,5 @@ namespace mongo { int myConfigVersion, int& theirConfigVersion, bool checkEmpty = false); -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/heartbeat_info.cpp b/src/mongo/db/repl/heartbeat_info.cpp index e6bd6b92fb9..083cf31b969 100644 --- a/src/mongo/db/repl/heartbeat_info.cpp +++ b/src/mongo/db/repl/heartbeat_info.cpp @@ -33,6 +33,7 @@ #include "mongo/util/fail_point_service.h" namespace mongo { +namespace replset { unsigned int HeartbeatInfo::numPings; @@ -84,4 +85,5 @@ namespace mongo { } +} // namespace replset } // namespace mongo diff --git a/src/mongo/db/repl/heartbeat_info.h b/src/mongo/db/repl/heartbeat_info.h index 951a2a269d6..1718098dcbb 100644 --- a/src/mongo/db/repl/heartbeat_info.h +++ b/src/mongo/db/repl/heartbeat_info.h @@ -35,6 +35,7 @@ #include "mongo/util/concurrency/value.h" namespace mongo { +namespace replset { /* this is supposed to be just basic information on a member, and copy constructable. */ @@ -81,4 +82,5 @@ namespace mongo { unsigned _id; }; +} // namespace replset } // namespace mongo diff --git a/src/mongo/db/repl/initial_sync.cpp b/src/mongo/db/repl/initial_sync.cpp index 7f99106f25a..39d38eb431d 100644 --- a/src/mongo/db/repl/initial_sync.cpp +++ b/src/mongo/db/repl/initial_sync.cpp @@ -31,11 +31,10 @@ #include "mongo/db/repl/initial_sync.h" #include "mongo/db/repl/oplog.h" +#include "mongo/db/repl/replset_commands.h" #include "mongo/db/repl/rs.h" namespace mongo { - extern unsigned replSetForceInitialSyncFailure; - namespace replset { InitialSync::InitialSync(BackgroundSyncInterface *q) : SyncTail(q) {} diff --git a/src/mongo/db/repl/is_master.h b/src/mongo/db/repl/is_master.h index dc52d5b092b..26c32a5d15e 100644 --- a/src/mongo/db/repl/is_master.h +++ b/src/mongo/db/repl/is_master.h @@ -36,6 +36,7 @@ #include "mongo/util/mongoutils/str.h" namespace mongo { +namespace replset { /* We should not allow most operations when not the master also we report not master if we are "dead". @@ -76,4 +77,5 @@ namespace mongo { return ns[5] == 0 || ns[5] == '.'; } +} // namespace replset } // namespace mongo diff --git a/src/mongo/db/repl/manager.cpp b/src/mongo/db/repl/manager.cpp index c84d0c803e7..91b0f0eb15e 100644 --- a/src/mongo/db/repl/manager.cpp +++ b/src/mongo/db/repl/manager.cpp @@ -36,6 +36,7 @@ #include "mongo/db/client.h" namespace mongo { +namespace replset { /* check members OTHER THAN US to see if they think they are primary */ const Member * Manager::findOtherPrimary(bool& two) { @@ -288,4 +289,5 @@ namespace mongo { busyWithElectSelf = false; } -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/manager.h b/src/mongo/db/repl/manager.h index 0aae7357c5c..02b0c7ab7c7 100644 --- a/src/mongo/db/repl/manager.h +++ b/src/mongo/db/repl/manager.h @@ -32,6 +32,7 @@ #include "mongo/db/repl/server.h" namespace mongo { +namespace replset { class Member; class ReplSetImpl; @@ -56,4 +57,5 @@ namespace mongo { void msgCheckNewState(); }; -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/master_slave.cpp b/src/mongo/db/repl/master_slave.cpp index 4326a1d146c..30723f48a62 100644 --- a/src/mongo/db/repl/master_slave.cpp +++ b/src/mongo/db/repl/master_slave.cpp @@ -58,6 +58,7 @@ #include "mongo/util/exit.h" namespace mongo { +namespace replset { void pretouchOperation(const BSONObj& op); void pretouchN(vector<BSONObj>&, unsigned a, unsigned b); @@ -1308,5 +1309,5 @@ namespace mongo { } } +} // namespace replset } // namespace mongo - diff --git a/src/mongo/db/repl/master_slave.h b/src/mongo/db/repl/master_slave.h index 740a767cc4e..37adf66963a 100644 --- a/src/mongo/db/repl/master_slave.h +++ b/src/mongo/db/repl/master_slave.h @@ -40,10 +40,15 @@ */ namespace mongo { + namespace threadpool { + class ThreadPool; + } class Database; class OperationContext; +namespace replset { + // Main entry point for master/slave at startup time. void startMasterSlave(); @@ -54,16 +59,14 @@ namespace mongo { // Global variable that contains a std::string telling why master/slave halted extern const char *replAllDead; + extern const char *replInfo; + /* A replication exception */ class SyncException : public DBException { public: SyncException() : DBException( "sync exception" , 10001 ) {} }; - namespace threadpool { - class ThreadPool; - } - /* A Source is a source from which we can pull (replicate) data. stored in collection local.sources. @@ -182,4 +185,5 @@ namespace mongo { std::map< std::string, OpTime > _ignores; }; -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/member.cpp b/src/mongo/db/repl/member.cpp index 1b46e96cb56..5d4e6585caa 100644 --- a/src/mongo/db/repl/member.cpp +++ b/src/mongo/db/repl/member.cpp @@ -33,6 +33,7 @@ namespace mongo { +namespace replset { using namespace mongoutils::html; @@ -87,4 +88,5 @@ namespace mongo { return hbinfo().up() && (config().buildIndexes || !buildIndexes) && state().readable(); } +} // namespace replset } // namespace mongo diff --git a/src/mongo/db/repl/member.h b/src/mongo/db/repl/member.h index 5364672f1ee..d05c9fa4d2c 100644 --- a/src/mongo/db/repl/member.h +++ b/src/mongo/db/repl/member.h @@ -33,6 +33,7 @@ #include "mongo/util/concurrency/list.h" namespace mongo { +namespace replset { /* member of a replica set */ class Member : public List1<Member>::Base { @@ -74,4 +75,5 @@ namespace mongo { HeartbeatInfo _hbinfo; }; +} // namespace replset } // namespace mongo diff --git a/src/mongo/db/repl/member_state.h b/src/mongo/db/repl/member_state.h index d9c1801dd59..985d5592fa6 100644 --- a/src/mongo/db/repl/member_state.h +++ b/src/mongo/db/repl/member_state.h @@ -31,6 +31,7 @@ #pragma once namespace mongo { +namespace replset { /* @@ -92,4 +93,5 @@ namespace mongo { return ""; } -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/multicmd.h b/src/mongo/db/repl/multicmd.h index 02f53e2796e..6a95e7b6cbf 100644 --- a/src/mongo/db/repl/multicmd.h +++ b/src/mongo/db/repl/multicmd.h @@ -34,6 +34,7 @@ #include "mongo/util/background.h" namespace mongo { +namespace replset { struct Target { Target(std::string hostport) : toHost(hostport), ok(false) { } @@ -86,4 +87,5 @@ namespace mongo { (*i)->wait(); } } -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index 41c4ac7aacf..67588ead947 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -65,6 +65,7 @@ #include "mongo/util/startup_test.h" namespace mongo { +namespace replset { // cached copies of these...so don't rename them, drop them, etc.!!! static Database* localDB = NULL; @@ -772,4 +773,5 @@ namespace mongo { setNewOptime(lastOp[ "ts" ].date()); } } -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/oplog.h b/src/mongo/db/repl/oplog.h index 68714dea96d..675348bfc2e 100644 --- a/src/mongo/db/repl/oplog.h +++ b/src/mongo/db/repl/oplog.h @@ -29,12 +29,13 @@ #pragma once namespace mongo { - class BSONObj; class Database; class OperationContext; class OpTime; +namespace replset { + // These functions redefine the function for logOp(), // for either master/slave or replica sets. void oldRepl(); // master-slave @@ -112,4 +113,5 @@ namespace mongo { * Initializes the global OpTime with the value from the timestamp of the last oplog entry. */ void initOpTimeFromOplog(const std::string& oplogNS); -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/oplogreader.cpp b/src/mongo/db/repl/oplogreader.cpp index 6441d59e052..39b31de3d4d 100644 --- a/src/mongo/db/repl/oplogreader.cpp +++ b/src/mongo/db/repl/oplogreader.cpp @@ -45,6 +45,7 @@ #include "mongo/util/log.h" namespace mongo { +namespace replset { //number of readers created; // this happens when the source source changes, a reconfig/network-error or the cursor dies @@ -188,4 +189,5 @@ namespace mongo { tailingQuery(ns, query.done(), fields); } -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/oplogreader.h b/src/mongo/db/repl/oplogreader.h index 9121c466f66..14fc53edcd9 100644 --- a/src/mongo/db/repl/oplogreader.h +++ b/src/mongo/db/repl/oplogreader.h @@ -37,6 +37,8 @@ namespace mongo { extern const BSONObj reverseNaturalObj; // { $natural : -1 } + +namespace replset { /** * Authenticates conn using the server's cluster-membership credentials. * @@ -163,4 +165,5 @@ namespace mongo { bool passthroughHandshake(const mongo::OID& rid, const int f); }; -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/repl_reads_ok.cpp b/src/mongo/db/repl/repl_reads_ok.cpp index 6bec81ffbe9..ac2623eb709 100644 --- a/src/mongo/db/repl/repl_reads_ok.cpp +++ b/src/mongo/db/repl/repl_reads_ok.cpp @@ -36,6 +36,7 @@ #include "mongo/util/assert_util.h" namespace mongo { +namespace replset { /** we allow queries to SimpleSlave's */ void replVerifyReadsOk(const std::string& ns, const LiteParsedQuery* pq) { @@ -62,4 +63,5 @@ namespace mongo { } } +} // namespace replset } // namespace mongo diff --git a/src/mongo/db/repl/repl_reads_ok.h b/src/mongo/db/repl/repl_reads_ok.h index 492e8b55c78..825324d6a9c 100644 --- a/src/mongo/db/repl/repl_reads_ok.h +++ b/src/mongo/db/repl/repl_reads_ok.h @@ -32,10 +32,12 @@ namespace mongo { - class LiteParsedQuery; +namespace replset { + // Check to see if slaveOk reads are allowed, // based on read preference and query options void replVerifyReadsOk(const std::string& ns, const LiteParsedQuery* pq); -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/repl_set.h b/src/mongo/db/repl/repl_set.h index 5fadfa155c7..fea08ef3b5b 100644 --- a/src/mongo/db/repl/repl_set.h +++ b/src/mongo/db/repl/repl_set.h @@ -32,6 +32,7 @@ #include "mongo/util/concurrency/thread_pool.h" namespace mongo { +namespace replset { class ReplSet : public ReplSetImpl { public: @@ -96,4 +97,5 @@ namespace mongo { ReplSet(); }; +} // namespace replset } // namespace mongo diff --git a/src/mongo/db/repl/repl_set_health_poll_task.cpp b/src/mongo/db/repl/repl_set_health_poll_task.cpp index 4bd9f113654..3e2340e1fd6 100644 --- a/src/mongo/db/repl/repl_set_health_poll_task.cpp +++ b/src/mongo/db/repl/repl_set_health_poll_task.cpp @@ -37,6 +37,7 @@ #include "mongo/db/repl/rs_config.h" namespace mongo { +namespace replset { int ReplSetHealthPollTask::s_try_offset = 0; @@ -292,4 +293,5 @@ namespace mongo { mem.electionTime = info["electionTime"].Date(); } } +} // namespace replset } // namespace mongo diff --git a/src/mongo/db/repl/repl_set_health_poll_task.h b/src/mongo/db/repl/repl_set_health_poll_task.h index d05f45d4b73..6d239e6e193 100644 --- a/src/mongo/db/repl/repl_set_health_poll_task.h +++ b/src/mongo/db/repl/repl_set_health_poll_task.h @@ -36,6 +36,7 @@ #include "mongo/util/net/hostandport.h" namespace mongo { +namespace replset { /** * Poll every other set member to check its status. @@ -90,4 +91,5 @@ namespace mongo { time_t _timeout; }; +} // namespace replset } // namespace mongo diff --git a/src/mongo/db/repl/repl_set_impl.cpp b/src/mongo/db/repl/repl_set_impl.cpp index 75055a52c14..3d119df3b5b 100644 --- a/src/mongo/db/repl/repl_set_impl.cpp +++ b/src/mongo/db/repl/repl_set_impl.cpp @@ -30,6 +30,7 @@ #include "mongo/db/client.h" #include "mongo/db/catalog/database.h" +#include "mongo/db/commands/get_last_error.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/instance.h" #include "mongo/db/operation_context_impl.h" @@ -43,6 +44,7 @@ #include "mongo/util/exit.h" namespace mongo { +namespace replset { #ifdef MONGO_PLATFORM_64 const int ReplSetImpl::replWriterThreadCount = 16; const int ReplSetImpl::replPrefetcherThreadCount = 16; @@ -497,8 +499,6 @@ namespace { else _buildIndexes = true; } - extern BSONObj *getLastErrorDefault; - // @param reconf true if this is a reconfiguration and not an initial load of the configuration. // @return true if ok; throws if config really bad; false if config doesn't include self bool ReplSetImpl::initFromConfig(ReplSetConfig& c, bool reconf) { @@ -914,4 +914,5 @@ namespace { return true; } +} // namespace replset } // namespace mongo diff --git a/src/mongo/db/repl/repl_set_impl.h b/src/mongo/db/repl/repl_set_impl.h index 2e1c8d450b1..6b46d72d4ab 100644 --- a/src/mongo/db/repl/repl_set_impl.h +++ b/src/mongo/db/repl/repl_set_impl.h @@ -41,8 +41,10 @@ #include "mongo/util/concurrency/value.h" namespace mongo { - class Cloner; + +namespace replset { + struct FixUpInfo; class ReplSetCmdline; class ReplSetHealthPollTask; @@ -350,4 +352,5 @@ namespace mongo { static const char* _initialSyncFlagString; static const BSONObj _initialSyncFlag; }; +} // namespace replset } // namespace mongo diff --git a/src/mongo/db/repl/repl_settings.cpp b/src/mongo/db/repl/repl_settings.cpp index 474631dd5e8..306ad48902c 100644 --- a/src/mongo/db/repl/repl_settings.cpp +++ b/src/mongo/db/repl/repl_settings.cpp @@ -45,6 +45,7 @@ #include "mongo/s/write_ops/batched_command_request.h" namespace mongo { +namespace replset { // our config from command line etc. @@ -209,4 +210,5 @@ namespace mongo { OpCounterServerStatusSection replOpCounterServerStatusSection( "opcountersRepl", &replOpCounters ); -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/repl_settings.h b/src/mongo/db/repl/repl_settings.h index 3b7238b7c63..00ae52f9e78 100644 --- a/src/mongo/db/repl/repl_settings.h +++ b/src/mongo/db/repl/repl_settings.h @@ -36,6 +36,7 @@ namespace mongo { +namespace replset { bool anyReplEnabled(); @@ -96,4 +97,5 @@ namespace mongo { }; extern ReplSettings replSettings; -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/repl_start.cpp b/src/mongo/db/repl/repl_start.cpp index 2ca7650a6f9..54655160f88 100644 --- a/src/mongo/db/repl/repl_start.cpp +++ b/src/mongo/db/repl/repl_start.cpp @@ -39,6 +39,7 @@ #include "mongo/util/log.h" namespace mongo { +namespace replset { /** @param cfgString <setname>/<seedhost1>,<seedhost2> */ void parseReplsetCmdLine(const std::string& cfgString, @@ -108,4 +109,5 @@ namespace mongo { startMasterSlave(); } +} // namespace replset } // namespace mongo diff --git a/src/mongo/db/repl/repl_start.h b/src/mongo/db/repl/repl_start.h index 45643ad8ae1..1f621e08b0f 100644 --- a/src/mongo/db/repl/repl_start.h +++ b/src/mongo/db/repl/repl_start.h @@ -34,6 +34,7 @@ #include "mongo/util/net/hostandport.h" namespace mongo { +namespace replset { void parseReplsetCmdLine(const std::string& cfgString, std::string& setname, @@ -57,4 +58,5 @@ namespace mongo { // This function starts replica set or master/slave replication // based on command line/config parameters. void startReplication(); -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/replset_commands.cpp b/src/mongo/db/repl/replset_commands.cpp index 1ac6e0daec3..a6f91384b6d 100644 --- a/src/mongo/db/repl/replset_commands.cpp +++ b/src/mongo/db/repl/replset_commands.cpp @@ -43,6 +43,7 @@ using namespace bson; namespace mongo { +namespace replset { void checkMembersUpForConfigChange(const ReplSetConfig& cfg, BSONObjBuilder& result, bool initial); @@ -452,4 +453,5 @@ namespace mongo { } } cmdReplSetUpdatePosition; -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/replset_commands.h b/src/mongo/db/repl/replset_commands.h index e303ae13890..25dc174b945 100644 --- a/src/mongo/db/repl/replset_commands.h +++ b/src/mongo/db/repl/replset_commands.h @@ -35,8 +35,10 @@ #include "mongo/db/repl/rs.h" // replSet bool namespace mongo { +namespace replset { extern bool replSetBlind; + extern unsigned replSetForceInitialSyncFailure; /** * Base class for repl set commands. Checks basic things such if we're in @@ -73,4 +75,5 @@ namespace mongo { } }; +} // namespace replset } // namespace mongo diff --git a/src/mongo/db/repl/replset_web_handler.cpp b/src/mongo/db/repl/replset_web_handler.cpp index 0f4c9b96bca..631d4fa3643 100644 --- a/src/mongo/db/repl/replset_web_handler.cpp +++ b/src/mongo/db/repl/replset_web_handler.cpp @@ -36,10 +36,7 @@ #include "mongo/util/mongoutils/str.h" namespace mongo { - - extern void fillRsLog(std::stringstream&); - -namespace { +namespace replset { using namespace bson; using namespace mongoutils; @@ -129,5 +126,5 @@ namespace { } replSetHandler; -} // namespace -} // namespace mongo +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/resync.cpp b/src/mongo/db/repl/resync.cpp index 6db1ca4c6e2..dcd0ec414b5 100644 --- a/src/mongo/db/repl/resync.cpp +++ b/src/mongo/db/repl/resync.cpp @@ -33,6 +33,7 @@ #include "mongo/db/operation_context_impl.h" namespace mongo { +namespace replset { // operator requested resynchronization of replication (on a slave or secondary). {resync: 1} class CmdResync : public Command { @@ -117,4 +118,5 @@ namespace mongo { return true; } } cmdResync; -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/rs.cpp b/src/mongo/db/repl/rs.cpp index c58c8d6a661..f2cba63d3df 100644 --- a/src/mongo/db/repl/rs.cpp +++ b/src/mongo/db/repl/rs.cpp @@ -42,6 +42,7 @@ using namespace std; namespace mongo { +namespace replset { using namespace bson; @@ -56,7 +57,7 @@ namespace mongo { return theReplSet && theReplSet->isPrimary(); } - void replset::sethbmsg(const string& s, const int level) { + void sethbmsg(const string& s, const int level) { if (theReplSet) { theReplSet->sethbmsg(s, level); } @@ -204,5 +205,5 @@ namespace mongo { } } replIndexPrefetch; -} - +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/rs.h b/src/mongo/db/repl/rs.h index 7be93804842..41ceddfb081 100644 --- a/src/mongo/db/repl/rs.h +++ b/src/mongo/db/repl/rs.h @@ -63,6 +63,7 @@ */ namespace mongo { +namespace replset { extern bool replSet; // true if using repl sets extern class ReplSet *theReplSet; // null until initialized @@ -73,6 +74,7 @@ namespace mongo { // Main entry point for replica sets void startReplSets(ReplSetCmdline *replSetCmdline); + bool isCurrentlyAReplSetPrimary(); /** * does local authentication @@ -109,4 +111,5 @@ namespace mongo { return true; } -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/rs_base.h b/src/mongo/db/repl/rs_base.h index 61c85dbdd56..b8615f46bfd 100644 --- a/src/mongo/db/repl/rs_base.h +++ b/src/mongo/db/repl/rs_base.h @@ -33,6 +33,7 @@ #include "mongo/util/log.h" namespace mongo { +namespace replset { /** * most operations on a ReplSet object should be done while locked. that @@ -88,4 +89,5 @@ namespace mongo { bool lockedByMe() { return _lockedByMe.get(); } }; +} // namespace replset } // namespace mongo diff --git a/src/mongo/db/repl/rs_config.cpp b/src/mongo/db/repl/rs_config.cpp index 889e79466dd..0897e859136 100644 --- a/src/mongo/db/repl/rs_config.cpp +++ b/src/mongo/db/repl/rs_config.cpp @@ -46,6 +46,7 @@ using namespace bson; namespace mongo { +namespace replset { mongo::mutex ReplSetConfig::groupMx("RS tag group"); const int ReplSetConfig::DEFAULT_HB_TIMEOUT = 10; @@ -763,4 +764,5 @@ namespace mongo { _constructed = true; } -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/rs_config.h b/src/mongo/db/repl/rs_config.h index f25984a9ddf..1dab0945f8d 100644 --- a/src/mongo/db/repl/rs_config.h +++ b/src/mongo/db/repl/rs_config.h @@ -37,6 +37,7 @@ #include "mongo/util/net/hostandport.h" namespace mongo { +namespace replset { class Member; const std::string rsConfigNs = "local.system.replset"; @@ -328,4 +329,5 @@ namespace mongo { }; }; -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/rs_exception.h b/src/mongo/db/repl/rs_exception.h index 4b3fc643991..5e0b70aea71 100644 --- a/src/mongo/db/repl/rs_exception.h +++ b/src/mongo/db/repl/rs_exception.h @@ -31,6 +31,7 @@ #pragma once namespace mongo { +namespace replset { class VoteException : public std::exception { public: @@ -42,4 +43,5 @@ namespace mongo { const char * what() const throw () { return "RetryAfterSleepException"; } }; -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/rs_initialsync.cpp b/src/mongo/db/repl/rs_initialsync.cpp index ba09cf6f9c1..7e31ac3e94e 100644 --- a/src/mongo/db/repl/rs_initialsync.cpp +++ b/src/mongo/db/repl/rs_initialsync.cpp @@ -30,28 +30,31 @@ #include "mongo/db/repl/rs.h" +#include "mongo/bson/optime.h" #include "mongo/db/auth/authorization_manager.h" #include "mongo/db/auth/authorization_manager_global.h" #include "mongo/db/client.h" #include "mongo/db/cloner.h" #include "mongo/db/dbhelpers.h" +#include "mongo/db/operation_context_impl.h" +#include "mongo/db/operation_context_impl.h" +#include "mongo/db/pdfile.h" #include "mongo/db/repl/bgsync.h" +#include "mongo/db/repl/initial_sync.h" +#include "mongo/db/repl/initial_sync.h" #include "mongo/db/repl/member.h" #include "mongo/db/repl/oplog.h" #include "mongo/db/repl/oplogreader.h" -#include "mongo/bson/optime.h" #include "mongo/db/repl/repl_settings.h" // replSettings -#include "mongo/db/repl/initial_sync.h" -#include "mongo/db/operation_context_impl.h" +#include "mongo/db/structure/catalog/namespace_details.h" #include "mongo/util/mongoutils/str.h" namespace mongo { +namespace replset { using namespace mongoutils; using namespace bson; - void dropAllDatabasesExceptLocal(); - // add try/catch with sleep void isyncassert(const string& msg, bool expr) { @@ -491,4 +494,5 @@ namespace mongo { sethbmsg("initial sync done",0); } -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/rs_initiate.cpp b/src/mongo/db/repl/rs_initiate.cpp index b007c1fc8bf..0c5cb6b2a44 100644 --- a/src/mongo/db/repl/rs_initiate.cpp +++ b/src/mongo/db/repl/rs_initiate.cpp @@ -53,6 +53,7 @@ using namespace bson; using namespace mongoutils; namespace mongo { +namespace replset { /* called on a reconfig AND on initiate throws @@ -298,4 +299,5 @@ namespace mongo { } } cmdReplSetInitiate; -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/rs_rollback.cpp b/src/mongo/db/repl/rs_rollback.cpp index 1e5dc7dbe9e..24fc8fa5dd0 100644 --- a/src/mongo/db/repl/rs_rollback.cpp +++ b/src/mongo/db/repl/rs_rollback.cpp @@ -82,6 +82,7 @@ */ namespace mongo { +namespace replset { using namespace bson; @@ -744,4 +745,5 @@ namespace mongo { return 0; } -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/rs_sync.cpp b/src/mongo/db/repl/rs_sync.cpp index 2ccd9456ff4..85ffc3f7c8f 100644 --- a/src/mongo/db/repl/rs_sync.cpp +++ b/src/mongo/db/repl/rs_sync.cpp @@ -56,6 +56,7 @@ #include "mongo/util/fail_point_service.h" namespace mongo { +namespace replset { using namespace bson; @@ -300,4 +301,5 @@ namespace mongo { changeState(MemberState::RS_RECOVERING); } } -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/state_box.h b/src/mongo/db/repl/state_box.h index 7a7a7b5663e..de9550e092a 100644 --- a/src/mongo/db/repl/state_box.h +++ b/src/mongo/db/repl/state_box.h @@ -33,6 +33,7 @@ #include "mongo/util/concurrency/rwlock.h" namespace mongo { +namespace replset { class Member; @@ -91,4 +92,5 @@ namespace mongo { RWLock m; SP sp; }; +} // namespace replset } // namespace mongo diff --git a/src/mongo/db/repl/sync.cpp b/src/mongo/db/repl/sync.cpp index 6ad56531f80..ce78d279d8e 100644 --- a/src/mongo/db/repl/sync.cpp +++ b/src/mongo/db/repl/sync.cpp @@ -42,6 +42,7 @@ #include "mongo/util/log.h" namespace mongo { +namespace replset { void Sync::setHostname(const string& hostname) { hn = hostname; @@ -135,4 +136,5 @@ namespace mongo { return true; } } -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/sync.h b/src/mongo/db/repl/sync.h index 18ecaa63e54..fc1addcfafa 100644 --- a/src/mongo/db/repl/sync.h +++ b/src/mongo/db/repl/sync.h @@ -33,9 +33,10 @@ #include "mongo/db/jsobj.h" namespace mongo { - class Database; +namespace replset { + class Sync { protected: std::string hn; @@ -51,4 +52,5 @@ namespace mongo { void setHostname(const std::string& hostname); }; -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/sync_source_feedback.cpp b/src/mongo/db/repl/sync_source_feedback.cpp index 03c243683b4..b4d7e16af65 100644 --- a/src/mongo/db/repl/sync_source_feedback.cpp +++ b/src/mongo/db/repl/sync_source_feedback.cpp @@ -40,6 +40,7 @@ #include "mongo/db/operation_context_impl.h" namespace mongo { +namespace replset { // used in replAuthenticate static const BSONObj userReplQuery = fromjson("{\"user\":\"repl\"}"); @@ -286,4 +287,5 @@ namespace mongo { } cc().shutdown(); } -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/sync_source_feedback.h b/src/mongo/db/repl/sync_source_feedback.h index ba1fe483e45..8e7587382ca 100644 --- a/src/mongo/db/repl/sync_source_feedback.h +++ b/src/mongo/db/repl/sync_source_feedback.h @@ -35,6 +35,7 @@ #include "mongo/util/background.h" namespace mongo { +namespace replset { class Member; @@ -118,4 +119,5 @@ namespace mongo { // used to indicate a connection change which has not yet been shook on bool _handshakeNeeded; }; -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/write_concern.cpp b/src/mongo/db/repl/write_concern.cpp index a1d2481cc5d..ed7b2f09250 100644 --- a/src/mongo/db/repl/write_concern.cpp +++ b/src/mongo/db/repl/write_concern.cpp @@ -33,6 +33,7 @@ #include "mongo/db/auth/authorization_session.h" #include "mongo/db/auth/user_name.h" #include "mongo/db/client.h" +#include "mongo/db/commands/fsync.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/instance.h" #include "mongo/db/repl/is_master.h" @@ -43,10 +44,7 @@ #define REPLDEBUG(x) namespace mongo { - - // this is defined in fsync.cpp - // need to figure out where to put for real - bool lockedForWriting(); +namespace replset { using namespace mongoutils; @@ -367,4 +365,5 @@ namespace mongo { unsigned getSlaveCount() { return slaveTracking.getSlaveCount(); } -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/repl/write_concern.h b/src/mongo/db/repl/write_concern.h index 9c9aab87dc9..b9ec0b1ce8c 100644 --- a/src/mongo/db/repl/write_concern.h +++ b/src/mongo/db/repl/write_concern.h @@ -38,9 +38,10 @@ */ namespace mongo { - class CurOp; +namespace replset { + bool updateSlaveLocations(BSONArray optimes); void updateSlaveLocation( CurOp& curop, const char * oplog_ns , OpTime lastOp ); @@ -56,4 +57,5 @@ namespace mongo { void resetSlaveCache(); unsigned getSlaveCount(); -} +} // namespace replset +} // namespace mongo diff --git a/src/mongo/db/restapi.cpp b/src/mongo/db/restapi.cpp index 4ddf39ff3e2..ea03837d429 100644 --- a/src/mongo/db/restapi.cpp +++ b/src/mongo/db/restapi.cpp @@ -50,7 +50,6 @@ namespace mongo { - extern const char *replInfo; bool getInitialSyncCompleted(); using namespace bson; @@ -278,16 +277,17 @@ namespace mongo { ss << "# databases: " << dbHolder().sizeInfo() << '\n'; ss << "# Cursors: " << ClientCursor::totalOpen() << '\n'; ss << "replication: "; - if( *replInfo ) - ss << "\nreplInfo: " << replInfo << "\n\n"; - if( replSet ) { - ss << a("", "see replSetGetStatus link top of page") << "--replSet </a>" << replSettings.replSet; + if (*replset::replInfo) + ss << "\nreplInfo: " << replset::replInfo << "\n\n"; + if (replset::replSet) { + ss << a("", "see replSetGetStatus link top of page") << "--replSet </a>" + << replset::replSettings.replSet; } - if ( replAllDead ) - ss << "\n<b>replication replAllDead=" << replAllDead << "</b>\n"; + if (replset::replAllDead) + ss << "\n<b>replication replAllDead=" << replset::replAllDead << "</b>\n"; else { - ss << "\nmaster: " << replSettings.master << '\n'; - ss << "slave: " << replSettings.slave << '\n'; + ss << "\nmaster: " << replset::replSettings.master << '\n'; + ss << "slave: " << replset::replSettings.slave << '\n'; ss << '\n'; } diff --git a/src/mongo/db/ttl.cpp b/src/mongo/db/ttl.cpp index f1d7e9cd8e2..2572b5ff1a2 100644 --- a/src/mongo/db/ttl.cpp +++ b/src/mongo/db/ttl.cpp @@ -67,7 +67,7 @@ namespace mongo { void doTTLForDB( const string& dbName ) { - if ( !isMasterNs( dbName.c_str() ) ) + if (!replset::isMasterNs(dbName.c_str())) return; vector<BSONObj> indexes; @@ -122,7 +122,7 @@ namespace mongo { continue; } - if ( !isMasterNs( dbName.c_str() ) ) { + if (!replset::isMasterNs(dbName.c_str())) { // we've stepped down since we started this function, // so we should stop working as we only do deletes on the primary break; @@ -166,7 +166,7 @@ namespace mongo { } // if part of replSet but not in a readable state (e.g. during initial sync), skip. - if ( theReplSet && !theReplSet->state().readable() ) + if (replset::theReplSet && !replset::theReplSet->state().readable()) continue; set<string> dbs; diff --git a/src/mongo/db/write_concern.cpp b/src/mongo/db/write_concern.cpp index ee09a8bd933..596a582595f 100644 --- a/src/mongo/db/write_concern.cpp +++ b/src/mongo/db/write_concern.cpp @@ -53,8 +53,8 @@ namespace mongo { } const bool isConfigServer = serverGlobalParams.configsvr; - const bool isMasterSlaveNode = anyReplEnabled() && !theReplSet; - const bool isReplSetNode = anyReplEnabled() && theReplSet; + const bool isMasterSlaveNode = replset::anyReplEnabled() && !replset::theReplSet; + const bool isReplSetNode = replset::anyReplEnabled() && replset::theReplSet; if ( isConfigServer || ( !isMasterSlaveNode && !isReplSetNode ) ) { @@ -167,12 +167,12 @@ namespace mongo { return Status::OK(); } - if ( !anyReplEnabled() || serverGlobalParams.configsvr ) { + if (!replset::anyReplEnabled() || serverGlobalParams.configsvr) { // no replication check needed (validated above) return Status::OK(); } - const bool isMasterSlaveNode = anyReplEnabled() && !theReplSet; + const bool isMasterSlaveNode = replset::anyReplEnabled() && !replset::theReplSet; if ( writeConcern.wMode == "majority" && isMasterSlaveNode ) { // with master/slave, majority is equivalent to w=1 return Status::OK(); @@ -189,11 +189,11 @@ namespace mongo { while ( 1 ) { if ( writeConcern.wNumNodes > 0 ) { - if ( opReplicatedEnough( replOpTime, writeConcern.wNumNodes ) ) { + if (replset::opReplicatedEnough(replOpTime, writeConcern.wNumNodes)) { break; } } - else if ( opReplicatedEnough( replOpTime, writeConcern.wMode ) ) { + else if (replset::opReplicatedEnough(replOpTime, writeConcern.wMode)) { break; } @@ -217,7 +217,7 @@ namespace mongo { } // Add stats - result->writtenTo = getHostsWrittenTo( replOpTime ); + result->writtenTo = replset::getHostsWrittenTo(replOpTime); result->wTime = gleTimerHolder.recordMillis(); return replStatus; diff --git a/src/mongo/dbtests/framework_options.cpp b/src/mongo/dbtests/framework_options.cpp index c2d67621dd6..044fb8f1cb3 100644 --- a/src/mongo/dbtests/framework_options.cpp +++ b/src/mongo/dbtests/framework_options.cpp @@ -191,7 +191,7 @@ namespace mongo { storageGlobalParams.dur = true; } - replSettings.oplogSize = 10 * 1024 * 1024; + replset::replSettings.oplogSize = 10 * 1024 * 1024; DEV log() << "_DEBUG build" << endl; if( sizeof(void*)==4 ) diff --git a/src/mongo/dbtests/mock/mock_replica_set.cpp b/src/mongo/dbtests/mock/mock_replica_set.cpp index 2c1369f2004..571a30129a7 100644 --- a/src/mongo/dbtests/mock/mock_replica_set.cpp +++ b/src/mongo/dbtests/mock/mock_replica_set.cpp @@ -53,7 +53,7 @@ namespace mongo { MockConnRegistry::get()->addServer(mockServer); - ReplSetConfig::MemberCfg config; + replset::ReplSetConfig::MemberCfg config; config.h = HostAndPort(hostName); replConfig.insert(std::make_pair(hostName, config)); } @@ -110,7 +110,7 @@ namespace mongo { ReplConfigMap::const_iterator iter = _replConfig.find(hostAndPort); fassert(16578, iter != _replConfig.end()); - const ReplSetConfig::MemberCfg& config = iter->second; + const replset::ReplSetConfig::MemberCfg& config = iter->second; fassert(16579, !config.hidden && config.priority > 0 && !config.arbiterOnly); _primaryHost = hostAndPort; @@ -201,7 +201,7 @@ namespace mongo { builder.append("primary", getPrimary()); - const ReplSetConfig::MemberCfg& replConfig = configIter->second; + const replset::ReplSetConfig::MemberCfg& replConfig = configIter->second; if (replConfig.arbiterOnly) { builder.append("arbiterOnly", true); } @@ -242,13 +242,13 @@ namespace mongo { int MockReplicaSet::getState(const std::string& hostAndPort) const { if (_replConfig.count(hostAndPort) < 1) { - return static_cast<int>(MemberState::RS_SHUNNED); + return static_cast<int>(replset::MemberState::RS_SHUNNED); } else if (hostAndPort == getPrimary()) { - return static_cast<int>(MemberState::RS_PRIMARY); + return static_cast<int>(replset::MemberState::RS_PRIMARY); } else { - return static_cast<int>(MemberState::RS_SECONDARY); + return static_cast<int>(replset::MemberState::RS_SECONDARY); } } diff --git a/src/mongo/dbtests/mock/mock_replica_set.h b/src/mongo/dbtests/mock/mock_replica_set.h index 6c29af730ed..fe29f791e88 100644 --- a/src/mongo/dbtests/mock/mock_replica_set.h +++ b/src/mongo/dbtests/mock/mock_replica_set.h @@ -49,7 +49,7 @@ namespace mongo { */ class MockReplicaSet { public: - typedef std::map<std::string, ReplSetConfig::MemberCfg> ReplConfigMap; + typedef std::map<std::string, replset::ReplSetConfig::MemberCfg> ReplConfigMap; /** * Creates a mock replica set and automatically mocks the isMaster diff --git a/src/mongo/dbtests/replsettests.cpp b/src/mongo/dbtests/replsettests.cpp index 228201d2eef..3742e5683b7 100644 --- a/src/mongo/dbtests/replsettests.cpp +++ b/src/mongo/dbtests/replsettests.cpp @@ -45,18 +45,13 @@ #include "mongo/dbtests/dbtests.h" #include "mongo/util/time_support.h" - -namespace mongo { - void createOplog(); -} - namespace ReplSetTests { const int replWriterThreadCount(32); const int replPrefetcherThreadCount(32); - class ReplSetTest : public ReplSet { - ReplSetConfig *_config; - ReplSetConfig::MemberCfg *_myConfig; - replset::BackgroundSyncInterface *_syncTail; + class ReplSetTest : public mongo::replset::ReplSet { + mongo::replset::ReplSetConfig *_config; + mongo::replset::ReplSetConfig::MemberCfg *_myConfig; + mongo::replset::BackgroundSyncInterface *_syncTail; public: static const int replWriterThreadCount; static const int replPrefetcherThreadCount; @@ -65,7 +60,7 @@ namespace ReplSetTests { ret->init(); // we need to get() the BackgroundSync so that it has its s_instance initialized // since applyOps() eventually calls notify() which makes use of the s_instance - replset::BackgroundSync::get(); + mongo::replset::BackgroundSync::get(); return ret.release(); } virtual ~ReplSetTest() { @@ -81,10 +76,10 @@ namespace ReplSetTests { virtual bool tryToGoLiveAsASecondary(OpTime& minvalid) { return false; } - virtual const ReplSetConfig& config() { + virtual const mongo::replset::ReplSetConfig& config() { return *_config; } - virtual const ReplSetConfig::MemberCfg& myConfig() { + virtual const mongo::replset::ReplSetConfig::MemberCfg& myConfig() { return *_myConfig; } virtual bool buildIndexes() const { @@ -100,8 +95,9 @@ namespace ReplSetTests { void init() { BSONArrayBuilder members; members.append(BSON("_id" << 0 << "host" << "host1")); - _config = ReplSetConfig::make(BSON("_id" << "foo" << "members" << members.arr())); - _myConfig = new ReplSetConfig::MemberCfg(); + _config = mongo::replset::ReplSetConfig::make(BSON("_id" << "foo" + << "members" << members.arr())); + _myConfig = new mongo::replset::ReplSetConfig::MemberCfg(); } }; @@ -120,7 +116,7 @@ namespace ReplSetTests { virtual void consume() { _queue.pop(); } - virtual Member* getSyncTarget() { + virtual mongo::replset::Member* getSyncTarget() { return 0; } void addDoc(BSONObj doc) { @@ -190,9 +186,9 @@ namespace ReplSetTests { db->dropCollection(&txn, ns()); } static void setup() { - replSettings.replSet = "foo"; - replSettings.oplogSize = 5 * 1024 * 1024; - createOplog(); + mongo::replset::replSettings.replSet = "foo"; + mongo::replset::replSettings.oplogSize = 5 * 1024 * 1024; + mongo::replset::createOplog(); // setup background sync instance _bgsync = new BackgroundSyncTest(); @@ -204,8 +200,8 @@ namespace ReplSetTests { ReplSetTest *rst = ReplSetTest::make(); rst->setSyncTail(_bgsync); - delete theReplSet; - theReplSet = rst; + delete replset::theReplSet; + replset::theReplSet = rst; } }; @@ -363,7 +359,7 @@ namespace ReplSetTests { Client::Context ctx( _cappedNs ); OperationContextImpl txn; // in an annoying twist of api, returns true on failure - return !applyOperation_inlock(&txn, ctx.db(), op, true); + return !mongo::replset::applyOperation_inlock(&txn, ctx.db(), op, true); } void run() { @@ -371,7 +367,7 @@ namespace ReplSetTests { BSONObj op = updateFail(); - Sync s(""); + mongo::replset::Sync s(""); verify(!s.shouldRetry(op)); } }; @@ -531,7 +527,7 @@ namespace ReplSetTests { void run() { const int expected = 100; - theReplSet->syncSourceFeedback.ensureMe(); + replset::theReplSet->syncSourceFeedback.ensureMe(); drop(); addInserts(100); diff --git a/src/mongo/dbtests/repltests.cpp b/src/mongo/dbtests/repltests.cpp index 8d67b786c65..9f034cdaf18 100644 --- a/src/mongo/dbtests/repltests.cpp +++ b/src/mongo/dbtests/repltests.cpp @@ -58,11 +58,11 @@ namespace ReplTests { mutable OperationContextImpl _txn; public: Base() : _context( ns() ) { - oldRepl(); - replSettings.replSet = ""; - replSettings.oplogSize = 5 * 1024 * 1024; - replSettings.master = true; - createOplog(); + mongo::replset::oldRepl(); + mongo::replset::replSettings.replSet = ""; + mongo::replset::replSettings.oplogSize = 5 * 1024 * 1024; + mongo::replset::replSettings.master = true; + mongo::replset::createOplog(); Collection* c = _context.db()->getCollection( ns() ); if ( ! c ) { @@ -72,7 +72,7 @@ namespace ReplTests { } ~Base() { try { - replSettings.master = false; + mongo::replset::replSettings.master = false; deleteAll( ns() ); deleteAll( cllNS() ); } @@ -170,7 +170,7 @@ namespace ReplTests { BSONObjBuilder b; b.append("host", "localhost"); b.appendTimestamp("syncedTo", 0); - ReplSource a(b.obj()); + mongo::replset::ReplSource a(b.obj()); for( vector< BSONObj >::iterator i = ops.begin(); i != ops.end(); ++i ) { if ( 0 ) { mongo::unittest::log() << "op: " << *i << endl; @@ -1336,7 +1336,7 @@ namespace ReplTests { class DatabaseIgnorerBasic { public: void run() { - DatabaseIgnorer d; + mongo::replset::DatabaseIgnorer d; ASSERT( !d.ignoreAt( "a", OpTime( 4, 0 ) ) ); d.doIgnoreUntilAfter( "a", OpTime( 5, 0 ) ); ASSERT( d.ignoreAt( "a", OpTime( 4, 0 ) ) ); @@ -1352,7 +1352,7 @@ namespace ReplTests { class DatabaseIgnorerUpdate { public: void run() { - DatabaseIgnorer d; + mongo::replset::DatabaseIgnorer d; d.doIgnoreUntilAfter( "a", OpTime( 5, 0 ) ); d.doIgnoreUntilAfter( "a", OpTime( 6, 0 ) ); ASSERT( d.ignoreAt( "a", OpTime( 5, 5 ) ) ); @@ -1373,7 +1373,7 @@ namespace ReplTests { class ReplSetMemberCfgEquality : public Base { public: void run() { - ReplSetConfig::MemberCfg m1, m2; + mongo::replset::ReplSetConfig::MemberCfg m1, m2; verify(m1 == m2); m1.tags["x"] = "foo"; verify(m1 != m2); @@ -1388,10 +1388,10 @@ namespace ReplTests { } }; - class SyncTest : public Sync { + class SyncTest : public mongo::replset::Sync { public: bool returnEmpty; - SyncTest() : Sync(""), returnEmpty(false) {} + SyncTest() : mongo::replset::Sync(""), returnEmpty(false) {} virtual ~SyncTest() {} virtual BSONObj getMissingDoc(Database* db, const BSONObj& o) { if (returnEmpty) { @@ -1410,7 +1410,7 @@ namespace ReplTests { // this should fail because we can't connect try { - Sync badSource("localhost:123"); + mongo::replset::Sync badSource("localhost:123"); badSource.getMissingDoc(db(), o); } catch (DBException&) { diff --git a/src/mongo/s/d_migrate.cpp b/src/mongo/s/d_migrate.cpp index 06ff9ccb9db..aa485c4e343 100644 --- a/src/mongo/s/d_migrate.cpp +++ b/src/mongo/s/d_migrate.cpp @@ -805,15 +805,15 @@ namespace mongo { // if we do a w=2 after every write bool secondaryThrottle = cmdObj["secondaryThrottle"].trueValue(); if ( secondaryThrottle ) { - if ( theReplSet ) { - if ( theReplSet->config().getMajority() <= 1 ) { + if (replset::theReplSet) { + if (replset::theReplSet->config().getMajority() <= 1) { secondaryThrottle = false; warning() << "not enough nodes in set to use secondaryThrottle: " - << " majority: " << theReplSet->config().getMajority() + << " majority: " << replset::theReplSet->config().getMajority() << endl; } } - else if ( !anyReplEnabled() ) { + else if (!replset::anyReplEnabled() ) { secondaryThrottle = false; warning() << "secondaryThrottle selected but no replication" << endl; } @@ -1602,7 +1602,8 @@ namespace mongo { verify( ! min.isEmpty() ); verify( ! max.isEmpty() ); - replSetMajorityCount = theReplSet ? theReplSet->config().getMajority() : 0; + replSetMajorityCount = replset::theReplSet ? + replset::theReplSet->config().getMajority() : 0; log() << "starting receiving-end of migration of chunk " << min << " -> " << max << " for collection " << ns << " from " << from @@ -1672,8 +1673,8 @@ namespace mongo { } // make sure to create index on secondaries as well - logOp( txn, "i", db->getSystemIndexesName().c_str(), idx, - NULL, NULL, true /* fromMigrate */ ); + replset::logOp(txn, "i", db->getSystemIndexesName().c_str(), idx, + NULL, NULL, true /* fromMigrate */); } timing.done(1); @@ -1770,7 +1771,8 @@ namespace mongo { clonedBytes += o.objsize(); if ( secondaryThrottle && thisTime > 0 ) { - if ( ! waitForReplication( cc().getLastOp(), 2, 60 /* seconds to wait */ ) ) { + if (!replset::waitForReplication(cc().getLastOp(), + 2, 60 /* seconds to wait */)) { warning() << "secondaryThrottle on, but doc insert timed out after 60 seconds, continuing" << endl; } } @@ -1813,7 +1815,7 @@ namespace mongo { return; } - if ( opReplicatedEnough( lastOpApplied ) ) + if (opReplicatedEnough(lastOpApplied)) break; if ( i > 100 ) { @@ -2025,7 +2027,7 @@ namespace mongo { // if replication is on, try to force enough secondaries to catch up // TODO opReplicatedEnough should eventually honor priorities and geo-awareness // for now, we try to replicate to a sensible number of secondaries - return mongo::opReplicatedEnough( lastOpApplied , replSetMajorityCount ); + return replset::opReplicatedEnough(lastOpApplied, replSetMajorityCount); } bool flushPendingWrites( const ReplTime& lastOpApplied ) { @@ -2228,7 +2230,7 @@ namespace mongo { migrateStatus.shardKeyPattern = keya.getOwned(); } - if ( migrateStatus.secondaryThrottle && ! anyReplEnabled() ) { + if (migrateStatus.secondaryThrottle && ! replset::anyReplEnabled()) { warning() << "secondaryThrottle asked for, but not replication" << endl; migrateStatus.secondaryThrottle = false; } diff --git a/src/mongo/s/d_state.cpp b/src/mongo/s/d_state.cpp index 7f7e602b59c..c5c36de789e 100644 --- a/src/mongo/s/d_state.cpp +++ b/src/mongo/s/d_state.cpp @@ -982,7 +982,7 @@ namespace mongo { } // we can run on a slave up to here - if (!_isMaster()) { + if (!replset::_isMaster()) { result.append( "errmsg" , "not master" ); result.append( "note" , "from post init in setShardVersion" ); return false; @@ -1259,7 +1259,7 @@ namespace mongo { if ( ! shardingState.enabled() ) return true; - if ( ! isMasterNs( ns.c_str() ) ) { + if (!replset::isMasterNs(ns.c_str())) { // right now connections to secondaries aren't versioned at all return true; } diff --git a/src/mongo/tools/oplog.cpp b/src/mongo/tools/oplog.cpp index d8eedb42f2e..fc5bb95860f 100644 --- a/src/mongo/tools/oplog.cpp +++ b/src/mongo/tools/oplog.cpp @@ -53,7 +53,7 @@ public: toolInfoLog() << "going to connect" << std::endl; - OplogReader r; + replset::OplogReader r; r.setTailingQueryOptions( QueryOption_SlaveOk | QueryOption_AwaitData ); r.connect(mongoOplogGlobalParams.from); |