00001
00002
00019 #ifndef S_BALANCER_POLICY_HEADER
00020 #define S_BALANCER_POLICY_HEADER
00021
00022 #include "../pch.h"
00023
00024 namespace mongo {
00025
00026 class BalancerPolicy {
00027 public:
00028 struct ChunkInfo;
00029
00043 typedef map< string,BSONObj > ShardToLimitsMap;
00044 typedef map< string,vector<BSONObj> > ShardToChunksMap;
00045 static ChunkInfo* balance( const string& ns, const ShardToLimitsMap& shardToLimitsMap,
00046 const ShardToChunksMap& shardToChunksMap, int balancedLastTime );
00047
00048
00049
00050 static BSONObj pickChunk( const vector<BSONObj>& from, const vector<BSONObj>& to );
00051
00057 static bool isSizeMaxed( BSONObj shardLimits );
00058
00063 static bool isDraining( BSONObj shardLimits );
00064
00068 static bool hasOpsQueued( BSONObj shardLimits );
00069
00070 private:
00071
00072 typedef ShardToChunksMap::const_iterator ShardToChunksIter;
00073 typedef ShardToLimitsMap::const_iterator ShardToLimitsIter;
00074
00075 };
00076
00077 struct BalancerPolicy::ChunkInfo {
00078 const string ns;
00079 const string to;
00080 const string from;
00081 const BSONObj chunk;
00082
00083 ChunkInfo( const string& a_ns , const string& a_to , const string& a_from , const BSONObj& a_chunk )
00084 : ns( a_ns ) , to( a_to ) , from( a_from ), chunk( a_chunk ) {}
00085 };
00086
00090 struct LimitsFields {
00091
00092 static BSONField<long long> currSize;
00093 static BSONField<bool> hasOpsQueued;
00094 };
00095
00096 }
00097
00098 #endif // S_BALANCER_POLICY_HEADER