From c86f376300322103d46f19133a4340c243d59ba0 Mon Sep 17 00:00:00 2001 From: Alberto Lerner Date: Wed, 26 May 2010 09:55:34 -0400 Subject: [PATCH] Balancer now skips a database that doesn't have any sharded collections in it --- s/balance.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/s/balance.cpp b/s/balance.cpp index 79c234dbaff..4ceeaf95cdd 100644 --- a/s/balance.cpp +++ b/s/balance.cpp @@ -87,7 +87,19 @@ namespace mongo { auto_ptr cursor = conn.query( ShardNS::database , BSON( "partitioned" << true ) ); while ( cursor->more() ){ BSONObj db = cursor->next(); - BSONObjIterator i( db["sharded"].Obj() ); + + // A database may be partitioned but not yet have a sharded collection. + // 'cursor' will point to docs that do not contain the "sharded" key. Since + // there'd be nothing to balance, we want to skip those here. + + BSONElement shardedColls = db["sharded"]; + if ( shardedColls.eoo() ){ + log(3) << "balancer: skipping database with no sharded collection (" + << db["_id"].str() << ")" << endl; + continue; + } + + BSONObjIterator i( shardedColls.Obj() ); while ( i.more() ){ BSONElement e = i.next(); BSONObj data = e.Obj().getOwned();