diff options
author | Eliot Horowitz <eliot@10gen.com> | 2010-04-23 11:22:56 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2010-04-23 11:22:56 -0400 |
commit | e7e41410dc4dacc266ab1e1c644727ec44c6a5b8 (patch) | |
tree | 5bec7874ca0deca5f0c7a4ad2c964ba1f1638bf0 /s | |
parent | a60318c503bf4b2c470be23abe3acd3e721375b2 (diff) | |
download | mongo-e7e41410dc4dacc266ab1e1c644727ec44c6a5b8.tar.gz |
clean up ping and don't fsync before or after
Diffstat (limited to 's')
-rw-r--r-- | s/balance.cpp | 40 | ||||
-rw-r--r-- | s/balance.h | 3 |
2 files changed, 34 insertions, 9 deletions
diff --git a/s/balance.cpp b/s/balance.cpp index e60206b233b..6be6d88da97 100644 --- a/s/balance.cpp +++ b/s/balance.cpp @@ -54,7 +54,7 @@ namespace mongo { return false; } - log(3) << "balancer: going to take over" << endl; + log() << "balancer: going to take over" << endl; // we want to take over, so fall through to below } @@ -74,12 +74,12 @@ namespace mongo { true ); x = conn.findOne( ShardNS::settings , BSON( "_id" << "balancer" ) ); - log(3) << "balancer: after update: " << x << endl; + log() << "balancer: after update: " << x << endl; return _myid == x["who"].String() && hack == x["x"].OID(); } void Balancer::balance( DBClientBase& conn ){ - log() << "i'm going to do some balancing" << endl; + log(1) << "i'm going to do some balancing" << endl; auto_ptr<DBClientCursor> cursor = conn.query( ShardNS::database , BSON( "partitioned" << true ) ); while ( cursor->more() ){ @@ -138,7 +138,7 @@ namespace mongo { string to = min.first; BSONObj chunkToMove = pickChunk( shards[from] , shards[to] ); - log(1) << "balancer: move a chunk from [" << from << "] to [" << to << "] " << chunkToMove << endl; + log() << "balancer: move a chunk from [" << from << "] to [" << to << "] " << chunkToMove << endl; DBConfig * cfg = grid.getDBConfig( ns ); assert( cfg ); @@ -172,6 +172,30 @@ namespace mongo { return from[0]; } + void Balancer::ping(){ + assert( _myid.size() && _started ); + try { + ShardConnection conn( configServer.getPrimary() ); + ping( conn.conn() ); + conn.done(); + } + catch ( std::exception& e ){ + log() << "bare ping failed: " << e.what() << endl; + } + + } + + void Balancer::ping( DBClientBase& conn ){ + WriteConcern w = conn.getWriteConcern(); + conn.setWriteConcern( W_NONE ); + + conn.update( ShardNS::mongos , + BSON( "_id" << _myid ) , + BSON( "$set" << BSON( "ping" << DATENOW << "up" << (int)(time(0)-_started) ) ) , + true ); + + conn.setWriteConcern( w); + } void Balancer::run(){ @@ -183,17 +207,15 @@ namespace mongo { _started = time(0); } - + + ping(); while ( ! inShutdown() ){ sleepsecs( 30 ); try { ShardConnection conn( configServer.getPrimary() ); - conn->update( ShardNS::mongos , - BSON( "_id" << _myid ) , - BSON( "$set" << BSON( "ping" << DATENOW << "up" << (int)(time(0)-_started) ) ) , - true ); + ping( conn.conn() ); if ( shouldIBalance( conn.conn() ) ){ balance( conn.conn() ); diff --git a/s/balance.h b/s/balance.h index ed705c83b7d..a77feddd0d0 100644 --- a/s/balance.h +++ b/s/balance.h @@ -35,6 +35,9 @@ namespace mongo { void balance( DBClientBase& conn ); void balance( DBClientBase& conn , const string& ns , const BSONObj& data ); + void ping(); + void ping( DBClientBase& conn ); + BSONObj pickChunk( vector<BSONObj>& from, vector<BSONObj>& to ); string _myid; |