MongoDB的local庫鎖庫現象分析

來源:互聯網
上載者:User

並發對"主複本集"的影響?

在副本複製過程中,當在主庫執行寫操作時,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/

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.