Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB sharding, how does it rebalance when adding new nodes?

I'm trying to understand MongoDB and the concept of sharding. If we start with 2 nodes and partition say, customer data, based on last name where A thru M data is stored on node 1 and N thru Z data is stored on node 2. What happens when we want to scale out and add more nodes? I just don't see how that will work.

like image 513
user646584 Avatar asked Jul 04 '11 20:07

user646584


People also ask

How does sharding work in MongoDB?

MongoDB uses the shard key to distribute a collection's documents across shards. MongoDB splits the data into “chunks”, by dividing the span of shard key values into non-overlapping ranges. MongoDB then attempts to distribute those chunks evenly among the shards in the cluster.

What does it makes a difference when sharding combined with replication?

What is the difference between replication and sharding? Replication: The primary server node copies data onto secondary server nodes. This can help increase data availability and act as a backup, in case if the primary server fails. Sharding: Handles horizontal scaling across servers using a shard key.

At which point does the balancer decide to start moving chunks from one shard to another?

The balancer process sends the moveChunk command to the source shard. The source starts the move when it receives an internal moveRange command.

How does MongoDB increase sharding performance?

Sharding with MongoDB allows you to seamlessly scale the database as your applications grow beyond the hardware limits of a single server, and it does so without adding complexity to the application.


1 Answers

If you have 2 nodes it doesn't mean that data is partitioned into 2 chunks. It can by partitioned to let's say 10 chunks and 6 of them are on server 1 ane rest is on server 2.

When you add another server MongoDB is able to redistribute those chunks between nodes of new configuration

You can read more in official docs:

  • http://www.mongodb.org/display/DOCS/Sharding+Introduction

  • http://www.mongodb.org/display/DOCS/Choosing+a+Shard+Key

like image 170
Daimon Avatar answered Oct 10 '22 05:10

Daimon