0

I am having a replica set includes (1 primary, 1 secondary and 1 recovering server), I am performing following on primary:

  1. All writes and reads are performing on and from primary.
  2. Let's say we have one database consisting of 5 collections A, B, C, D and E

  3. We are performing write (importing or upserting) on collection A, so does it will impact on other collections? Like does mongodb allow read operation to collection B and C at the same time?

  4. Or it will perform a Write lock to database level, so it will prevent other read operation also?
  5. List item The problem I am getting at present is, I am writing on collection A it will give timeouts to the other READ operation performing on other database?

Please provide a specification with example, it would be great help..

kl78
  • 1,628
  • 1
  • 16
  • 26
Aayushi
  • 1
  • 1

1 Answers1

1

With replica sets, when mongodb writes to a collection on the primary say collection A in your case, it also writes data into the primary's oplog which syncs data to secondaries. Here, oplog collection is a part of local database.

So, mongo has to lock both the databases ie., collection's database and the local database at the same time to keep the database consistent and ensure that write operations are atomic ie., update all or nothing.

Different mongoDB operations hold different variants of locks. I would suggest you to go through the below link to have good understanding on the locking mechanism and concurrency.

https://docs.mongodb.org/manual/faq/concurrency/#mgl-ref

You can check the status of the locks by issuing db.serverStatus().locks command. It tells you the different types of locks your mongod has including oplog.

harshavmb
  • 3,404
  • 3
  • 21
  • 55
  • Thanks for reverting, I have been through this link, I want to confirm, if there is intend exclusive lock on database level i.e. small w (w), does it allow any read operation to that db? What is the difference between small w and capital W, like : "locks" : { "Global" : "w", "MMAPV1Journal" : "w", "Database" : "w", "Collection" : "W" – Aayushi Jan 13 '16 at 03:40