Book Image

MongoDB High Availability

By : Afshin Mehrabani
Book Image

MongoDB High Availability

By: Afshin Mehrabani

Overview of this book

Table of Contents (17 chapters)
MongoDB High Availability
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Understanding database locks


MongoDB uses read/write locks to prevent conflicts between write/read operations and also makes sure that all clients receive the same dataset with the same query.

MongoDB uses the readers-writer lock to prevent conflicts and control the read/write operations.

Note

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. For more information, please visit http://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock.

MongoDB uses the shared read-lock, which means that many operations can use the existing read-lock. On the other hand, a write-lock is limited to a single operation, which means that no more write operations can use and share the existing lock.

The MongoDB lock mechanism gets better with each version. Before v2.2, MongoDB had a global lock per mongod instance for most read/write...