有些时候有于硬件资源有限,所以我们不得不进行一些回收工作,下面我们就要将刚刚启用的Shard Server 回收,系统首先会将在这个即将被移除的Shard Server 上的数据先平均分配到其它的Shard Server 上,然后最终在将这个Shard Server 踢下线,我们需要不停的调用db.runCommand({"removeshard" :"localhost:20002"});来观察这个移除操作进行到哪里了:
- >useadmin
- switchedtodbadmin
- >db.runCommand({"removeshard":"localhost:20002"});
- {
- "msg":"drainingstartedsuccessfully",
- "state":"started",
- "shard":"shard0002",248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "ok":1
- }
- >db.runCommand({"removeshard":"localhost:20002"});
- {
- "msg":"drainingongoing",108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "state":"ongoing",248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "remaining":{
- "chunks":NumberLong(44),248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "dbs":NumberLong(0)
- },248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> ……
- "msg":"drainingongoing",248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "state":"ongoing",108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "remaining":{
- "chunks":NumberLong(1),108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "dbs":NumberLong(0)
- },108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "ok":1
- }
- "msg":"removeshardcompletedsuccessfully",248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "state":"completed",248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "assertion":"can'tfindshardfor:localhost:20002",108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "assertionCode":13129,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "errmsg":"dbassertionfailure",108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "ok":0
- }
- >usetest
- switchedtodbtest
- >db.users_2.stats()
- "sharded":true,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "ns":"test.users_2",108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "count":500000,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "size":48000000,108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "avgObjSize":96,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "storageSize":95203584,108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "nindexes":1,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "nchunks":92,108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "shards":{
- "shard0000":{
- "ns":"test.users_2",248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "count":248749,108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "size":23879904,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "avgObjSize":96,108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "storageSize":61875968,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "numExtents":11,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "lastExtentSize":15001856,108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "paddingFactor":1,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "flags":1,108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "totalIndexSize":13033472,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "indexSizes":{
- "_id_":13033472
- "shard0001":{
- "count":251251,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "size":24120096,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "storageSize":33327616,108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "numExtents":8,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "nindexes":1,108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "lastExtentSize":12079360,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "paddingFactor":1,108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "flags":1,248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "totalIndexSize":10469376,108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "indexSizes":{
- "_id_":10469376
- }