-
Notifications
You must be signed in to change notification settings - Fork 97
MongoDB Locking
prohaska edited this page Apr 15, 2013
·
1 revision
- Each MongoDB database has a reader writer lock.
- There is an in memory map that allows one to find the reader write lock for a database given the database name.
- Queries on a collection in a database find the reader writer lock in the map given the database name, and acquire a read lock on the lock.
- The lock is held until the query operation completes.
- Writes to a collection in a database also find the reader writer lock in the map given the database name, and acquire a write lock on the lock.
- The lock is held until the write operation completes.
- The qlock is a global lock that supports four locking levels.
- 'r' allows concurrent 'r', 'w', and 'R' locks; blocked by 'W' locks
- 'w' allows concurrent 'r' and 'w' locks; blocked by 'R' and 'W' locks
- 'R' allows concurrent 'r' and 'R' locks; blocked by 'w' and 'W' locks
- 'W' locks are exclusive, blocked by 'r', 'w', and 'R' locks
- Queries on a collection acquire a read lock on the database's reader writer lock as described above.
- In addition, an 'r' lock is acquired on the qlock.
- Writes on a collection acquire a write lock on the database's reader write lock as described above.
- In addition, a 'w' lock is acquired on the qlock.
- Some operations in MongoDB need to lock out all other database operations. They acquire an 'R' or 'W' lock on the qlock for these operations.