-
Notifications
You must be signed in to change notification settings - Fork 97
MongoDB Concurrency
This wiki describes the concurrency seen by MongoDB applications and how it is implemented.
MongoDB allows concurrent queries on any collection in any database
- Query database(a).collection() || Query database(a).collection()
- Query database(a).collection() || Query database(b).collection(), a != b
MongoDB does not allow concurrent insertions to the same database
- Insert database(a).collection() blocks Insert database(a).collection()
MongoDB does allow concurrent insertions to different databases
- Insert database(a).collection() || Insert database(b).collection(), a != b
MongoDB queries block insertions to the same database
- Query database(a).collection() blocks Insert database(a).collection()
MongoDB insertions block queries in the same database
- Insert database(a).collection() blocks Query database(a).collection()
MongoDB allows concurrent insertions and queries in different databases
- Insert database(a).collection() || Query database(b).collection(), a != b
- Query database(a).collection() || Insert database(b).collection(), a != b
MongoDB does not allow concurrent queries with dropping the collection
- Query database(a).collection(b) blocks database(a).collection(b).drop
Inserts
- Grab a write lock on the database
- Find the rwlock associated with the database name in the dblocks map
- Grab a write lock on database's rwlock
- Grab a little write lock on the qlock
Insert to a non-existent collection
- TODO
Queries
- Grab a read lock on the database
- Find the rwlock associated with the database name in the dblocks map
- Grab a read lock on the database's rwlock
- Grab a little read lock on the qlock
Query a non-existent collection
- TODO
What is the dblocks map? The dblocks map is a map from database name to a reader writer lock.
How is the dblocks map used?
What is the qlock?
How is the qlock used?