Mongodb研究---sharded cluster(集群分片)

Primary Shard(主分片)
Each database in a sharded cluster has a primary shard that holds all the un-sharded collections for that database. Each database has its own primary shard. The primary shard has no relation to the primary in a replica set.

每个database会有一个 primary shard(主分片),存储没有启用分片的集合,在数据库创建时分配。这个primary shard(主分片) 与副本集中的primary(主节点) 没有关系
Shard Status
Use the sh.status() method in the mongo shell to see an overview of the cluster. This reports includes which shard is primary for the database and the chunk distribution across the shards. See sh.status() method for more details.

可以使用Mongo Shell 中的sh.status() 命令,去查看集群状态。可以查看这个库的主分片,和chunk(数据段)在分片上的分布。

movePrimary

In a sharded cluster, movePrimary reassigns the primary shard which holds all un-sharded collections in the database. movePrimary first changes the primary shard in the cluster metadata, and then migrates all un-sharded collections to the specified shard. Use the command with the following form:

在Sharded cluster集群中,存储该库所有没有分片的集合是primary shard, movePrimary可以重新分配primary shard。movePrimary 命令首先修改cluster metadata 中的信息,然后迁移所有没有分片的集合到指定的分片。

db.runCommand( { movePrimary: <databaseName>, to: <newPrimaryShard> } )

For example, the following command moves the primary shard from test to shard0001:
db.runCommand( { movePrimary : "test", to : "shard0001" } )
When the command returns, the database’s primary shard location has switched to the specified shard. To fully decommission a shard, use the removeShard command.

当命令返回时,数据库的primary shard已经切换到指定的分片上。如果准备彻底弃用这个分片,可以使用removeShard命令。

The destination shard must rebuild its indexes in the foreground when it becomes the primary shard. The collection locks while the indexes are building, preventing reads and writes until the indexes are finished. See Index Build Operations on a Populated Collection for details.

movePrimary is an administrative command that is only available for mongos instances.

在它成为primary shard 时,目的分片会在你前台重新构建索引。当创建索引时,集合就会被锁住,阻止所有的读写直到索引创建结束。

猜你喜欢

转载自blog.csdn.net/xf_87/article/details/80561611