mongo::Balancer Class Reference

#include <balance.h>

Inheritance diagram for mongo::Balancer:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 Balancer ()
virtual string name () const
virtual void run ()
virtual ~Balancer ()

Private Types

typedef BalancerPolicy::ChunkInfo CandidateChunk
typedef shared_ptr
< CandidateChunk
CandidateChunkPtr

Private Member Functions

bool _checkOIDs ()
void _doBalanceRound (DBClientBase &conn, vector< CandidateChunkPtr > *candidateChunks)
bool _init ()
int _moveChunks (const vector< CandidateChunkPtr > *candidateChunks)
void _ping (DBClientBase &conn)

Private Attributes

int _balancedLastTime
string _myid
BalancerPolicy_policy
time_t _started

Detailed Description

The balancer is a background task that tries to keep the number of chunks across all servers of the cluster even. Although every mongos will have one balancer running, only one of them will be active at the any given point in time. The balancer uses a 'DistributedLock' for that coordination.

The balancer does act continuously but in "rounds". At a given round, it would decide if there is an imbalance by checking the difference in chunks between the most and least loaded shards. It would issue a request for a chunk migration per round, if it found so.

Definition at line 36 of file balance.h.


Member Typedef Documentation

Definition at line 37 of file balance.h.

typedef shared_ptr<CandidateChunk> mongo::Balancer::CandidateChunkPtr [private]

Definition at line 38 of file balance.h.


Constructor & Destructor Documentation

mongo::Balancer::Balancer (  ) 
virtual mongo::Balancer::~Balancer (  )  [virtual]

Member Function Documentation

bool mongo::Balancer::_checkOIDs (  )  [private]
Returns:
true if all the servers listed in configdb as being shards are reachable and are distinct processes
void mongo::Balancer::_doBalanceRound ( DBClientBase conn,
vector< CandidateChunkPtr > *  candidateChunks 
) [private]

Gathers all the necessary information about shards and chunks, and decides whether there are candidate chunks to be moved.

Parameters:
conn is the connection with the config server(s)
candidateChunks (IN/OUT) filled with candidate chunks, one per collection, that could possibly be moved
bool mongo::Balancer::_init (  )  [private]

Checks that the balancer can connect to all servers it needs to do its job.

Returns:
true if balancing can be started

This method throws on a network exception

int mongo::Balancer::_moveChunks ( const vector< CandidateChunkPtr > *  candidateChunks  )  [private]

Issues chunk migration request, one at a time.

Parameters:
candidateChunks possible chunks to move
Returns:
number of chunks effectively moved
void mongo::Balancer::_ping ( DBClientBase conn  )  [private]

Marks this balancer as being live on the config server(s).

Parameters:
conn is the connection with the config server(s)
virtual string mongo::Balancer::name (  )  const [inline, virtual]

Implements mongo::BackgroundJob.

Definition at line 34 of file balance.h.

virtual void mongo::Balancer::run (  )  [virtual]

define this to do your work. after this returns, state is set to done. after this returns, deleted if deleteSelf true.

NOTE: if run() throws, the exception will be caught within 'this' object and will ultimately lead to the BackgroundJob's thread being finished, as if run() returned.

Implements mongo::BackgroundJob.


Member Data Documentation

Definition at line 47 of file balance.h.

string mongo::Balancer::_myid [private]

Definition at line 41 of file balance.h.

Definition at line 50 of file balance.h.

time_t mongo::Balancer::_started [private]

Definition at line 44 of file balance.h.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


mongodb
Author(s): Nate Koenig
autogenerated on Fri Jan 11 12:15:53 2013