码迷,mamicode.com
首页 > 数据库 > 详细

MongoDB整理笔记の移除Shard Server

时间:2015-01-24 13:05:57      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:

    有些时候有于硬件资源有限,所以我们不得不进行一些回收工作,下面我们就要将刚刚启用的Shard Server 回收,系统首先会将在这个即将被移除的Shard Server 上的数据先平均分配到其它的Shard Server 上,然后最终在将这个Shard Server 踢下线, 我们需要不停的调用db.runCommand({"removeshard" :"localhost:20002"});来观察这个移除操作进行到哪里了:

技术分享
> use admin
switched 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 test
switched 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

标签:

原文地址:http://www.cnblogs.com/tomcatx/p/4245682.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!