Q. Write Concern : wtimeout

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 for w values greater than 1 .

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 the wtimeout 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 a wtimeout value of 0 is equivalent to a write concern without the wtimeout option.

Q1. wtimeout can be set by the application to guarantee that:

  1. MongoDB will roll back the write operations if the nodes do not acknowledge the write operation within the specified wtimeout.
  2. The application will learn how many servers have performed the write within wtimeout.
  3. 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?

  1. For the other node in which the operation is not completed, the operation is terminated.
  2. For the other node in which the operation is not completed, wait even after wtimeout has elapsed until the operation is completed.

Hi @Kim_Hakseon,

Your understanding is correct. I assume Q1 comes from a course quiz or exam practice question, but the initial information you have quoted from the documentation is accurate.

Only one of the statements in Q1 is True:

  1. MongoDB will roll back the write operations if the nodes do not acknowledge the write operation within the specified wtimeout.

False. Quoting from the docs above:

When these write operations return, MongoDB does not undo successful data modifications performed before the write concern exceeded the wtimeout time limit.

  1. The application will learn how many servers have performed the write within wtimeout.

False. The write concern acknowledgement will be returned earlier than the wtimeout if write operations have been ack’d by the required number of replica set members.

    1. If a write is acknowledged, the replica set has applied the write on a number of servers within the specified wtimeout.

True!

Regards,
Stennie

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.