summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Milkie <milkie@10gen.com>2012-07-27 10:13:08 -0400
committerEric Milkie <milkie@10gen.com>2012-07-27 10:13:08 -0400
commit7542d7baa9f529a4dcf6bb7a0be162c8e6949607 (patch)
tree77d2c106af6f88091005ed037af8171081de2037
parent90fa91c352ffef46a4ae9b849e9a17b5ad3bac66 (diff)
downloadmongo-7542d7baa9f529a4dcf6bb7a0be162c8e6949607.tar.gz
SERVER-6512 ReplicaSetMonitor::_checkConnection does not check upper bounds for the indexes
Make sure to invalidate the cached _master index whenever the _nodes structure is modified. This is a short term fix - the long term is to not use indexes at all.
-rw-r--r--client/dbclient_rs.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/client/dbclient_rs.cpp b/client/dbclient_rs.cpp
index 6a4bf1dea63..be66bb451c4 100644
--- a/client/dbclient_rs.cpp
+++ b/client/dbclient_rs.cpp
@@ -225,6 +225,7 @@ namespace mongo {
HostAndPort ReplicaSetMonitor::getMaster() {
{
scoped_lock lk( _lock );
+ assert(_master < static_cast<int>(_nodes.size()));
if ( _master >= 0 && _nodes[_master].ok )
return _nodes[_master].addr;
}
@@ -233,6 +234,7 @@ namespace mongo {
scoped_lock lk( _lock );
uassert( 10009 , str::stream() << "ReplicaSetMonitor no master found for set: " << _name , _master >= 0 );
+ assert(_master < static_cast<int>(_nodes.size()));
return _nodes[_master].addr;
}
@@ -467,6 +469,10 @@ namespace mongo {
_nodes.push_back( Node( h , newConn ) );
}
+
+ // Invalidate the cached _master index since the _nodes structure has
+ // already been modified.
+ _master = -1;
}
@@ -552,7 +558,11 @@ namespace mongo {
if ( errorOccured && nodesOffset >= 0 ) {
scoped_lock lk( _lock );
- _nodes[nodesOffset].ok = false;
+
+ if (_checkConnMatch_inlock(conn, nodesOffset)) {
+ // Make sure _checkHosts didn't modify the _nodes structure
+ _nodes[nodesOffset].ok = false;
+ }
}
if ( changed && _hook )
@@ -572,6 +582,7 @@ namespace mongo {
if ( !checkAllSecondaries ) {
scoped_lock lk( _lock );
+ assert(_master < static_cast<int>(_nodes.size()));
if ( _master >= 0 ) {
/* Nothing else to do since another thread already
* found the _master
@@ -662,6 +673,7 @@ namespace mongo {
// first see if the current master is fine
if ( _master >= 0 ) {
+ assert(_master < static_cast<int>(_nodes.size()));
masterConn = _nodes[_master].conn;
}
}