標籤:
有些時候有於硬體資源有限,所以我們不得不進行一些回收工作,下面我們就要將剛剛啟用的Shard Server 回收,系統首先會將在這個即將被移除的Shard Server 上的資料先平均分配到其它的Shard Server 上,然後最終在將這個Shard Server 踢下線, 我們需要不停的調用db.runCommand({"removeshard" :"localhost:20002"});來觀察這個移除操作進行到哪裡了:
> use adminswitched to db admin> db.runCommand({"removeshard" : "localhost:20002"});{"msg" : "draining started successfully","state" : "started","shard" : "shard0002","ok" : 1}> db.runCommand({"removeshard" : "localhost:20002"});{"msg" : "draining ongoing","state" : "ongoing","remaining" : {"chunks" : NumberLong(44),"dbs" : NumberLong(0)},"ok" : 1}……> db.runCommand({"removeshard" : "localhost:20002"});{"msg" : "draining ongoing","state" : "ongoing","remaining" : {"chunks" : NumberLong(1),"dbs" : NumberLong(0)},"ok" : 1}> db.runCommand({"removeshard" : "localhost:20002"});{"msg" : "removeshard completed successfully","state" : "completed","shard" : "shard0002","ok" : 1}> db.runCommand({"removeshard" : "localhost:20002"});{"assertion" : "can‘t find shard for: localhost:20002","assertionCode" : 13129,"errmsg" : "db assertion failure","ok" : 0}
View Code
最終移除後,當我們再次調用db.runCommand({"removeshard" : "localhost:20002"});的時候系統會報錯,已便通知我們不存在20002 這個連接埠的Shard Server 了,因為它已經被移除掉了。
> use testswitched to db test> db.users_2.stats(){"sharded" : true,"ns" : "test.users_2","count" : 500000,"size" : 48000000,"avgObjSize" : 96,"storageSize" : 95203584,"nindexes" : 1,"nchunks" : 92,"shards" : {"shard0000" : {"ns" : "test.users_2","count" : 248749,"size" : 23879904,"avgObjSize" : 96,"storageSize" : 61875968,"numExtents" : 11,"nindexes" : 1,"lastExtentSize" : 15001856,"paddingFactor" : 1,"flags" : 1,"totalIndexSize" : 13033472,"indexSizes" : {"_id_" : 13033472},"ok" : 1},"shard0001" : {"ns" : "test.users_2","count" : 251251,"size" : 24120096,"avgObjSize" : 96,"storageSize" : 33327616,"numExtents" : 8,"nindexes" : 1,"lastExtentSize" : 12079360,"paddingFactor" : 1,"flags" : 1,"totalIndexSize" : 10469376,"indexSizes" : {"_id_" : 10469376},"ok" : 1}},"ok" : 1}
View Code
可以看出資料又被平均分配到了另外2 台Shard Server 上了!
MongoDB整理筆記の移除Shard Server