MongoDB分片,添加新节点时如何重新平衡?
我正在尝试了解 MongoDB 和分片的概念。如果我们从 2 个节点开始,并根据姓氏对客户数据进行分区,其中 A 到 M 数据存储在节点 1 上,N 到 Z 数据存储在节点 2 上。当我们想要横向扩展并添加更多节点时会发生什么?我只是不明白那会如何运作。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有 2 个节点,并不意味着数据会被划分为 2 个块。它可以分区为 10 个块,其中 6 个位于服务器 1 上,其余位于服务器 2 上。
当您添加另一台服务器时,MongoDB 能够在新配置的节点之间重新分配这些块
您可以在官方文档中阅读更多信息:
http://www.mongodb.org/display/DOCS/Choosing+a+Shard+Key
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
如果有多个分片可用,MongoDB将开始将数据迁移到其他分片
一旦你有足够数量的块。这种迁移称为平衡,并且是
由一个称为平衡器的进程执行。平衡器将块从一个分片移动到另一个分片。
为了进行平衡轮,一个分片必须比当前分片至少多 9 个块。
人口最少的碎片。那时,块将从拥挤的分片中迁移出来
直到与其余碎片齐平。
当您向集群添加新节点时,MongoDB 会在新配置的节点之间重新分配这些块。
这是一个小摘录,要完全了解添加新节点时如何重新平衡,请阅读 Kristina Chodrow 的书“Scaling MongoDB”的第 2 章“Understanding Sharding”
If there are multiple shards available, MongoDB will start migrating data to other shards
once you have a sufficient number of chunks. This migration is called balancing and is
performed by a process called the balancer.The balancer moves chunks from one shard to another.
For a balancing round to occur, a shard must have at least nine more chunks than the
least-populous shard. At that point, chunks will be migrated off of the crowded shard
until it is even with the rest of the shards.
When you add new node to cluster, MongoDB redistribute those chunks among nodes of new configuration.
It's a little extract ,to get complete understanding of how does it rebalance when adding new node read chapter 2 "Understanding Sharding" of Kristina Chodrow's book "Scaling MongoDB"