mongodb中的chunk

chunk的概念有些类似于数据库中的分区的概念。
当chunk的大小达到了chunk size的指定大小后,或chunk中的文档数量超过了Maximum number of documents per chunk to migrate mongodb会分裂这个chunk。

一个只包含一个分片键值的chunk是不能被分裂的。
默认的chunk的大小是64M,chunk的大小优缺点如下:

Small chunks lead to a more even distribution of data at the expense of more frequent migrations. This creates expense at the query routing (mongos) layer.
Large chunks lead to fewer migrations. This is more efficient both from the networking perspective and in terms of internal overhead at the query routing layer. But, these efficiencies come at the expense of a potentially uneven distribution of data.
Chunk size affects the Maximum Number of Documents Per Chunk to Migrate.
Chunk size affects the maximum collection size when sharding an existing collection. Post-sharding, chunk size does not constrain collection size.

如果修改了chunk的大小,那么现存的chunk在达到新的大小后,才分裂。chunk的分裂是元数据的操作,很快,没有进行数据的迁移也不影响分片。
chunk的迁移,迁移可以自动,也可以收工。
balancer是一个后台进程管理chunk的迁移。如果在分片中存在的最大的chunk与最小的chunk超过了migration 限制,那么balancer会开始迁移chunk保证集群中的数据分布均衡。
在sharding.archiveMovedChunks启用的时候,会在集合的命名空间下出现movechunk目录存放的额是迁移的chunk的备份。如果在迁移过程中出现问题,这些文件可以用来恢复文档。一旦迁移完成了,就不在需要这些文件了,可以删除这些文件。为了看迁移是否完成,使用sh.isBalancerRunning() 命令来查看进度。

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值