Shard Shard::pick( const Shard& current ) { vector<Shard> all; staticShardInfo.getAllShards( all ); if ( all.size() == 0 ) { staticShardInfo.reload(); staticShardInfo.getAllShards( all ); if ( all.size() == 0 ) return EMPTY; } // if current shard was provided, pick a different shard only if it is a better choice ShardStatus best = all[0].getStatus(); if ( current != EMPTY ) { best = current.getStatus(); } for ( size_t i=0; i<all.size(); i++ ) { ShardStatus t = all[i].getStatus(); if ( t < best ) best = t; } LOG(1) << "best shard for new allocation is " << best << endl; return best.shard(); }
Shard Shard::pick(){ vector<Shard> all; staticShardInfo.getAllShards( all ); if ( all.size() == 0 ){ staticShardInfo.reload(); staticShardInfo.getAllShards( all ); if ( all.size() == 0 ) return EMPTY; } ShardStatus best = all[0].getStatus(); for ( size_t i=1; i<all.size(); i++ ){ ShardStatus t = all[i].getStatus(); if ( t < best ) best = t; } log(1) << "picking shard: " << best << endl; return best.shard(); }