NOTE
The balancer window must be sufficient to complete the migration of all data inserted during the day.
As data insert rates can change based on activity and usage patterns, it is important to ensure that the balancing window you select will be sufficient to support the needs of your deployment.
Do not use the sh.startBalancer() method when you have set an activeWindow.
上面是官方的警告:
我就想知道,如果在设置窗口的时间段没有完成数据迁移,当时间到达时,正在数据迁移会有什么后果。
请讲解下
##7月1日19点过5分,设置时间窗口为12:00-12:10
[mongodb@cst ~]$ date
Wed Jul 1 19:05:41 CST 2015
[mongodb@cst ~]$ /home/mongodb/mongodb3.0.2/bin/mongo –port=30000
MongoDB shell version: 3.0.2
connecting to: 127.0.0.1:30000/test
mongos> use config
switched to db config
mongos> sh.setBalancerState(true)
mongos> db.settings.update({ _id :”balancer” }, { $set : { activeWindow : { start :”12:00″, stop :”12:10″ } } }, true )
WriteResult({ “nMatched” : 1, “nUpserted” : 0, “nModified” : 1 })
mongos> db.settings.find()
{ “_id” : “chunksize”, “value” : 64 }
{ “_id” : “balancer”, “stopped” : false, “activeWindow” : { “start” : “12:00”, “stop” : “12:10” } }
mongos>
##此时balancer状态和数据块状态如下,数据库无任何增删改查操作:
balancer:
Currently enabled: yes
Currently running: no
Balancer active window is set between 12:00 and 12:10 server local time
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
No recent migrations
wy_test.Test
shard key: { “number” : “hashed” }
chunks:
rs1 72
rs2 72
rs3 72
too many chunks to print, use verbose if you want to force print
{ “_id” : “test”, “partitioned” : false, “primary” : “rs3” }
##向数据库insert30000000条数据
##期间由于工作原因,没有查看其状态。
##7月2日上午11点多查看状态。
balancer:
Currently enabled: yes
Currently running: yes
Balancer lock taken at Wed Jul 01 2015 23:29:05 GMT+0800 (CST) by cst.test.111:30000:1435563620:1804289383:Balancer:846930886
Balancer active window is set between 12:00 and 12:10 server local time
Collections with active migrations:
wy_test.Test started at Wed Jul 01 2015 23:29:35 GMT+0800 (CST)
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
No recent migrations
{ “_id” : “wy_test”, “partitioned” : true, “primary” : “rs3” }
wy_test.Test
shard key: { “number” : “hashed” }
chunks:
rs1 76
rs2 74
rs3 76
too many chunks to print, use verbose if you want to force print
{ “_id” : “test”, “partitioned” : false, “primary” : “rs3”
##而且服务器变得很卡,查看currentOp中慢的操作发现:moveChunk运行了52415秒。
{
“desc” : “conn623”,
“threadId” : “0x31915260”,
“connectionId” : 623,
“opid” : “rs1:45011063”,
“active” : true,
“secs_running” : 52415,
“microsecs_running” : NumberLong(“52415931651”),
“op” : “query”,
“ns” : “wy_test.Test”,
“query” : {
“moveChunk” : “wy_test.Test”,
“from” : “rs1/172.16.5.110:27017,172.16.5.111:27017”,
“to” : “rs2/172.16.5.110:27018,172.16.5.112:27018”,
“fromShard” : “rs1”,
“toShard” : “rs2”,
“min” : {
“number” : { “$minKey” : 1 }
},
“max” : {
“number” : NumberLong(“-9153541293874985355”)
},
“maxChunkSizeBytes” : NumberLong(67108864),
“shardId” : “wy_test.Test-number_MinKey”,
“configdb” : “172.16.5.110:20000,172.16.5.111:20000,172.16.5.112:20000”,
“secondaryThrottle” : true,
“waitForDelete” : false,
“maxTimeMS” : 0,
“epoch” : ObjectId(“55910a2a2f531a312c7922ff”)
},
“client_s” : “172.16.5.111:55843”,
“msg” : “step 3 of 6”,
“numYields” : 1176,
“locks” : {
},
“waitingForLock” : false,
“lockStats” : {
“Global” : {
“acquireCount” : {
“r” : NumberLong(1177),
“w” : NumberLong(1),
“R” : NumberLong(1)
},
“acquireWaitCount” : {
“R” : NumberLong(1)
},
“timeAcquiringMicros” : {
“R” : NumberLong(81107)
}
},
“Database” : {
“acquireCount” : {
“r” : NumberLong(1177),
“w” : NumberLong(1)
}
},
“Collection” : {
“acquireCount” : {
“r” : NumberLong(1177),
“W” : NumberLong(1)
}
}
}
},