On this page本页内容
To provide durability in the event of a failure, MongoDB uses write ahead logging to on-disk journal files.
Important
The log mentioned in this section refers to the WiredTiger write-ahead log (i.e. the journal) and not the MongoDB log file.
WiredTiger uses checkpoints to provide a consistent view of data on disk and allow MongoDB to recover from the last checkpoint. However, if MongoDB exits unexpectedly in between checkpoints, journaling is required to recover information that occurred after the last checkpoint.
Note
Starting in MongoDB 4.0, you cannot specify --nojournal
option or storage.journal.enabled:
false
for replica set members that use the WiredTiger storage engine.
With journaling, the recovery process:
Changed in version 3.2.在版本3.2中更改。
With journaling, WiredTiger creates one journal record for each client initiated write operation. The journal record includes any internal write operations caused by the initial write. For example, an update to a document in a collection may result in modifications to the indexes; WiredTiger creates a single journal record that includes both the update operation and its associated index modifications.
MongoDB configures WiredTiger to use in-memory buffering for storing the journal records. Threads coordinate to allocate and copy into their portion of the buffer. All journal records up to 128 kB are buffered.
WiredTiger syncs the buffered journal records to disk upon any of the following conditions:
j: true
.
Note
Write concern "majority"
implies j: true
if the writeConcernMajorityJournalDefault
is true.
storage.journal.commitIntervalMs
).Important
In between write operations, while the journal records remain in the WiredTiger buffers, updates can be lost following a hard shutdown of mongod
.
See also参阅
The serverStatus
command returns information on the WiredTiger journal statistics in the wiredTiger.log
field.
For the journal files, MongoDB creates a subdirectory named journal
under the dbPath
directory. WiredTiger journal files have names with the following format WiredTigerLog.<sequence>
where <sequence>
is a zero-padded number starting from 0000000001
.
Journal files contain a record per each client initiated write operation
By default, MongoDB configures WiredTiger to use snappy compression for its journaling data. To specify a different compression algorithm or no compression, use the storage.wiredTiger.engineConfig.journalCompressor
setting. For details, see Change WiredTiger Journal Compressor.s
Note
If a log record less than or equal to 128 bytes (the mininum log record size for WiredTiger), WiredTiger does not compress that record.
WiredTiger journal files for MongoDB have a maximum size limit of approximately 100 MB.
WiredTiger pre-allocates journal files.
Starting in MongoDB Enterprise version 3.2.6, the In-Memory Storage Engine is part of general availability (GA). Because its data is kept in memory, there is no separate journal. Write operations with a write concern of j: true
are immediately acknowledged.
If any voting member of a replica set uses the in-memory storage engine, you must set writeConcernMajorityJournalDefault
to false
.
Note
Starting in version 4.2 (and 4.0.13 and 3.6.14 ), if a replica set member uses the in-memory storage engine (voting or non-voting) but the replica set has writeConcernMajorityJournalDefault
set to true, the replica set member logs a startup warning.
With writeConcernMajorityJournalDefault
set to false
, MongoDB does not wait for w: "majority"
writes to be written to the on-disk journal before acknowledging the writes. As such, majority
write operations could possibly roll back in the event of a transient loss (e.g. crash and restart) of a majority of nodes in a given replica set.
See also参阅