summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordwight <dwight@10gen.com>2011-04-30 11:53:59 -0400
committerdwight <dwight@10gen.com>2011-04-30 11:53:59 -0400
commitd04022b31f5d8c8b79386c4fc58946a7324e8643 (patch)
tree8a54909afc8a2e46d7bf695b96cd47bb29a3e9e2
parent2221ad4eea656016858a51cc8ced07597683d15a (diff)
parentf46e1873013ba477896148f385dc3656d444df1d (diff)
downloadmongo-d04022b31f5d8c8b79386c4fc58946a7324e8643.tar.gz
Merge branch 'master' of github.com:mongodb/mongo
-rw-r--r--client/dbclient.h2
-rw-r--r--client/dbclient_rs.cpp28
-rw-r--r--client/dbclient_rs.h2
-rw-r--r--client/examples/clientTest.cpp29
-rw-r--r--db/db.cpp15
-rw-r--r--db/dur_journal.cpp5
-rw-r--r--db/repl/rs.cpp10
-rw-r--r--db/repl/rs_sync.cpp19
-rw-r--r--jstests/replsets/sync1.js5
-rw-r--r--jstests/sharding/migrateBig.js2
-rw-r--r--jstests/sharding/shard3.js9
-rw-r--r--jstests/sharding/sync7.js2
-rw-r--r--jstests/slowNightly/sharding_balance1.js3
-rw-r--r--s/balance.cpp62
-rw-r--r--s/config.cpp6
-rw-r--r--s/d_migrate.cpp1
-rw-r--r--s/strategy_shard.cpp4
-rw-r--r--shell/mongo_vstudio.cpp16
-rw-r--r--shell/utils_sh.js16
-rw-r--r--tools/sniffer.cpp3
-rw-r--r--util/file.h8
-rw-r--r--util/message.cpp45
-rw-r--r--util/version.cpp2
23 files changed, 200 insertions, 94 deletions
diff --git a/client/dbclient.h b/client/dbclient.h
index 5d6d87cc129..03030a3c6be 100644
--- a/client/dbclient.h
+++ b/client/dbclient.h
@@ -884,7 +884,7 @@ namespace mongo {
*/
bool isFailed() const { return _failed; }
- MessagingPort& port() { return *p; }
+ MessagingPort& port() { assert(p); return *p; }
string toStringLong() const {
stringstream ss;
diff --git a/client/dbclient_rs.cpp b/client/dbclient_rs.cpp
index 1fb8e755e47..217c38804a5 100644
--- a/client/dbclient_rs.cpp
+++ b/client/dbclient_rs.cpp
@@ -74,7 +74,7 @@ namespace mongo {
ReplicaSetMonitor::ReplicaSetMonitor( const string& name , const vector<HostAndPort>& servers )
- : _lock( "ReplicaSetMonitor instance" ) , _checkConnectionLock( "ReplicaSetMonitor check connection lock" ), _name( name ) , _master(-1) {
+ : _lock( "ReplicaSetMonitor instance" ) , _checkConnectionLock( "ReplicaSetMonitor check connection lock" ), _name( name ) , _master(-1), _nextSlave(0) {
uassert( 13642 , "need at least 1 node for a replica set" , servers.size() > 0 );
@@ -221,19 +221,19 @@ namespace mongo {
}
HostAndPort ReplicaSetMonitor::getSlave() {
- int x = rand() % _nodes.size();
+
{
scoped_lock lk( _lock );
for ( unsigned i=0; i<_nodes.size(); i++ ) {
- int p = ( i + x ) % _nodes.size();
- if ( p == _master )
+ _nextSlave = ( _nextSlave + 1 ) % _nodes.size();
+ if ( _nextSlave == _master )
continue;
- if ( _nodes[p].ok )
- return _nodes[p].addr;
+ if ( _nodes[ _nextSlave ].ok )
+ return _nodes[ _nextSlave ].addr;
}
}
- return _nodes[0].addr;
+ return _nodes[ 0 ].addr;
}
/**
@@ -535,7 +535,7 @@ namespace mongo {
return checkSlave()->query(ns,query,nToReturn,nToSkip,fieldsToReturn,queryOptions,batchSize);
}
catch ( DBException &e ) {
- log() << "can't query replica set slave: " << _slaveHost << causedBy( e ) << endl;
+ LOG(1) << "can't query replica set slave " << i << " : " << _slaveHost << causedBy( e ) << endl;
}
}
}
@@ -552,8 +552,8 @@ namespace mongo {
try {
return checkSlave()->findOne(ns,query,fieldsToReturn,queryOptions);
}
- catch ( DBException & ) {
- LOG(1) << "can't query replica set slave: " << _slaveHost << endl;
+ catch ( DBException &e ) {
+ LOG(1) << "can't findone replica set slave " << i << " : " << _slaveHost << causedBy( e ) << endl;
}
}
}
@@ -585,8 +585,8 @@ namespace mongo {
try {
return checkSlave()->callLazy( toSend );
}
- catch ( DBException & ) {
- log(1) << "can't query replica set slave: " << _slaveHost << endl;
+ catch ( DBException &e ) {
+ LOG(1) << "can't callLazy replica set slave " << i << " : " << _slaveHost << causedBy( e ) << endl;
}
}
}
@@ -608,8 +608,8 @@ namespace mongo {
*actualServer = s->getServerAddress();
return s->call( toSend , response , assertOk );
}
- catch ( DBException & ) {
- log(1) << "can't query replica set slave: " << _slaveHost << endl;
+ catch ( DBException &e ) {
+ LOG(1) << "can't call replica set slave " << i << " : " << _slaveHost << causedBy( e ) << endl;
if ( actualServer )
*actualServer = "";
}
diff --git a/client/dbclient_rs.h b/client/dbclient_rs.h
index f65fe3d3ad4..f0e855ae8c4 100644
--- a/client/dbclient_rs.h
+++ b/client/dbclient_rs.h
@@ -147,7 +147,7 @@ namespace mongo {
vector<Node> _nodes;
int _master; // which node is the current master. -1 means no master is known
-
+ int _nextSlave; // which node is the current slave
static mongo::mutex _setsLock; // protects _sets
static map<string,ReplicaSetMonitorPtr> _sets; // set name to Monitor
diff --git a/client/examples/clientTest.cpp b/client/examples/clientTest.cpp
index 96c014e245c..aaea6bd1bdf 100644
--- a/client/examples/clientTest.cpp
+++ b/client/examples/clientTest.cpp
@@ -246,5 +246,34 @@ int main( int argc, const char **argv ) {
//MONGO_PRINT(out);
}
+ {
+ // test timeouts
+
+ DBClientConnection conn( true , 0 , 2 );
+ if ( ! conn.connect( string( "127.0.0.1:" ) + port , errmsg ) ) {
+ cout << "couldn't connect : " << errmsg << endl;
+ throw -11;
+ }
+ conn.insert( "test.totest" , BSON( "x" << 1 ) );
+ BSONObj res;
+
+ bool gotError = false;
+ assert( conn.eval( "test" , "return db.totest.findOne().x" , res ) );
+ try {
+ conn.eval( "test" , "sleep(5000); return db.totest.findOne().x" , res );
+ }
+ catch ( std::exception& e ) {
+ gotError = true;
+ log() << e.what() << endl;
+ }
+ assert( gotError );
+ // sleep so the server isn't locked anymore
+ sleepsecs( 4 );
+
+ assert( conn.eval( "test" , "return db.totest.findOne().x" , res ) );
+
+
+ }
+
cout << "client test finished!" << endl;
}
diff --git a/db/db.cpp b/db/db.cpp
index 72f5631bf43..18ffa36cc14 100644
--- a/db/db.cpp
+++ b/db/db.cpp
@@ -284,7 +284,9 @@ namespace mongo {
if ( !h->isCurrentVersion() || forceRepair ) {
if( h->version <= 0 ) {
- uasserted(14026, str::stream() << "db " << dbName << " appears corrupt pdfile version: " << h->version << " info: " << h->versionMinor << ' ' << h->fileLength);
+ uasserted(14026,
+ str::stream() << "db " << dbName << " appears corrupt pdfile version: " << h->version
+ << " info: " << h->versionMinor << ' ' << h->fileLength);
}
log() << "****" << endl;
@@ -416,7 +418,7 @@ namespace mongo {
l << "MongoDB starting : pid=" << pid << " port=" << cmdLine.port << " dbpath=" << dbpath;
if( replSettings.master ) l << " master=" << replSettings.master;
if( replSettings.slave ) l << " slave=" << (int) replSettings.slave;
- l << ( is32bit ? " 32" : " 64" ) << "-bit " << endl;
+ l << ( is32bit ? " 32" : " 64" ) << "-bit host=" << getHostNameCached() << endl;
}
DEV log() << "_DEBUG build (which is slower)" << endl;
show_warnings();
@@ -748,13 +750,10 @@ int main(int argc, char* argv[]) {
if (params.count("repairpath")) {
repairpath = params["repairpath"].as<string>();
if (!repairpath.size()) {
- out() << "repairpath has to be non-zero" << endl;
+ out() << "repairpath is empty" << endl;
dbexit( EXIT_BADOPTIONS );
}
}
- else {
- repairpath = dbpath;
- }
if (params.count("nocursors")) {
useCursors = false;
}
@@ -933,6 +932,10 @@ int main(int argc, char* argv[]) {
dbexit( EXIT_BADOPTIONS );
}
+ // needs to be after things like --configsvr parsing, thus here.
+ if( repairpath.empty() )
+ repairpath = dbpath;
+
Module::configAll( params );
dataFileSync.go();
diff --git a/db/dur_journal.cpp b/db/dur_journal.cpp
index 1738884006c..b8c259a6763 100644
--- a/db/dur_journal.cpp
+++ b/db/dur_journal.cpp
@@ -486,6 +486,11 @@ namespace mongo {
File f;
f.open(lsnPath().string().c_str());
assert(f.is_open());
+ if( f.len() == 0 ) {
+ // this could be 'normal' if we crashed at the right moment
+ log() << "info lsn file is zero bytes long" << endl;
+ return 0;
+ }
f.read(0,(char*)&L, sizeof(L));
unsigned long long lsn = L.get();
return lsn;
diff --git a/db/repl/rs.cpp b/db/repl/rs.cpp
index eea51e3f2e2..84ef3935a3b 100644
--- a/db/repl/rs.cpp
+++ b/db/repl/rs.cpp
@@ -465,9 +465,14 @@ namespace mongo {
forgetPrimary();
setSelfTo(0);
+
+ // For logging
+ string members = "";
+
for( vector<ReplSetConfig::MemberCfg>::iterator i = _cfg->members.begin(); i != _cfg->members.end(); i++ ) {
const ReplSetConfig::MemberCfg& m = *i;
Member *mi;
+ members += ( members == "" ? "" : ", " ) + m.h.toString();
if( m.h.isSelf() ) {
assert( _self == 0 );
mi = new Member(m.h, m._id, &m, true);
@@ -484,6 +489,11 @@ namespace mongo {
box.setOtherPrimary(mi);
}
}
+
+ if( ! _self ){
+ log() << "replSet warning did not detect own host in full reconfig, members " << members << " config: " << c << rsLog;
+ }
+
return true;
}
diff --git a/db/repl/rs_sync.cpp b/db/repl/rs_sync.cpp
index 815a224a79b..535796b5a25 100644
--- a/db/repl/rs_sync.cpp
+++ b/db/repl/rs_sync.cpp
@@ -34,7 +34,7 @@ namespace mongo {
if ( *ns == '.' || *ns == 0 ) {
if( *o.getStringField("op") == 'n' )
return;
- log() << "replSet skipping bad op in oplog: " << o.toString() << endl;
+ log() << "replSet skipping bad op in oplog: " << o.toString() << rsLog;
return;
}
@@ -141,7 +141,7 @@ namespace mongo {
time_t now = time(0);
if (now - start > 10) {
// simple progress metering
- log() << "initialSyncOplogApplication applied " << n << " operations, synced to "
+ log() << "replSet initialSyncOplogApplication applied " << n << " operations, synced to "
<< ts.toStringPretty() << rsLog;
start = now;
}
@@ -322,8 +322,8 @@ namespace mongo {
OpTime ts = o["ts"]._opTime();
long long h = o["h"].numberLong();
if( ts != lastOpTimeWritten || h != lastH ) {
- log() << "replSet our last op time written: " << lastOpTimeWritten.toStringPretty() << endl;
- log() << "replset source's GTE: " << ts.toStringPretty() << endl;
+ log() << "replSet our last op time written: " << lastOpTimeWritten.toStringPretty() << rsLog;
+ log() << "replset source's GTE: " << ts.toStringPretty() << rsLog;
syncRollback(r);
return;
}
@@ -467,8 +467,13 @@ namespace mongo {
*/
while( 1 ) {
- if( myConfig().arbiterOnly )
+ // After a reconfig, we may not be in the replica set anymore, so
+ // check that we are in the set (and not an arbiter) before
+ // trying to sync with other replicas.
+ if( ! _self || myConfig().arbiterOnly ){
+ if( ! _self ) log() << "replSet warning did not detect own host and port, not syncing, config: " << theReplSet->config() << rsLog;
return;
+ }
try {
_syncThread();
@@ -489,9 +494,9 @@ namespace mongo {
member has done a stepDown() and needs to come back up.
*/
OCCASIONALLY {
- log() << "default rs heartbeat starting..." << endl;
+ log() << "replSet default heartbeat starting..." << rsLog;
mgr->send( boost::bind(&Manager::msgCheckNewState, theReplSet->mgr) );
- log() << "rs heartbeat finished" << endl;
+ log() << "replSet heartbeat finished" << rsLog;
}
}
}
diff --git a/jstests/replsets/sync1.js b/jstests/replsets/sync1.js
index de824d0989b..5e862106efa 100644
--- a/jstests/replsets/sync1.js
+++ b/jstests/replsets/sync1.js
@@ -80,12 +80,17 @@ doTest = function (signal) {
assert(count < 300);
+ // Need to be careful here, allocating datafiles for the slaves can take a *long* time on slow systems
+ sleep(7000);
+
print("\nsync1.js ********************************************************************** part 6");
dbs[0].getSisterDB("admin").runCommand({ replSetTest: 1, blind: true });
print("\nsync1.js ********************************************************************** part 7");
sleep(5000);
+ // If we start getting error hasNext: false with done alloc datafile msgs - may need to up the sleep again in part 5
+
var max1;
var max2;
diff --git a/jstests/sharding/migrateBig.js b/jstests/sharding/migrateBig.js
index f6ba18a7c02..917f152a4d2 100644
--- a/jstests/sharding/migrateBig.js
+++ b/jstests/sharding/migrateBig.js
@@ -40,6 +40,6 @@ for ( i=0; i<20; i+= 2 )
db.printShardingStatus()
-assert.soon( function(){ var x = s.chunkDiff( "foo" , "test" ); print( "chunk diff: " + x ); return x < 2; } , "no balance happened" , 120 * 1000 , 2000 )
+assert.soon( function(){ var x = s.chunkDiff( "foo" , "test" ); print( "chunk diff: " + x ); return x < 2; } , "no balance happened" , 8 * 60 * 1000 , 2000 )
s.stop()
diff --git a/jstests/sharding/shard3.js b/jstests/sharding/shard3.js
index 71325637baf..0a4bc2ff75f 100644
--- a/jstests/sharding/shard3.js
+++ b/jstests/sharding/shard3.js
@@ -4,9 +4,18 @@ s = new ShardingTest( "shard3" , 2 , 1 , 2 );
s2 = s._mongos[1];
+db = s.getDB( "test" )
s.adminCommand( { enablesharding : "test" } );
s.adminCommand( { shardcollection : "test.foo" , key : { num : 1 } } );
+assert( sh.getBalancerState() , "A1" )
+sh.setBalancerState( false )
+assert( ! sh.getBalancerState() , "A2" )
+sh.setBalancerState( true )
+assert( sh.getBalancerState() , "A3" )
+sh.setBalancerState( false )
+assert( ! sh.getBalancerState() , "A4" )
+
s.config.databases.find().forEach( printjson )
a = s.getDB( "test" ).foo;
diff --git a/jstests/sharding/sync7.js b/jstests/sharding/sync7.js
index 0badd9ebeb7..a8ff0944a00 100644
--- a/jstests/sharding/sync7.js
+++ b/jstests/sharding/sync7.js
@@ -7,7 +7,7 @@ s._connections[1].getDB( "admin" ).runCommand( { _skewClockCommand : 1, skew : -
// We need to start another mongos after skewing the clock, since the first mongos will have already
// tested the config servers (via the balancer) before we manually skewed them
-otherMongos = startMongos( { port : 30020, v : 0, configdb : s._configDB, logpath : "/dev/null" } );
+otherMongos = startMongos( { port : 30020, v : 0, configdb : s._configDB } );
// Initialize DB data
initDB = function(name) {
diff --git a/jstests/slowNightly/sharding_balance1.js b/jstests/slowNightly/sharding_balance1.js
index 9379c4fa310..c50148c0400 100644
--- a/jstests/slowNightly/sharding_balance1.js
+++ b/jstests/slowNightly/sharding_balance1.js
@@ -41,7 +41,8 @@ print( diff() )
assert.soon( function(){
var d = diff();
return d < 5;
-} , "balance didn't happen" , 1000 * 60 * 3 , 5000 );
+// Make sure there's enough time here, since balancing can sleep for 15s or so between balances.
+} , "balance didn't happen" , 1000 * 60 * 5 , 5000 );
var chunkCount = sum();
s.adminCommand( { removeshard: "shard0000" } );
diff --git a/s/balance.cpp b/s/balance.cpp
index 40d542b9111..fba325ed5ae 100644
--- a/s/balance.cpp
+++ b/s/balance.cpp
@@ -275,47 +275,51 @@ namespace mongo {
try {
- // first make sure we should even be running
+ ScopedDbConnection conn( config );
+
+ // ping has to be first so we keep things in the config server in sync
+ _ping( conn.conn() );
+
+ // now make sure we should even be running
if ( ! grid.shouldBalance() ) {
log(1) << "skipping balancing round because balancing is disabled" << endl;
+ conn.done();
+
sleepsecs( 30 );
continue;
}
-
- ScopedDbConnection conn( config );
-
- _ping( conn.conn() );
- if ( ! _checkOIDs() ) {
- uassert( 13258 , "oids broken after resetting!" , _checkOIDs() );
- }
+ uassert( 13258 , "oids broken after resetting!" , _checkOIDs() );
// use fresh shard state
Shard::reloadShardInfo();
- dist_lock_try lk( &balanceLock , "doing balance round" );
- if ( ! lk.got() ) {
- log(1) << "skipping balancing round because another balancer is active" << endl;
- conn.done();
-
- sleepsecs( 30 ); // no need to wake up soon
- continue;
- }
-
- log(1) << "*** start balancing round" << endl;
-
- vector<CandidateChunkPtr> candidateChunks;
- _doBalanceRound( conn.conn() , &candidateChunks );
- if ( candidateChunks.size() == 0 ) {
- log(1) << "no need to move any chunk" << endl;
+ {
+ dist_lock_try lk( &balanceLock , "doing balance round" );
+ if ( ! lk.got() ) {
+ log(1) << "skipping balancing round because another balancer is active" << endl;
+ conn.done();
+
+ sleepsecs( 30 ); // no need to wake up soon
+ continue;
+ }
+
+ log(1) << "*** start balancing round" << endl;
+
+ vector<CandidateChunkPtr> candidateChunks;
+ _doBalanceRound( conn.conn() , &candidateChunks );
+ if ( candidateChunks.size() == 0 ) {
+ log(1) << "no need to move any chunk" << endl;
+ }
+ else {
+ _balancedLastTime = _moveChunks( &candidateChunks );
+ }
+
+ log(1) << "*** end of balancing round" << endl;
}
- else {
- _balancedLastTime = _moveChunks( &candidateChunks );
- }
-
- log(1) << "*** end of balancing round" << endl;
+
conn.done();
-
+
sleepsecs( _balancedLastTime ? 5 : 10 );
}
catch ( std::exception& e ) {
diff --git a/s/config.cpp b/s/config.cpp
index c1410c9e33f..86b169afe40 100644
--- a/s/config.cpp
+++ b/s/config.cpp
@@ -456,9 +456,6 @@ namespace mongo {
}
bool ConfigServer::checkConfigServersConsistent( string& errmsg , int tries ) const {
- if ( _config.size() == 1 )
- return true;
-
if ( tries <= 0 )
return false;
@@ -485,6 +482,9 @@ namespace mongo {
res.push_back(x);
}
+ if ( _config.size() == 1 )
+ return true;
+
if ( up == 0 ) {
errmsg = "no config servers reachable";
return false;
diff --git a/s/d_migrate.cpp b/s/d_migrate.cpp
index fe4c0efe355..22b600a8db1 100644
--- a/s/d_migrate.cpp
+++ b/s/d_migrate.cpp
@@ -1008,6 +1008,7 @@ namespace mongo {
conn.done();
}
catch ( DBException& e ) {
+ warning() << e << endl;
ok = false;
BSONObjBuilder b;
e.getInfo().append( b );
diff --git a/s/strategy_shard.cpp b/s/strategy_shard.cpp
index 4e0c76312cd..2b36025d4a2 100644
--- a/s/strategy_shard.cpp
+++ b/s/strategy_shard.cpp
@@ -166,8 +166,8 @@ namespace mongo {
gotThrough = true;
break;
}
- catch ( StaleConfigException& ) {
- log( i < ( maxTries / 2 ) ) << "retrying insert because of StaleConfigException: " << o << endl;
+ catch ( StaleConfigException& e ) {
+ log( i < ( maxTries / 2 ) ) << "retrying insert because of StaleConfigException: " << e << " object: " << o << endl;
r.reset();
manager = r.getChunkManager();
}
diff --git a/shell/mongo_vstudio.cpp b/shell/mongo_vstudio.cpp
index 175ac004e00..01fa3ad54ea 100644
--- a/shell/mongo_vstudio.cpp
+++ b/shell/mongo_vstudio.cpp
@@ -1534,7 +1534,10 @@ const StringData _jscode_raw_utils_sh =
"print( \"\\tsh.enableSharding(dbname) enables sharding on the database dbname\" )\n"
"print( \"\\tsh.shardCollection(fullName,key,unique) shards the collection\" );\n"
"print( \"\\tsh.splitFind(fullName,find) splits the chunk that find is in at the median\" );\n"
-"print( \"\\tsh.splitAt(fullName,middle) splits the chunk that middle is in at middle\" );\n"
+"print( \"\\tsh.splitAt(fullName,middle) splits the chunk that middle is in at middle\" );\n"
+"\n"
+"print( \"\\tsh.setBalancerState( <bool on or not> ) turns the balancer on or off true=on, false=off\" );\n"
+"print( \"\\tsh.getBalancerState() return true if on, off if not\" );\n"
"\n"
"print( \"\\tsh.status() prints a general overview of the cluster\" )\n"
"}\n"
@@ -1575,6 +1578,17 @@ const StringData _jscode_raw_utils_sh =
"sh._checkFullName( fullName )\n"
"sh._adminCommand( { split : fullName , middle : middle } )\n"
"}\n"
+"\n"
+"sh.setBalancerState = function( onOrNot ) {\n"
+"db.getSisterDB( \"config\" ).settings.update({ _id: \"balancer\" }, { $set : { stopped: onOrNot ? false : true } }, true );\n"
+"}\n"
+"\n"
+"sh.getBalancerState = function() {\n"
+"var x = db.getSisterDB( \"config\" ).settings.findOne({ _id: \"balancer\" } )\n"
+"if ( x == null )\n"
+"return true;\n"
+"return ! x.stopped;\n"
+"}\n"
;
extern const JSFile utils_sh;
const JSFile utils_sh = { "shell/utils_sh.js" , _jscode_raw_utils_sh };
diff --git a/shell/utils_sh.js b/shell/utils_sh.js
index 8644fcbe6ca..b66929ced05 100644
--- a/shell/utils_sh.js
+++ b/shell/utils_sh.js
@@ -28,7 +28,10 @@ sh.help = function() {
print( "\tsh.enableSharding(dbname) enables sharding on the database dbname" )
print( "\tsh.shardCollection(fullName,key,unique) shards the collection" );
print( "\tsh.splitFind(fullName,find) splits the chunk that find is in at the median" );
- print( "\tsh.splitAt(fullName,middle) splits the chunk that middle is in at middle" );
+ print( "\tsh.splitAt(fullName,middle) splits the chunk that middle is in at middle" );
+
+ print( "\tsh.setBalancerState( <bool on or not> ) turns the balancer on or off true=on, false=off" );
+ print( "\tsh.getBalancerState() return true if on, off if not" );
print( "\tsh.status() prints a general overview of the cluster" )
}
@@ -69,3 +72,14 @@ sh.splitAt = function( fullName , middle ) {
sh._checkFullName( fullName )
sh._adminCommand( { split : fullName , middle : middle } )
}
+
+sh.setBalancerState = function( onOrNot ) {
+ db.getSisterDB( "config" ).settings.update({ _id: "balancer" }, { $set : { stopped: onOrNot ? false : true } }, true );
+}
+
+sh.getBalancerState = function() {
+ var x = db.getSisterDB( "config" ).settings.findOne({ _id: "balancer" } )
+ if ( x == null )
+ return true;
+ return ! x.stopped;
+}
diff --git a/tools/sniffer.cpp b/tools/sniffer.cpp
index 4e9cfd21bf3..024a37475cc 100644
--- a/tools/sniffer.cpp
+++ b/tools/sniffer.cpp
@@ -104,6 +104,9 @@ struct sniff_ip {
#define IP_V(ip) (((ip)->ip_vhl) >> 4)
/* TCP header */
+#ifdef _WIN32
+typedef unsigned __int32 uint32_t;
+#endif
typedef uint32_t tcp_seq;
struct sniff_tcp {
diff --git a/util/file.h b/util/file.h
index aed5d52fdaa..704dc536211 100644
--- a/util/file.h
+++ b/util/file.h
@@ -38,6 +38,8 @@ namespace mongo {
typedef boost::uint64_t fileofs;
#endif
+ /* NOTE: not thread-safe. (at least the windows implementation isn't. */
+
class FileInterface {
public:
void open(const char *fn) {}
@@ -183,7 +185,11 @@ namespace mongo {
bool bad() { return _bad; }
bool is_open() { return fd > 0; }
fileofs len() {
- return lseek(fd, 0, SEEK_END);
+ off_t o = lseek(fd, 0, SEEK_END);
+ if( o != (off_t) -1 )
+ return o;
+ err(false);
+ return 0;
}
void fsync() { ::fsync(fd); }
static boost::intmax_t freeSpace ( const string &path ) {
diff --git a/util/message.cpp b/util/message.cpp
index c58d0ddca63..892d64c7bdb 100644
--- a/util/message.cpp
+++ b/util/message.cpp
@@ -364,7 +364,7 @@ namespace mongo {
ConnectBG(int sock, SockAddr farEnd) : _sock(sock), _farEnd(farEnd) { }
void run() { _res = ::connect(_sock, _farEnd.raw(), _farEnd.addressSize); }
- string name() const { return ""; /* too short lived to need to name */ }
+ string name() const { return "ConnectBG"; }
int inError() const { return _res; }
private:
@@ -634,12 +634,20 @@ again:
unsigned retries = 0;
while( len > 0 ) {
int ret = ::recv( sock , buf , len , portRecvFlags );
- if ( ret == 0 ) {
+ if ( ret > 0 ) {
+ if ( len <= 4 && ret != len )
+ log(_logLevel) << "MessagingPort recv() got " << ret << " bytes wanted len=" << len << endl;
+ assert( ret <= len );
+ len -= ret;
+ buf += ret;
+ }
+ else if ( ret == 0 ) {
log(3) << "MessagingPort recv() conn closed? " << farEnd.toString() << endl;
throw SocketException( SocketException::CLOSED );
}
- if ( ret < 0 ) {
+ else { /* ret < 0 */
int e = errno;
+
#if defined(EINTR) && !defined(_WIN32)
if( e == EINTR ) {
if( ++retries == 1 ) {
@@ -648,29 +656,18 @@ again:
}
}
#endif
- if ( e != EAGAIN || _timeout == 0 ) {
- SocketException::Type t = SocketException::RECV_ERROR;
-#if defined(_WINDOWS)
- if( e == WSAETIMEDOUT ) t = SocketException::RECV_TIMEOUT;
-#else
- /* todo: what is the error code on an SO_RCVTIMEO on linux? EGAIN? EWOULDBLOCK? */
+ if ( ( e == EAGAIN
+#ifdef _WINDOWS
+ || e == WSAETIMEDOUT
#endif
- log(_logLevel) << "MessagingPort recv() " << errnoWithDescription(e) << " " << farEnd.toString() <<endl;
- throw SocketException(t);
- }
- else {
- if ( !serverAlive( farEnd.toString() ) ) {
- log(_logLevel) << "MessagingPort recv() remote dead " << farEnd.toString() << endl;
- throw SocketException( SocketException::RECV_ERROR );
- }
+ ) && _timeout > 0 ) {
+ // this is a timeout
+ log(_logLevel) << "MessagingPort recv() timeout " << farEnd.toString() <<endl;
+ throw SocketException(SocketException::RECV_TIMEOUT);
}
- }
- else {
- if ( len <= 4 && ret != len )
- log(_logLevel) << "MessagingPort recv() got " << ret << " bytes wanted len=" << len << endl;
- assert( ret <= len );
- len -= ret;
- buf += ret;
+
+ log(_logLevel) << "MessagingPort recv() " << errnoWithDescription(e) << " " << farEnd.toString() <<endl;
+ throw SocketException(SocketException::RECV_ERROR);
}
}
}
diff --git a/util/version.cpp b/util/version.cpp
index 7919b0be790..f763c7f4119 100644
--- a/util/version.cpp
+++ b/util/version.cpp
@@ -110,7 +110,7 @@ namespace mongo {
#endif
void printSysInfo() {
- log() << "build sys info: " << sysInfo() << endl;
+ log() << "build info: " << sysInfo() << endl;
}
//