despot
despot

Reputation: 7377

read lock yealds when MongoDB predicts data not in memory?

Changed in version 2.2: The use of yielding expanded greatly in MongoDB 2.2. Including the “yield for page fault.” MongoDB tracks the contents of memory and predicts whether data is available before performing a read. If MongoDB predicts that the data is not in memory a read operation yields its lock while MongoDB loads the data to memory. Once data is available in memory, the read will reacquire the lock to complete the operation.

Taken from "Does a read or write operation ever yield the lock?"

Imagine that a write operation acquires the lock. How can a write be performed (change a certain collection) while MongoDB reading the data from the same collection. What happens if part of the read collection was not changed by the write and part of it was changed?

Upvotes: 0

Views: 91

Answers (1)

Sammaye
Sammaye

Reputation: 43884

Imagine that a write operation acquires the lock. How can a write be performed (change a certain collection) while MongoDB reading the data from the same collection.

It cannot, MongoDB has a writer greedy read/write database level lock ( http://docs.mongodb.org/manual/faq/concurrency/#what-type-of-locking-does-mongodb-use ).

While a single document write is occuring MongoDB is blocked from reading on a database wide level.

What happens if part of the read collection was not changed by the write and part of it was changed?

MongoDB is transactional to a single document which means that if a part of a large multi update fails then it fails, there is no rollback or atomicity or transaction for the life time of the multi update.

Upvotes: 1

Related Questions