fsync MongoDB behavior

92 Views Asked by At

Based on documentation, fsync with lock=true should block the writes. But what's being noticed is its still writing though its blocking the writes. Is this the expected behavior?

I installed MongoDB locally on my machine and running it as a single node replica set. MongoDB version being used is 4.2.11 enter image description here

I perform fsync as shown here under.

enter image description here

And then attempt a write, it gets blocked. I would cancel it. enter image description here

And then perform fsync unlock.

enter image description here

It is expected that the write wouldn't have worked, but it is persisted any ways. Is there a bug in fsync?

enter image description here

1

There are 1 best solutions below

0
Shailendra On

This can be possible in a scenario when you shut down the blocked insert ( e.g. by control+ C or any other mechanism) but somehow the process did not stopped and after you ran unblock fsync the command still went through in the background and was inserted OR when the insert command was blocked and after that you ran unblock fsync which made the block insert to unblock automatically. I tested this on v 4.4.10 ( on a higher version than yours) and it works perfectly fine as per documentation.

First insert one record

enter image description here

Then use fsync

enter image description here

Then try to insert one more record which will get blocked and subsequently killed using Ctrl + C

enter image description here

Then unblock fsync

enter image description here

Verify that the second insert was not successful ( this is what the expected behavior is)

enter image description here

You can also check the db.serverStatus() before and after to see the difference in "insert" commands accepted by the server. This can provide you hint as to whether the command somehow reached. The info looks like this

enter image description here