博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mongodb分片balance
阅读量:2433 次
发布时间:2019-05-10

本文共 2025 字,大约阅读时间需要 6 分钟。

查看balance状态
mongos> sh.getBalancerState()
true
通过balance锁查看balance活动
如果state是2,表示balance锁已经被获取
mongos> db.locks.find({"_id" : "balancer"}).pretty()
{
        "_id" : "balancer",
         
"state" : 2,
        "who" : "db10:4001:1427696724:1804289383:Balancer:1681692777",
        "ts" : ObjectId("5519158885c46501a2380c4a"),
        "process" : "db10:4001:1427696724:1804289383",
        "when" : ISODate("2015-03-30T09:21:12.689Z"),
        "why" : "doing balance round"
}
设置balance窗口
db.settings.update({ _id : "balancer" }, { $set : { activeWindow : { start : "23:00", stop : "6:00" } } }, true )
查看
mongos> sh.getBalancerWindow()
{ "start" : "23:00", "stop" : "22:00" }
手动执行balance
mongos> sh.startBalancer()
集合级别启用、禁用balance
sh.enableBalancing("test.doc2")
sh.disableBalancing("test.doc2")
查看
mongos> db.getSiblingDB("config").collections.findOne({_id : "test.doc2"})
{
        "_id" : "test.doc2",
        "lastmod" : ISODate("2015-03-30T06:40:58.730Z"),
        "dropped" : false,
        "key" : {
                "_id" : "hashed"
        },
        "unique" : false,
        "lastmodEpoch" : ObjectId("5518effa291477d087fdc6fe"),
         
"noBalance" : true
}
当发现数据分配不平均时
如:
mongos> sh.status()
--- Sharding Status ---
  sharding version: {
...
...
test.doc0
               shard key: { "int1" : 1, "int2" : 1 }
               chunks:
                    rs0     1
                    rs1     1
                    rs2     1
                
{ "int1" : { "$minKey" : 1 }, "int2" : { "$minKey" : 1 } } --&gt> { "int1" : 0, "int2" : 1 } on : rs1 Timestamp(2, 0)
               { "int1" : 0, "int2" : 1 } --&gt> { "int1" : 0, "int2" : 9 } on : rs2 Timestamp(3, 0)
               { "int1" : 0, "int2" : 9 } --&gt> { "int1" : { "$maxKey" : 1 }, "int2" : { "$maxKey" : 1 } } on : rs0 Timestamp(3, 1)
...
...
上面的doc0,有3个chunk,其中rs0上的chunk包含了从0,9一直到最大值的所有数据。
此时可以split这个chunk
mongos> sh.splitAt( "test.doc0", { int1:30, int2:30 });
{ "ok" : 1 }
mongos> sh.splitAt( "test.doc0", { int1:60, int2:60 });
{ "ok" : 1 }
手工移动chunk
通过find条件,将这条记录所在的chunk移动到指定rs
mongos> db.runCommand({moveChunk:"
test.doc0", find:{
int1:30, int2:30}, to:"
rs1"})
{ "millis" : 11137, "ok" : 1 }

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26239116/viewspace-1485441/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/26239116/viewspace-1485441/

你可能感兴趣的文章
名智新系统错误表(转)
查看>>
WindowsXP自带系统还原 你知其多深(转)
查看>>
Platform Builder之旅(一)(转)
查看>>
用注册表清除计算机病毒(转)
查看>>
IE 新奇技巧28 则(转)
查看>>
提高ASP性能的最佳选择(续四)(转)
查看>>
测试你的Java段位 (转)
查看>>
C#开发WAP程序(转)
查看>>
SQL SERVER2000备份和恢复存储过程(转)
查看>>
在ASP中用“正则表达式对象”来校验数据的合法性(转)
查看>>
CDMA2000 1X EV-DO主要技术特点(转)
查看>>
微软确认新Windows DoS漏洞(转)
查看>>
通过改DLL来美化系统图标(转)
查看>>
Oracle中文技术中心
查看>>
什么是SEO(转)
查看>>
技术方案:网吧无盘存储解决方案(转)
查看>>
黑客共享代码:病毒制作竟也能开源!(转)
查看>>
WAP与PHP - 基础篇(转)
查看>>
使用AYGShell实现 CE.NET 和 PPC 外壳兼容性(转)
查看>>
Symbian 智能指针(转)
查看>>