Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

SERVER-2988 catch exceptions loading chunksize

Conflicts:

	s/config.cpp
  • Loading branch information...
commit ba8d0f572c9108c0c2f279a393a854c59d475008 1 parent e694456
gregs authored andy10gen committed
Showing with 38 additions and 27 deletions.
  1. +38 −27 s/config.cpp
View
65 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 ) {
Please sign in to comment.
Something went wrong with that request. Please try again.