2

I'm running mongo 3.4.7 (WiredTiger) replica set with two secondaries.

According to the docs, when journaling is enabled and write concern is {w: "majority", j: 0}, the ack is sent after the data is written to "In memory".

However the docs don't specify what happens when journaling is off on the server (--nojournal). What happens in that case? What is the write concern waiting for?

2 Answers 2

1

Since you're using MongoDB 3.4.7 with WiredTiger, there are certain defaults in place if you run MongoDB with the default values (journal is enabled):

If you run MongoDB without journaling, using {w:'majority', j:true} will result in an error (see the Note section on j option):

[PRIMARY:replset] test> db.test.insert({a:1},{writeConcern:{w:'majority', j:true}})
WriteResult({
  "writeError": {
    "code": 2,
    "errmsg": "cannot use 'j' option when a host does not have journaling enabled"
  }
})

Please note that counter-intuitively, running WiredTiger with the --nojournal option may make it slower. This is because WiredTiger performs a checkpoint every 60 seconds or 2 GB of data in MongoDB 3.4, and writes to the journal between checkpoints.

Disabling journaling will force any journal flushes to become a checkpoint instead. Since a journal sync is relatively lightweight compared to a full checkpoint, the forced checkpoints will slow down WiredTiger.

2
  • Thanks! Why does turning journaling off makes checkpoints more frequent? Is that documented anywhere?
    – Tzach
    Sep 13, 2017 at 8:01
  • @Tzach I edited my answer to be more precise regarding this fact. It's currently not documented anywhere, but this behaviour in MongoDB 3.4.9 was defined in github.com/mongodb/mongo/blob/r3.4.9/src/mongo/db/storage/…
    – kevinadi
    Sep 18, 2017 at 2:31
1

The answer to your question: Writing data change to disk.

When journaling is on, the first change is written to the journal, then it is written to data blocks.

3
  • Thanks! So when journaling is on, is the ack sent before or after the change is actually written to the disk?
    – Tzach
    Sep 12, 2017 at 19:05
  • Here is an image: bit.ly/2wZ6VkL at the situation where you have w:1, j:true, without journaling, of course, we have only written to the disk possibility. But, remember, even write is done to data blocks, actual write (flush) to physical disk happens later.
    – JJussi
    Sep 12, 2017 at 19:16
  • Do you have the same image for j:false and journaling off on the server?
    – Tzach
    Sep 13, 2017 at 7:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.