mongodb中的chunk

来源:互联网 发布:为什么淘宝买家有信誉 编辑:程序博客网 时间:2024/06/04 18:53

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() 命令来查看进度。

原创粉丝点击