Chapter 4 Insert Performance

I am wondering what happens with ‘{ w: majority or > 1, j: true }’.

About j:true, the lecture mentions that the acknowledge of the CRUD operation is sent back to the client when journal is written on disk.

For example, with w:2 and j:true, is the acknowledge sent back to the client when the journals of the primary and the other node are written on disk or when the journal of the primary is written and one other node has applied the CRUD op.

1 Like

@ steevej-1495

Basically, the two are semi-independent. The w: value controls the number of nodes that have to respond; the j: value means that the journal has been written to disk on the primary. The full documentation on W: is here and more information on journaling is here.

For all practical purposes, however, the op will most likely have been written to both journals; notice that the journaling takes place when the operation is complete on the mongod instance (which is when you would get the acknowledgement of the completed op) and, in the case of WiredTiger, the journal record is made in memory first, then written to disk every 50 milliseconds.

1 Like

Thanks I will read with great care the 2 links you provided. However I will risk asking a related question. Sorry if the 2 links would have give me the answer.

Does the secondaries acknowledge the client’s driver directly and it is the driver that ensures that w:n is met or does the secondaries acknowledge the primary and then the primary acknowledge the driver when w:n is met. It might not be relevant as it might be too implementation specific.

I can see benefits in the 2 cases.

  1. When the secondaries acknowledge to the driver, the primary has less work to do as it only cares about its own acknowledgement. But each driver has to implement the logic to ensure w:n is met.
  2. When the secondaries acknowledge to the primary, the driver are simple since they only wait 1 acknowledge that will come from the primary when w:n is met. But the load on the primary is higher since it has to manage the w:n of all the clients.

As a developer I am curious of how it is done. But I would understand if you prefer not to go into the implementation details. One thing is sure is that for the client, the driver’s user, it does not change anything.

Thanks again.

1 Like

@ steevej-1495

No problem. I’m fairly sure the links won’t tell you that. And, to be clear, I’m not on the development team, so I don’t really know either. :wink:

My best guess is that the information flows back to the primary, and is passed on from there to the driver. Remember that the secondary members of the replica set are being fed from the oplog, and I don’t think the w: or j: options are passed to them directly. But, again, that’s just a guess. If you can come up with a use case for this, you could post this question on one of the MongoDB Support Forums or ask the Community. A list of those links is here. Good luck.