0

Given a replica set with 3 data bearing members, and MongoDB 2.6.3 (I'm also interested in the behavior of later versions if they differ) and a default write concern:

Does MongoDB (2.6 or 3.x) lock on updates until all replica sets verify the writes? That seems like a recipe for pretty slow writes.

Community
  • 1
  • 1
Antonius Bloch
  • 2,311
  • 2
  • 14
  • 14

1 Answers1

1

No; this behaviour is not the default; it is possible to request such a write concern, but only by specifying verification from a number of nodes in the replica set.

The default writeconcern is 1, which means that the update returns an acknowledgement as soon as the primary node has written the update.

Other available writeconcerns are:

  • "majority" (a majority of nodes have written the update)
  • by number (the specified number of nodes have written the update)
  • by tag (at least one node with the specified tag have written the update)

If you have a 3-member replica set, then specifying a write concern of 3 will make the primary wait (before acknowledgement to the client) until all 3 nodes have written the update.

The MongoDB site's documentation is pretty clear: - MongoDB v2.6 documentation on writeConcern - MongoDB v3.4 documentation on writeConcern

PS writeConcern affects how the replica set sends an acknowledgement back to the client; however locking is a different matter, and affects the primary only in practice.

Vince Bowdren
  • 8,326
  • 3
  • 31
  • 56
  • 1
    A further write concern consideration worth noting is whether the operation is acknowledged in-memory or on-disk (i.e. durable write in the journal). The replica set section of Write Concern [Acknowledgement Behaviour](https://docs.mongodb.com/manual/reference/write-concern/#replica-sets) goes into more detail on the options and configurations that influence this. Increasing the number of nodes or level of persistence will add latency to write acknowledgement but provide stronger guarantees for durability and avoiding [rollbacks](https://docs.mongodb.com/manual/core/replica-set-rollbacks/). – Stennie Mar 23 '17 at 20:42