当前位置:Gxlcms > 数据库问题 > Mongodb锁问题

Mongodb锁问题

时间:2021-07-01 10:21:17 帮助过:41人阅读


 WiredTiger:对于大部分的读写操作,WiredTiger使用乐观锁。WiredTiger对于全局、数据库、集合级别只会使用意向锁。当存储引擎检测到两个操作之间的冲突,一个写冲突导致MongoDB透明地重试写操作。一些全局操作,跟2.2版本一样还是会需要全局锁,例如,删除一个集合,那么仍然还是需要一个互斥的数据库锁的。


如何查看锁的状态

db.serverStatus()
db.currentOp()
mongotop
mongostat

产生数据库锁的操作

操作 锁类型
Issue a query Read lock
Get more data from a cursor Read lock
Insert data Write lock
Remove data Write lock
Update data Write lock
Map-reduce Read lock and write lock, unless operations are specified as non-atomic. Portions of map-reduce jobs can run concurrently.
Create an index Building an index in the foreground, which is the default, locks the database for extended periods of time.

db.eval() Write lock.

二.原子操作但不支持事务

所谓原子操作就是要么对这个文档操作全部成功,要么全部失败,不会出现查询到的文档没有保存完整的情况
mongodb不支持事务,所以,在你的项目中应用时,要注意这点。无论什么设计,都不要要求mongodb保证数据的完整性。但是mongodb对单个文档的操作提供了许多原子操作,比如文档的保存,修改(包括对单个文档修改多个字段),删除等,都是原子操作。

 

Mongodb锁问题

标签:共享   需要   rom   ext   cursor   包括   完整性   操作   issue   

人气教程排行