mongodb的存储引擎WiredTiger笔记

文档级别的并发控制

WiredTiger uses document-level concurrency control for write operations. As a result, multiple clients can modify different documents of a collection at the same time.

Snapshots、 Checkpoints and Journal

多版本并发控制

WiredTiger uses MultiVersion Concurrency Control (MVCC).

快照snapshot

At the start of an operation, WiredTiger provides a point-in-time snapshot of the data to the operation. A snapshot presents a consistent view of the in-memory data.

snapshot代表被操作的数据,内存级别

检查点checkpoint

When writing to disk, WiredTiger writes all the data in a snapshot to disk in a consistent way across all data files. The now-durable data act as a checkpoint in the data files. 

During the write of a new checkpoint, the previous checkpoint is still valid. As such, even if MongoDB terminates or encounters an error while writing a new checkpoint, upon restart, MongoDB can recover from the last valid checkpoint.

数据文件保存的是checkpoint的数据。新的checkpoint写入成功之前,之前的那个checkpoint数据依然有效。

The new checkpoint becomes accessible and permanent when WiredTiger’s metadata table is atomically updated to reference the new checkpoint. Once the new checkpoint is accessible, WiredTiger frees pages from the old checkpoints.

新的checkpoint要可用,必须要更新metatable表

Using WiredTiger, even without journaling, MongoDB can recover from the last checkpoint; however, to recover changes made after the last checkpoint, run with journaling.

没有开启Journal,mongodb的数据从checkpoint恢复;如果要恢复到最后一个checkpoint之后的更新,需要开启Journal

WiredTiger uses a write-ahead log (i.e. journal) in combination with checkpoints to ensure data durability.

内存

Starting in MongoDB 3.4, the default WiredTiger internal cache size is the larger of either:

  • 50% of (RAM – 1 GB), or
  • 256 MB.

For example, on a system with a total of 4GB of RAM the WiredTiger cache will use 1.5GB of RAM (0.5 * (4 GB - 1 GB) = 1.5 GB). Conversely, a system with a total of 1.25 GB of RAM will allocate 256 MB to the WiredTiger cache because that is more than half of the total RAM minus one gigabyte (0.5 * (1.25 GB - 1 GB) = 128 MB < 256 MB).

注意:一台物理机器上,运行两个mongdb,可能会造成内存溢出,造成mongodb工作不稳定

文件系统(推荐使用XFS文件系统)

With the WiredTiger storage engine, using XFS for data bearing nodes is recommended on Linux. For more information, see Kernel and File Systems.

此条目发表在其他分类目录,贴了标签。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。

*