diff options
author | Eliot Horowitz <eliot@10gen.com> | 2012-06-13 18:24:54 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2012-06-13 19:04:56 -0400 |
commit | 60c041e473b59e9451da79ac32b9f1cd2c686b28 (patch) | |
tree | e6a432bf8f1eb216e26083c87e1977496e081233 /src/mongo/s/balancer_policy.h | |
parent | 497caa1edc3e1cacdb675b50b68159f4f2364748 (diff) | |
download | mongo-60c041e473b59e9451da79ac32b9f1cd2c686b28.tar.gz |
clean balancer policy a bit in prep of SERVER-2545
Diffstat (limited to 'src/mongo/s/balancer_policy.h')
-rw-r--r-- | src/mongo/s/balancer_policy.h | 102 |
1 files changed, 59 insertions, 43 deletions
diff --git a/src/mongo/s/balancer_policy.h b/src/mongo/s/balancer_policy.h index cef5aa64afc..ffc4853f3d9 100644 --- a/src/mongo/s/balancer_policy.h +++ b/src/mongo/s/balancer_policy.h @@ -19,78 +19,94 @@ #ifndef S_BALANCER_POLICY_HEADER #define S_BALANCER_POLICY_HEADER -#include "../pch.h" +#include "mongo/db/jsobj.h" namespace mongo { class BalancerPolicy { public: - struct ChunkInfo; - + struct MigrateInfo; + + struct ChunkInfo { + const BSONObj min; + const BSONObj max; + + ChunkInfo( const BSONObj& a_min, const BSONObj& a_max ) + : min( a_min ), max( a_max ){} + + ChunkInfo( const BSONObj& chunk ) + : min( chunk["min"].Obj() ), max( chunk["max"].Obj() ) { + } + + string toString() const; + }; + + class ShardInfo { + public: + ShardInfo(); + ShardInfo( long long maxSize, long long currSize, bool draining, bool opsQueued ); + + /** + * @return true if a shard cannot receive any new chunks bacause it reache 'shardLimits'. + * Expects the optional fields "maxSize", can in size in MB, and "usedSize", currently used size + * in MB, on 'shardLimits'. + */ + bool isSizeMaxed() const; + + /** + * @return true if 'shardLimist' contains a field "draining". Expects the optional field + * "isDraining" on 'shrdLimits'. + */ + bool isDraining() const { return _draining; } + + /** + * @return true if a shard currently has operations in any of its writeback queues + */ + bool hasOpsQueued() const { return _hasOpsQueued; } + + string toString() const; + + private: + long long _maxSize; + long long _currSize; + bool _draining; + bool _hasOpsQueued; + }; + /** * Returns a suggested chunk to move whithin a collection's shards, given information about * space usage and number of chunks for that collection. If the policy doesn't recommend * moving, it returns NULL. * * @param ns is the collections namepace. - * @param shardLimitMap is a map from shardId to an object that describes (for now) space - * cap and usage. E.g.: { "maxSize" : <size_in_MB> , "usedSize" : <size_in_MB> }. * @param shardToChunksMap is a map from shardId to chunks that live there. A chunk's format * is { }. * @param balancedLastTime is the number of chunks effectively moved in the last round. - * @returns NULL or ChunkInfo of the best move to make towards balacing the collection. + * @returns NULL or MigrateInfo of the best move to make towards balacing the collection. */ - typedef map< string,BSONObj > ShardToLimitsMap; + typedef map< string,ShardInfo > ShardInfoMap; typedef map< string,vector<BSONObj> > ShardToChunksMap; - static ChunkInfo* balance( const string& ns, const ShardToLimitsMap& shardToLimitsMap, - const ShardToChunksMap& shardToChunksMap, int balancedLastTime ); + static MigrateInfo* balance( const string& ns, + const ShardInfoMap& shardInfo, + const ShardToChunksMap& shardToChunksMap, + int balancedLastTime ); // below exposed for testing purposes only -- treat it as private -- static BSONObj pickChunk( const vector<BSONObj>& from, const vector<BSONObj>& to ); - /** - * Returns true if a shard cannot receive any new chunks bacause it reache 'shardLimits'. - * Expects the optional fields "maxSize", can in size in MB, and "usedSize", currently used size - * in MB, on 'shardLimits'. - */ - static bool isSizeMaxed( BSONObj shardLimits ); - - /** - * Returns true if 'shardLimist' contains a field "draining". Expects the optional field - * "isDraining" on 'shrdLimits'. - */ - static bool isDraining( BSONObj shardLimits ); - - /** - * Returns true if a shard currently has operations in any of its writeback queues - */ - static bool hasOpsQueued( BSONObj shardLimits ); - - private: - // Convenience types - typedef ShardToChunksMap::const_iterator ShardToChunksIter; - typedef ShardToLimitsMap::const_iterator ShardToLimitsIter; - }; - struct BalancerPolicy::ChunkInfo { + struct BalancerPolicy::MigrateInfo { const string ns; const string to; const string from; - const BSONObj chunk; + const ChunkInfo chunk; - ChunkInfo( const string& a_ns , const string& a_to , const string& a_from , const BSONObj& a_chunk ) + MigrateInfo( const string& a_ns , const string& a_to , const string& a_from , const BSONObj& a_chunk ) : ns( a_ns ) , to( a_to ) , from( a_from ), chunk( a_chunk ) {} - }; - /** - * Field names used in the 'limits' map. - */ - struct LimitsFields { - // we use 'draining' and 'maxSize' from the 'shards' collection plus the following - static BSONField<long long> currSize; // currently used disk space in bytes - static BSONField<bool> hasOpsQueued; // writeback queue is not empty? + }; } // namespace mongo |