zoukankan      html  css  js  c++  java
  • MongoDB的local库锁库现象分析

    并发对"主副本集"的影响?

    在副本复制过程中,当在主库执行写操作时,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/

  • 相关阅读:
    shiro
    leetcode696 C++ 36ms 计算二进制子串
    leetcode557 C++ 56ms 反转字符串中的每个单词
    leetcode657 C++ 16ms 判断回环
    leetcode709 C++ 4ms 转换成小写字母
    leetcode141 C++ 8ms 环形链表
    leetcode160 C++ 32ms 相交链表
    leetcode234 C++ 28ms 回文链表
    leetcode203 C++ 28ms 删除链表中满足条件的节点
    leetcode83 C++ 12ms 删除有序链表中的重复元素
  • 原文地址:https://www.cnblogs.com/mytech/p/3135984.html
Copyright © 2011-2022 走看看