클라우드 컴퓨팅 & NoSQL/MongoDB

mongodb locking

조대협 2014. 1. 2. 15:01

* Single write lock (per database)

* Reader-Writer lock :  allowing concurrent access to multiple threads for reading but restricting access to a single thread for writes (or other changes) to the resource


(from wikipedia) In computer science, a readers-writer or shared-exclusive lock (also known as the multiple readers / single-writer lock[1] or the multi-reader lock,[2] or by typographical variants such as readers/writers lock) is a synchronization primitive that solves one of the readers-writers problems. A readers-writer lock is like a mutex, in that it controls access to a shared resource, allowing concurrent access to multiple threads for reading but restricting access to a single thread for writes (or other changes) to the resource. A common use might be to control access to a data structure in memory that can't be updated atomically and isn't valid (and shouldn't be read by another thread) until the update is complete.


* Yield lock 

 - from version 2.0 if page fault has been occured in mongod (data is not loaded to memory). It yield lock 

 - long running read locks will ield periodically to ensure that write operations have the opportunity to complete. 


* Sharding & Locking : the lock is not shared across the shard. each shard has its own locking

* Replication & Locking

 - Primary to secondary replication is done by batch way. it copies oplog to secondary and run it as a batch. 


참고 : mongodb FAQ/locking