[toc]
均衡器the balancer attempts to evenly distribute a sharded collection』s chunks across all shards in the cluster.
對於每乙個標記為要遷移的 chunk ,均衡器檢查所有配置區域內的每乙個可能的目標分片。如果資料塊範圍屬於某乙個區域,那麼均衡器就會將該資料塊遷移到該區域上的乙個分片。不屬於任何區域的資料塊可以存在於集群中的 任何 分片,並且正常遷移。
在均衡過程中,如果均衡器檢測到任何違背已配置區域上給定的分片,均衡器將會把這些資料塊遷移到不存在衝突的分片上。
在使用乙個片鍵範圍配置區域,並且將它與乙個或多個分片關聯起來之後,集群可能會花費一些時間來遷移影響的資料。這依賴於資料塊的劃分以及目前集群中資料的分布。當均衡完成之後,在某一給定區域的文件讀取和寫入將只會路由到該區域內的乙個分片或幾個分片。
一旦配置完成後,均衡器將在 balancing rounds 中重新檢查區域。
檢視在 shards 間遷移 資料塊 的 balancer 是 開啟或關閉sh.isbalancerrunning()#檢視在 shards 間遷移 資料塊 的 balancer 是 開啟或關閉.
1、開啟關閉balanceer
關閉balancer
mongos> use config
switched to db config
mongos> sh.getbalancerstate()
true
mongos> sh.stopbalancer()
waiting for active hosts...
waiting for the balancer lock...
waiting again for active hosts after balancer is off...
writeresult()
mongos> sh.getbalancerstate()
false
#開啟mongos> sh.setbalancerstate(true)
writeresult()
mongos> sh.getbalancerstate()
true
mongos>
2、關閉或開啟某張表的balanceer#開啟
mongos> sh.disablebalancing('testdb.table1')
writeresult()
#檢視mongos> db.getsiblingdb("config").collections.findone().nobalance;
true
#關閉mongos> sh.enablebalancing('testdb.table1')
writeresult()
mongos> db.getsiblingdb("config").collections.findone().nobalance;
false
mongos> sh.disablebalancing('testdb.table1')
writeresult()
mongos> db.getsiblingdb("config").collections.findone().nobalance;
truesh.getbalancerhost()
返回乙個布林值,報告當前是否有均衡器在進行資料塊的遷移.返回負責均衡過程的乙個mongos 名字.
sh.status()
內部命令,等待指定的 sharded cluster 分布鎖.
MyCat分片規則之取模分片
除了上一章總結的列舉分片之外,mycat中還有一種比較常見的分片 取模分片規則,本節將總結如何實現取模分片。a 建立資料庫和表結構 create database testmod1 create database testmod2 use testmod1 create table user id ...
MyCat分片規則之程式指定分片
a 建立資料庫和表 b 配置server.xml 0905 testdb user testdb true c 配置schema.xml分片表 分片節點等 d 配置rule.xml分片規則 e 測試插入資料 insert into user id,name values 111,0 zhangsan...
MyCat分片規則之取模範圍分片
本文介紹另外一種分片規則 取模範圍分片,先進行取模運算再根據求餘結果範圍進行分片。下面通過示例說明在mycat中如何進行取模範圍分片,具體實現步驟如下 a 建立資料庫和表 b 配置server.xml 邏輯庫資訊 使用者資訊 c 配置rule.xml,定義取模範圍分片規則 d 配置partition...