MongoDB 多粒度锁定

MongoDB multi-granularity locking

MongoDB uses multi-granularity locking [1] that allows operations to lock at the global, database or collection level, and allows for individual storage engines to implement their own concurrency control below the collection (i.e., at the document-level in WiredTiger).

此外,我还了解到 MongoDB 有两种可能的存储引擎:MMAPv1(默认)和 WiredTiger。从 MongoDB 3.0 开始,第一个使用集合级锁定,第二个使用文档级锁定。 MongoDB 允许操作锁定在 GLOBAL、DATABASE 或 COLLECTION 级别是什么意思?这意味着我可以选择锁粒度?如果是,我该怎么做?这与所选存储引擎的锁定粒度(例如 WiredTiger 中的文档级)形成对比吗? 以及如何将我的存储引擎从 MMAPv1 更改为 WiredTiger? 提前致谢。

回答

And how can I change my storage engine from MMAPv1 to WiredTiger?

This page 解释:

Start 3.0 mongod. Ensure that the 3.0 mongod is running with the default MMAPv1 engine.

Export the data using mongodump. mongodump --out <exportDataDestination> Specify additional options as appropriate, such as username and password if running with authorization enabled. See mongodump for available options.

Create data directory for WiredTiger. Create a new data directory for WiredTiger. Ensure that the user account running mongod has read and write permissions for the new directory.

mongod with WiredTiger will not start with data files created with a different storage engine.

Restart the mongod with WiredTiger. Restart the 3.0 mongod, specifying wiredTiger as the --storageEngine and the newly created data directory for WiredTiger as the --dbpath. Specify additional options as appropriate.

mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> You can also specify the options in a configuration file. To specify the storage engine, use the new storage.engine setting.