diff options
author | Antonin Kral <a.kral@bobek.cz> | 2010-08-11 12:38:57 +0200 |
---|---|---|
committer | Antonin Kral <a.kral@bobek.cz> | 2010-08-11 12:38:57 +0200 |
commit | 7645618fd3914cb8a20561625913c20d49504a49 (patch) | |
tree | 8370f846f58f6d71165b7a0e2eda04648584ec76 /s/balance.h | |
parent | 68c73c3c7608b4c87f07440dc3232801720b1168 (diff) | |
download | mongodb-7645618fd3914cb8a20561625913c20d49504a49.tar.gz |
Imported Upstream version 1.6.0
Diffstat (limited to 's/balance.h')
-rw-r--r-- | s/balance.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/s/balance.h b/s/balance.h new file mode 100644 index 0000000..cafae11 --- /dev/null +++ b/s/balance.h @@ -0,0 +1,80 @@ +// balance.h + +/** +* Copyright (C) 2008 10gen Inc. +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License, version 3, +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#pragma once + +#include "../pch.h" +#include "../util/background.h" +#include "../client/dbclient.h" +#include "balancer_policy.h" + +namespace mongo { + + class Balancer : public BackgroundJob { + public: + Balancer(); + virtual ~Balancer(); + + // BackgroundJob methods + + virtual void run(); + + virtual string name() { return "Balancer"; } + + private: + typedef BalancerPolicy::ChunkInfo CandidateChunk; + typedef shared_ptr<CandidateChunk> CandidateChunkPtr; + + /** + * Gathers all the necessary information about shards and chunks, and + * decides whether there are candidate chunks to be moved. + */ + void _doBalanceRound( DBClientBase& conn, vector<CandidateChunkPtr>* candidateChunks ); + + /** + * Execute the chunk migrations described in 'candidateChunks' and + * returns the number of chunks effectively moved. + */ + int _moveChunks( const vector<CandidateChunkPtr>* candidateChunks ); + + /** + * Check the health of the master configuration server + */ + void _ping(); + void _ping( DBClientBase& conn ); + + /** + * @return true if everything is ok + */ + bool _checkOIDs(); + + // internal state + + string _myid; // hostname:port of my mongos + time_t _started; // time Balancer starte running + int _balancedLastTime; // number of moved chunks in last round + BalancerPolicy* _policy; // decide which chunks to move; owned here. + + // non-copyable, non-assignable + + Balancer(const Balancer&); + Balancer operator=(const Balancer&); + }; + + extern Balancer balancer; +} |