能不能把数据暴力的刷到硬盘上,当然是可以的,mongodb给我们提供了fsync+lock机制就能满足我们提的需求。
fsync+lock首先会把缓冲区数据暴力刷入硬盘,然后给数据库一个写入锁,其他实例的写入操作全部被阻塞,直到fsync
+lock释放锁为止。
这里就不测试了。
加锁: db.runCommand({"fsync":1,"lock":1})
释放锁: db.$cmd.unlock.findOne()
<dl><dd></dd></dl>
The <code>fsync</code> command has the following syntax:
The <code>fsync</code> command has the following fields:
Field
Type
Description
<code>fsync</code>
integer
Enter “1” to apply <code>fsync</code>.
<code>async</code>
boolean
Optional. Runs <code>fsync</code> asynchronously. By default, the <code>fsync</code> operation is synchronous.
<code>lock</code>
The <code>fsync</code> operation is synchronous by default. To run <code>fsync</code> asynchronously, use the <code>async</code> field set to<code>true</code>:
NOTE
Changed in version 3.2: <code>fsync</code> command with the <code>lock</code> option can ensure that the data files do not change for MongoDB instances using either the MMAPv1 or the WiredTiger storage engines, thus providing consistency for the purposes of creating backups.
In previous MongoDB versions, <code>fsync</code> command with the <code>lock</code> option cannot guarantee a consistent set of files for low-level backups (e.g. via file copy <code>cp</code>, <code>scp</code>, <code>tar</code>) for WiredTiger.
To lock the database, use the <code>lock</code> field set to <code>true</code>:
本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/bonelee/p/6520521.html,如需转载请自行联系原作者