The main durability page (not the internals page) is the Journaling page.
The data file format is unchanged.
Journal files are placed in /data/db/journal/.
Journaling is on by default. Run with --nojournal to disable journaling/durable storage. Both mongod and dbtest support this option.
Declaring Write Intent¶
When writing mongod kernel code, one must now declare an intention to write. Declaration of the intent occurs before the actual write. See db/dur.h. The actual write must occur before releasing the write lock.
When you do your actual writing, use the pointer that dur::writing() returns, rather than the original pointer.
Foo *foo; getDur().writing(thing)->bar = something; int *x; getDur().writingInt(x) += 3; DiskLoc &loc; loc.writing() = newLoc; void *p; unsigned len; memcpy( getDur().writingPtr(p,len), src, len );
Try to declare intent on as small a region as possible to reduce the amount of information journalled. For example:
BigStruct *b; dur::writing(b)->x = 3; // less efficient *dur::writing(&b->x) = 3; // more efficient
However, because of overhead for each intent declaration, if many members of a struct will be written, it may be better to just declare intent on the whole struct.
jstests/dur/ contains tests for durability.
mongo --nodb jstests/dur/<testname>.js
# dump journal entries during any recover, and then start normally mongod --journal --durOptions 1 # recover and terminate mongod --journal --durOptions 4 # dump journal entries (doing nothing else) and then terminate mongod --journal --durOptions 7 # extra checks that everything is correct (slow but good for qa) mongod --journal --durOptions 8