00001 //@file balance.h 00002 00019 #pragma once 00020 00021 #include "../pch.h" 00022 #include "../util/background.h" 00023 #include "../client/dbclient.h" 00024 #include "balancer_policy.h" 00025 00026 namespace mongo { 00027 00037 class Balancer : public BackgroundJob { 00038 public: 00039 Balancer(); 00040 virtual ~Balancer(); 00041 00042 // BackgroundJob methods 00043 00044 virtual void run(); 00045 00046 virtual string name() const { return "Balancer"; } 00047 00048 private: 00049 typedef BalancerPolicy::ChunkInfo CandidateChunk; 00050 typedef shared_ptr<CandidateChunk> CandidateChunkPtr; 00051 00052 // hostname:port of my mongos 00053 string _myid; 00054 00055 // time the Balancer started running 00056 time_t _started; 00057 00058 // number of moved chunks in last round 00059 int _balancedLastTime; 00060 00061 // decide which chunks to move; owned here. 00062 BalancerPolicy* _policy; 00063 00071 bool _init(); 00072 00080 void _doBalanceRound( DBClientBase& conn, vector<CandidateChunkPtr>* candidateChunks ); 00081 00088 int _moveChunks( const vector<CandidateChunkPtr>* candidateChunks ); 00089 00095 void _ping( DBClientBase& conn ); 00096 00100 bool _checkOIDs(); 00101 00102 }; 00103 00104 extern Balancer balancer; 00105 }