Nosql Mongodb之旅(30)—MongoDB移除Shard Server

前端之家收集整理的这篇文章主要介绍了Nosql Mongodb之旅(30)—MongoDB移除Shard Server前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

[plain] view plain copy
  1. >useadmin
  2. switchedtodbadmin
  3. >db.runCommand({"removeshard":"localhost:20002"});
  4. {
  5. "msg":"drainingstartedsuccessfully",
  6. "state":"started",
  7. "shard":"shard0002",248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "ok":1
  8. }
  9. >db.runCommand({"removeshard":"localhost:20002"});
  10. {
  11. "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":{
  12. "chunks":NumberLong(44),248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "dbs":NumberLong(0)
  13. },248); line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> ……
  14. "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":{
  15. "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)
  16. },108); list-style:decimal-leading-zero outside; color:inherit; line-height:21px; margin:0px!important; padding:0px 3px 0px 10px!important"> "ok":1
  17. }
  18. "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
  19. }
最终移除后,当我们再次调用db.runCommand({"removeshard" : "localhost:20002"});的时候系统会报错,已便通知我们不存在20002 这个端口的Shard Server 了,因为它已经被移除掉了。
    >usetest
  1. switchedtodbtest
  2. >db.users_2.stats()
  3. "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":{
  4. "shard0000":{
  5. "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":{
  6. "_id_":13033472
  7. "shard0001":{
  8. "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":{
  9. "_id_":10469376
  10. }
可以看出数据又被平均分配到了另外2 台Shard Server 上了!
原文链接:https://www.f2er.com/nosql/204146.html

猜你在找的NoSQL相关文章