mongodb 中的主分片 [英] primary shards in mongodb

查看:101
本文介绍了mongodb 中的主分片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查看 mongodb 分片的文档,但我对主分片的分配方式和主分片的含义感到有些困惑

I am trying to go through the documents for mongodb sharding and I am a bit confused about how the primary shards are assigned and the meaning of primary shards

根据文档统计,

每个数据库都有一个主分片,用于保存所有未分片的数据数据库的集合.主分片与副本集中的主节点.

Every database has a primary shard that holds all the un-sharded collections for a database. The primary shard has no relation to the primary in a replica set.

这是否意味着主分片是第一次创建数据库的分片中的分片(或服务器集合)?

does this mean that a primary shard is the shard (or the collection of servers) in the shard where the database was first created ?

假设我有 3 个分片 s0、s1 和 s2.在每个分片中,我有 3 个服务器

Say I have 3 shards s0, s1 and s2. In each shard i have 3 servers

  • s0 服务器 1(主)
  • s0 服务器 2(辅助)
  • s0 - 服务器 3(辅助)

  • s0 Server 1 (Primary)
  • s0 Server 2 (Secondary)
  • s0 - Server 3 (Secondary)

s1 - 服务器 4(主要)

s1 - Server 4 (Primary)

s1 - 服务器 6(辅助)

s1 - Server 6(Secondary)

s2 - 服务器 7(主)

s2 - Server 7(Primary)

现在,当我通过 mongoclient 和 mongos 创建新数据库时.现在说请求转到分片 1 (s1).由于创建数据库是一个写操作,它会转到分片 1 中的服务器 4,因此 s1 成为主分片?

Now when I create a new database via a mongoclient and via mongos . Now say that request goes to the shard 1 (s1). Since create database is a write operation it would go to the server 4 in shard 1 and thus s1 becomes by primary shard ?

另一方面,如果请求将遍历到 s2 分片,那么服务器 7 将作为主服务器创建集合,然后 s2 将成为我的主分片?

If on the other hand the request would have traversed to s2 shard then server 7 would being primary would have created the collection and then s2 would have been my primary shard ?

这种理解是正确的还是我哪里出错了?

Is this understanding correct or I am going wrong some where ?

推荐答案

是的,你说得对!并且你理解了概念.

Yes, you are right! And you understanded concept.

只要您不分片单个集合,集合必须具有主要位置,位于其中一个副本集.因此,将这些单独的碎片视为单独的 RS.因此,一个 DB 位于一个分片,如果您在 DB 内对集合进行分片,则集合平衡"到多个分片.使用 TAG,您可以决定该系列的分布位置.正常情况是均匀分布到所有分片.

As long as you don't shard individual collection, collection must have primary location, at one of the replica sets. So, think those individual shards as individual RS's. So, one DB is located to one shard and if you shard collection inside DB, collection is "balanced" to multiple shards. With TAG's you can decide where that collection is spread. Normal situation is spread it to all shards evenly.

而且您始终可以决定 DB 的主要位置是什么.创建后,你可以移动"它,当数据库仍然是空的或很小的时候,它的运行速度很快.movePrimary

And you can always make decision what is DB's primary location. After creating, you can "move" it, when DB is still empty or quite small, it's fast operation. movePrimary

这篇关于mongodb 中的主分片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆