什么情况下会锁多库?
MongoDb如下操作会产生锁多库的情况:
db.copyDatabase() 启用全局锁
Journaling,它是一个内部的操作,将短时间内锁定所有的库。所有的库将共享一个Journal。
User authentication,锁定admin库和用户登录的库
All writes to a replica set’s primary 锁定接收写操作的数据库和local库,锁定local库使得mongod在primary中写oplog。
如下为原文:
How does concurrency affect a replica set primary?
In replication, when MongoDB writes to a collection on the primary, MongoDB also writes to the primary’s oplog, which is a special collection in the local database. Therefore, MongoDB must lock both the collection’s database and the local database. The mongod must lock both databases at the same time keep both data consistent and ensure that write operations, even with replication, are “all-or-nothing” operations.
Does a MongoDB operation ever lock more than one database?
The following MongoDB operations lock multiple databases:
db.copyDatabase() must lock the entire mongod instance at once.
Journaling, which is an internal operation, locks all databases for short intervals. All databases share a single journal.
User authentication locks the admin database as well as the database the user is accessing.
All writes to a replica set’s primary lock both the database receiving the writes and the local database. The lock for the local database allows the mongod to write to the primary’s oplog.