MongoDB 6 分片按集合拆分

huangapple go评论51阅读模式
英文:

MongoDB 6 sharding split by collection

问题

这是一个学校项目,我在理解共享密钥方面遇到了一些困难。

这是我的设置:
3台机器,每台机器都有1个配置服务器节点、1个shard1节点、1个shard2节点。然后,只是为了测试,其中一台机器有路由器。

我认为这部分工作正常:P

现在,在这个设置上,我有一个数据库,其中包含2个集合和以下字段:
se_temp:
InsertDate,Reading,SensorID(这将具有1到3个最大传感器ID之间的值)
se_door:
InsertDate,From,To -> From和To的值将在1和10之间

我尝试但没有成功的是,如果可能的话,让每个集合都分配到每个shard中。

还要注意,应用程序执行的大多数查询都基于InsertDate。

非常感谢您提前的帮助。


<details>
<summary>英文:</summary>

This is for a school project and I am having some dificultiys understading the shared keys.

This is my setup:
3 Machines each having 1 consif server node, 1 shard1 node, 1 shard2 node. and then just for testing one of this machines have the router.

I have this working fine, I think :P

Now on this I have a database that will have 2 collections and with the following fields:
     se_temp:
        InsertDate , Reading, SensorID (this will have between 1 to 3 max sensor ids)
     se_door:
        InsertDate, From, To -&gt; the from and to value will have values between 1 and 10

What I am trying to achieve with no sucess is to have each collection to each shard if this is possible.

Also to note most of the querys that the application performes is based on the InsertDate.

Thank you very much in advance.

edit to add the sh.status() output
shardingVersion
{
_id: 1,
minCompatibleVersion: 5,
currentVersion: 6,
clusterId: ObjectId("647216f9180976b065bb2686")
}

shards
[
{
_id: 'shard1ReplSet',
host: 'shard1ReplSet/X.X.X.X:27013,X.X.X.X:27011,X.X.X.X:27012',
state: 1,
topologyTime: Timestamp({ t: 1685198765, i: 3 })
},
{
_id: 'shard2ReplSet',
host: 'shard2ReplSet/X.X.X.X:27023,X.X.X.X:27021,X.X.X.X:27022',
state: 1,
topologyTime: Timestamp({ t: 1685198770, i: 3 })
}
]

most recently active mongoses
[ { '6.0.4': 1 } ]

autosplit
{ 'Currently enabled': 'yes' }

balancer
{
'Currently running': 'yes',
'Currently enabled': 'yes',
'Failed balancer rounds in last 5 attempts': 0,
'Migration Results for the last 24 hours': 'No recent migrations'
}

databases
[
{
database: { _id: 'config', primary: 'config', partitioned: true },
collections: {
'config.system.sessions': {
shardKey: { _id: 1 },
unique: false,
balancing: true,
chunkMetadata: [ { shard: 'shard1ReplSet', nChunks: 1024 } ],
chunks: [
'too many chunks to print, use verbose if you want to force print'
],
tags: []
}
}
},
{
database: {
_id: 'pisidg23',
primary: 'shard2ReplSet',
partitioned: false,
version: {
uuid: new UUID("ce24dbdb-8eaf-4b83-9103-6636590e6efd"),
timestamp: Timestamp({ t: 1685198773, i: 1 }),
lastMod: 1
}
},
collections: {}
}
]

答案1

得分: 1

  1. 你不能为不同的集合选择不同的主要分片,但如果你的集合位于不同的数据库中,那么是的,你可以将不同的数据库中的主要数据库分片移动到每个数据库的不同分片中。

  2. 你需要非常谨慎地选择分片键索引,因为如果你发送的查询不是分片键的一部分,那么查询将被发送到所有分片。如果你不经常在查询中使用你的索引,最好选择不同的索引作为分片键。

英文:
  1. You cannot select different primary shards per collection, but if your collections are in different databases then - yes , you can move the primary database shard in different shard per each database.
  2. You need to choose the shard key index very carefully since the queries you send to your collection if not part of shard key will be send to all shards. If you dont use often your index in queries better choose different index for shard key.

huangapple
  • 本文由 发表于 2023年5月29日 04:07:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76353398.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定