diff options
author | gregs <greg@10gen.com> | 2012-03-29 12:03:15 -0400 |
---|---|---|
committer | Andy Schwerin <schwerin@10gen.com> | 2012-04-18 17:24:51 -0400 |
commit | ba8d0f572c9108c0c2f279a393a854c59d475008 (patch) | |
tree | 0db6a6a08c0838682e6aa30264b298ddd8a632cf | |
parent | e69445666bd8acfb1fac1e826e610fac845019a7 (diff) | |
download | mongo-ba8d0f572c9108c0c2f279a393a854c59d475008.tar.gz |
SERVER-2988 catch exceptions loading chunksize
Conflicts:
s/config.cpp
-rw-r--r-- | s/config.cpp | 65 |
1 files changed, 38 insertions, 27 deletions
diff --git a/s/config.cpp b/s/config.cpp index 645e9236a43..9017eafbddd 100644 --- a/s/config.cpp +++ b/s/config.cpp @@ -710,42 +710,53 @@ namespace mongo { set<string> got; ScopedDbConnection conn( _primary, 30.0 ); - auto_ptr<DBClientCursor> c = conn->query( ShardNS::settings , BSONObj() ); - assert( c.get() ); - while ( c->more() ) { - BSONObj o = c->next(); - string name = o["_id"].valuestrsafe(); - got.insert( name ); - if ( name == "chunksize" ) { - LOG(1) << "MaxChunkSize: " << o["value"] << endl; - Chunk::MaxChunkSize = o["value"].numberInt() * 1024 * 1024; - } - else if ( name == "balancer" ) { - // ones we ignore here - } - else { - log() << "warning: unknown setting [" << name << "]" << endl; - } - } - if ( ! got.count( "chunksize" ) ) { - conn->insert( ShardNS::settings , BSON( "_id" << "chunksize" << - "value" << (Chunk::MaxChunkSize / ( 1024 * 1024 ) ) ) ); - } + try { + auto_ptr<DBClientCursor> c = conn->query( ShardNS::settings , BSONObj() ); + assert( c.get() ); + while ( c->more() ) { + + BSONObj o = c->next(); + string name = o["_id"].valuestrsafe(); + got.insert( name ); + if ( name == "chunksize" ) { + int csize = o["value"].numberInt(); + + // validate chunksize before proceeding + if ( csize == 0 ) { + // setting was not modified; mark as such + got.erase(name); + log() << "warning: invalid chunksize (" << csize << ") ignored" << endl; + } else { + LOG(1) << "MaxChunkSize: " << csize << endl; + Chunk::MaxChunkSize = csize * 1024 * 1024; + } + } + else if ( name == "balancer" ) { + // ones we ignore here + } + else { + log() << "warning: unknown setting [" << name << "]" << endl; + } + } - // indexes - try { + if ( ! got.count( "chunksize" ) ) { + conn->insert( ShardNS::settings , BSON( "_id" << "chunksize" << + "value" << (Chunk::MaxChunkSize / ( 1024 * 1024 ) ) ) ); + } + + // indexes conn->ensureIndex( ShardNS::chunk , BSON( "ns" << 1 << "min" << 1 ) , true ); conn->ensureIndex( ShardNS::chunk , BSON( "ns" << 1 << "shard" << 1 << "min" << 1 ) , true ); conn->ensureIndex( ShardNS::chunk , BSON( "ns" << 1 << "lastmod" << 1 ) , true ); conn->ensureIndex( ShardNS::shard , BSON( "host" << 1 ) , true ); + + conn.done(); } - catch ( std::exception& e ) { - log( LL_WARNING ) << "couldn't create indexes on config db: " << e.what() << endl; + catch ( DBException& e ) { + warning() << "couldn't load settings or create indexes on config db: " << e.what() << endl; } - - conn.done(); } string ConfigServer::getHost( string name , bool withPort ) { |