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 時,目的分片會在你前台重新建構索引。當建立索引時,集合就會被鎖住,阻止所有的讀寫直到索引建立結束。