While studying, there are something that I didn’t fully understand.
It’s wtimeout.
wtimeout
This option specifies a time limit, in milliseconds, for the write concern.
wtimeout
is only applicable forw
values greater than1
.
wtimeout
causes write operations to return with an error after the specified limit, even if the required write concern will eventually succeed. When these write operations return, MongoDB does not undo successful data modifications performed before the write concern exceeded thewtimeout
time limit.If you do not specify the
wtimeout
option and the level of write concern is unachievable, the write operation will block indefinitely. Specifying awtimeout
value of0
is equivalent to a write concern without thewtimeout
option.
Q1. wtimeout can be set by the application to guarantee that:
- MongoDB will roll back the write operations if the nodes do not acknowledge the write operation within the specified wtimeout.
- The application will learn how many servers have performed the write within wtimeout.
- If a write is acknowledged, the replica set has applied the write on a number of servers within the specified wtimeout.
I got curious while looking at No. 1 in this question.
First of all, I understood that the rollback was not possible even after wtimeout.
This means that when {w:3} and {wtimeout:n} were given in a replica set with three nodes, only two nodes were completed at the end of wtimeout.
Rollback won’t work for two, but what happens to the other node?
- For the other node in which the operation is not completed, the operation is terminated.
- For the other node in which the operation is not completed, wait even after wtimeout has elapsed until the operation is completed.