• mongodb分片balance


    查看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 } } -->> { "int1" : 0, "int2" : 1 } on : rs1 Timestamp(2, 0)
                   { "int1" : 0, "int2" : 1 } -->> { "int1" : 0, "int2" : 9 } on : rs2 Timestamp(3, 0)
                   { "int1" : 0, "int2" : 9 } -->> { "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 }
  • 相关阅读:
    64.Find the Duplicate Number(发现重复数字)
    63.Perfect Squares(完美平方数)
    62.Longest Valid Parentheses(最长的有效括号)
    61.Merge k Sorted Lists(合并k个排序链表)
    60.Median of Two Sorted Arrays(两个排序数组的中位数)
    59.Target Sum(目标和)
    58.Partition Equal Subset Sum(判断一个数组是否可以分成和相等的两个数组)
    57.Queue Reconstruction by Height(按身高重建对列)
    56.Decode String(解码字符串)
    55.Top K Frequent Elements(出现次数最多的k个元素)
  • 原文地址:https://www.cnblogs.com/ExMan/p/10763257.html
Copyright © 2020-2023  润新知