首页 > 数据库 >MongoDB复制集APS架构问题(writeConcern)

MongoDB复制集APS架构问题(writeConcern)

时间:2023-03-10 10:32:11浏览次数:41  
标签:wtimeout acquireCount 6000 MongoDB db writeConcern APS test


当前数据库采用APS架构(主、从、仲裁),考虑对服务器进行迁移,迁移从库时,主库无法写入

查看应用链接配置发现端倪

mongo复制集从库关机,对write-concern参数进行测试

[mongo@Mon02 ~]$ mongo
MongoDB shell version v4.4.16
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("265bba7f-21bf-496d-942d-fd904127ee09") }
MongoDB server version: 4.4.16
MongoRepl:SECONDARY> use admin
switched to db admin
MongoRepl:SECONDARY> db.auth("admin","cpcn1234")
1
MongoRepl:SECONDARY> db.shutdownServer()
server should be down...
>

测试writeConcern各参数现象

MongoRepl:PRIMARY> db.test.insert({name:'test9'},{writeConcern:{w:'majority',wtimeout:6000}})
WriteResult({
"nInserted" : 1,
"writeConcernError" : {
"code" : 64,
"codeName" : "WriteConcernFailed",
"errmsg" : "waiting for replication timed out",
"errInfo" : {
"wtimeout" : true,
"writeConcern" : {
"w" : "majority",
"wtimeout" : 6000,
"provenance" : "clientSupplied"
}
}
}
})

w:‘majority’,6秒后返回错误

MongoRepl:PRIMARY> db.test.insert({name:'test7'},{writeConcern:{w:0}})
WriteResult({ })

w:0,可正常写入

MongoRepl:PRIMARY> db.test.insert({name:'test5'},{writeConcern:{w:1}})
WriteResult({ "nInserted" : 1 })

w:1,可正常写入

MongoRepl:PRIMARY> db.test.insert({name:'test8'},{writeConcern:{w:2,wtimeout:6000}})
WriteResult({
"nInserted" : 1,
"writeConcernError" : {
"code" : 64,
"codeName" : "WriteConcernFailed",
"errmsg" : "waiting for replication timed out",
"errInfo" : {
"wtimeout" : true,
"writeConcern" : {
"w" : 2,
"wtimeout" : 6000,
"provenance" : "clientSupplied"
}
}
}
})

w:2,6秒后返回错误

报错时日志信息

关键字 “Slow query”,“writeConcern”

more /mongodb/mongod.log
{"t":{"$date":"2022-08-30T13:50:01.621+08:00"},"s":"I", "c":"COMMAND", "id":51803, "ctx":"conn58","msg":"Slow query","attr":{"type":"command","ns":"test.test","appName":"MongoDB Shell","command":{"insert":"test","ordered":true,"writeConcern":{"w":2.0,"wtimeout":6000.0},"lsid":{"id":{"$uuid":"55eb7aad-324a-41dc-9f41-aa213628acec"}},"$clusterTime":{"clusterTime":{"$timestamp":{"t":1661833513,"i":2}},"signature":{"hash":{"$binary":{"base64":"9GLSLDyutIlwuTiqCOKrKWwrQmU=","subType":"0"}},"keyId":7136548260675584003}},"$db":"test"},"ninserted":1,"keysInserted":1,"numYields":0,"reslen":439,"locks":{"ParallelBatchWriterMode":{"acquireCount":{"r":1}},"FeatureCompatibilityVersion":{"acquireCount":{"w":1}},"ReplicationStateTransition":{"acquireCount":{"w":1}},"Global":{"acquireCount":{"w":1}},"Database":{"acquireCount":{"w":1}},"Collection":{"acquireCount":{"w":1}},"Mutex":{"acquireCount":{"r":1}}},"flowControl":{"acquireCount":1,"timeAcquiringMicros":2},"writeConcern":{"w":2,"wtimeout":6000,"provenance":"clientSupplied"},"storage":{},"protocol":"op_msg","durationMillis":6019}}


标签:wtimeout,acquireCount,6000,MongoDB,db,writeConcern,APS,test
From: https://blog.51cto.com/u_14852239/6112559

相关文章