summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@mongodb.com>2014-07-16 19:20:59 -0400
committerSpencer T Brody <spencer@mongodb.com>2014-07-18 14:47:12 -0400
commit4b12168d5c14f0177586eeda8b22fba433d6df1f (patch)
treea55e8de6ddf34ac4cb07fb6383865359524d2d31
parent7c9e21b95804fde5a4837c5aab47ab9c2e57a267 (diff)
downloadmongo-4b12168d5c14f0177586eeda8b22fba433d6df1f.tar.gz
SERVER-14550 Stop maintaining local.slaves
-rw-r--r--src/mongo/db/repl/repl_coordinator_legacy.cpp12
-rw-r--r--src/mongo/db/repl/write_concern.cpp75
-rw-r--r--src/mongo/db/repl/write_concern.h4
3 files changed, 10 insertions, 81 deletions
diff --git a/src/mongo/db/repl/repl_coordinator_legacy.cpp b/src/mongo/db/repl/repl_coordinator_legacy.cpp
index 89f2eb667e3..9f68a8a7116 100644
--- a/src/mongo/db/repl/repl_coordinator_legacy.cpp
+++ b/src/mongo/db/repl/repl_coordinator_legacy.cpp
@@ -385,16 +385,13 @@ namespace {
if (rid != getMyRID()) {
// TODO(spencer): Remove this invariant for backwards compatibility
invariant(!config.isEmpty());
- std::string oplogNs = getReplicationMode() == modeReplSet?
- "local.oplog.rs" : "local.oplog.$main";
// This is what updates the progress information used for satisfying write concern
- // and wakes up threads waiting for replication. It also updates the tracking for
- // maintaining local.slaves
- if (!updateSlaveTracking(BSON("_id" << rid), config, oplogNs, ts)) {
+ // and wakes up threads waiting for replication.
+ if (!updateSlaveTracking(BSON("_id" << rid), config, ts)) {
return Status(ErrorCodes::NodeNotFound,
str::stream() << "could not update node with _id: "
- << config["_id"].Int()
- << " because it cannot be found in current ReplSetConfig");
+ << config["_id"].Int()
+ << " because it cannot be found in current ReplSetConfig");
}
}
@@ -403,7 +400,6 @@ namespace {
LOG(2) << "Updating our knowledge of the replication progress for node with RID " <<
rid << " to be at optime " << ts;
_slaveOpTimeMap[rid] = ts;
-
}
if (getReplicationMode() == modeReplSet && !getCurrentMemberState().primary()) {
diff --git a/src/mongo/db/repl/write_concern.cpp b/src/mongo/db/repl/write_concern.cpp
index 079a16fd281..adf1dc9f35f 100644
--- a/src/mongo/db/repl/write_concern.cpp
+++ b/src/mongo/db/repl/write_concern.cpp
@@ -38,7 +38,6 @@
#include "mongo/db/instance.h"
#include "mongo/db/repl/repl_coordinator_global.h"
#include "mongo/db/operation_context_impl.h"
-#include "mongo/util/background.h"
#include "mongo/util/mongoutils/str.h"
//#define REPLDEBUG(x) log() << "replBlock: " << x << endl;
@@ -49,17 +48,15 @@ namespace repl {
using namespace mongoutils;
- class SlaveTracking : public BackgroundJob { // SERVER-4328 todo review
+ class SlaveTracking { // SERVER-4328 todo review
public:
- string name() const { return "SlaveTracking"; }
struct Ident {
- Ident(const BSONObj& r, const BSONObj& config, const string& n) {
+ Ident(const BSONObj& r, const BSONObj& config) {
BSONObjBuilder b;
b.appendElements( r );
b.append( "config" , config );
- b.append( "ns" , n );
obj = b.obj();
}
@@ -71,76 +68,24 @@ namespace repl {
};
SlaveTracking() : _mutex("SlaveTracking") {
- _dirty = false;
- _started = false;
- _currentlyUpdatingCache = false;
- }
-
- void run() {
- Client::initThread( "slaveTracking" );
- cc().getAuthorizationSession()->grantInternalAuthorization();
- while ( ! inShutdown() ) {
- sleepsecs( 1 );
-
- if ( ! _dirty )
- continue;
-
- if ( inShutdown() )
- return;
-
- OperationContextImpl txn;
-
- if ( lockedForWriting() ) {
- // note: there is still a race here
- // since we could call fsyncLock between this and the last lock
- RARELY log() << "can't update local.slaves because locked for writing" << endl;
- continue;
- }
-
- list< pair<BSONObj,BSONObj> > todo;
-
- {
- scoped_lock mylk(_mutex);
-
- for ( map<Ident,OpTime>::iterator i=_slaves.begin(); i!=_slaves.end(); i++ ) {
- BSONObjBuilder temp;
- temp.appendTimestamp( "syncedTo" , i->second.asDate() );
- todo.push_back( pair<BSONObj,BSONObj>( i->first.obj.getOwned() ,
- BSON( "$set" << temp.obj() ).getOwned() ) );
- }
- _dirty = false;
- }
-
- _currentlyUpdatingCache = true;
- for ( list< pair<BSONObj,BSONObj> >::iterator i=todo.begin(); i!=todo.end(); i++ ) {
- DBDirectClient(&txn).update("local.slaves", i->first, i->second, true);
- }
- _currentlyUpdatingCache = false;
-
- _threadsWaitingForReplication.notify_all();
- }
}
void reset() {
- if ( _currentlyUpdatingCache )
- return;
scoped_lock mylk(_mutex);
_slaves.clear();
}
- bool update( const BSONObj& rid , const BSONObj config , const string& ns , OpTime last ) {
+ bool update(const BSONObj& rid, const BSONObj config, OpTime last) {
REPLDEBUG( config << " " << rid << " " << ns << " " << last );
- Ident ident(rid, config, ns);
+ Ident ident(rid, config);
scoped_lock mylk(_mutex);
if (last > _slaves[ident]) {
_slaves[ident] = last;
- _dirty = true;
// update write concern tags if this node is primary
- // TODO(spencer): Move this logic up into the ReplicationCoordinator
if (theReplSet && theReplSet->isPrimary()) {
const Member* mem = theReplSet->findById(ident.obj["config"]["_id"].Int());
if (!mem) {
@@ -150,12 +95,6 @@ namespace repl {
cfg.updateGroups(last);
}
- if ( ! _started ) {
- // start background thread here since we definitely need it
- _started = true;
- go();
- }
-
_threadsWaitingForReplication.notify_all();
}
return true;
@@ -284,17 +223,13 @@ namespace repl {
boost::condition _threadsWaitingForReplication;
map<Ident,OpTime> _slaves;
- bool _dirty;
- bool _started;
- bool _currentlyUpdatingCache; // this is not thread safe, but ok for our purposes
} slaveTracking;
bool updateSlaveTracking(const BSONObj& rid,
const BSONObj config,
- const string& ns,
OpTime last) {
- return slaveTracking.update(rid, config, ns, last);
+ return slaveTracking.update(rid, config, last);
}
bool opReplicatedEnough( OpTime op , BSONElement w ) {
diff --git a/src/mongo/db/repl/write_concern.h b/src/mongo/db/repl/write_concern.h
index 2c9b9fde91e..2ac3f23ab1a 100644
--- a/src/mongo/db/repl/write_concern.h
+++ b/src/mongo/db/repl/write_concern.h
@@ -43,14 +43,12 @@ namespace mongo {
namespace repl {
/**
- * This updates the slave tracking map, as well as updates the GhostSlave cache (used for
- * maintaining the local.slaves collection), and updates the tag groups.
+ * This updates the slave tracking map and updates the tag groups.
*
* @returns false when the member cannot be found
*/
bool updateSlaveTracking(const BSONObj& rid,
const BSONObj config,
- const string& ns,
OpTime last);
/** @return true if op has made it to w servers */