並發對"主複本集"的影響?
在副本複製過程中,當在主庫執行寫操作時,mongodb也同時在寫主庫的oplog,oplog為一個local庫中特殊的集合。(在Replica Set複製集模式下,local.oplog.rs一個capped collection集合,用來儲存oplog)。因此,MongoDB必須鎖住當前寫操作的庫和local庫。mongod必須鎖定這兩個庫,保持資料的一致性和保證寫操作是“全有或全無”的操作。
什麼情況下會鎖多庫?
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.
參考連結 http://docs.mongodb.org/manual/faq/concurrency/