mongodb给我们提供了fsync+lock机制把数据暴力的刷到硬盘上
2017-03-08 17:39
225 查看
能不能把数据暴力的刷到硬盘上,当然是可以的,mongodb给我们提供了fsync+lock机制就能满足我们提的需求。
fsync+lock首先会把缓冲区数据暴力刷入硬盘,然后给数据库一个写入锁,其他实例的写入操作全部被阻塞,直到fsync
+lock释放锁为止。
这里就不测试了。
加锁: db.runCommand({"fsync":1,"lock":1})
释放锁: db.$cmd.unlock.findOne()
As applications write data, MongoDB records the data in the storage layer and then writes the data to disk within the
The
The
The operation returns immediately. To view the status of the
Lock
NOTE
Changed in version 3.2:
In previous MongoDB versions,
The primary use of
To lock the database, use the
You may continue to perform read operations on a
Unlock
To unlock the
fsync+lock首先会把缓冲区数据暴力刷入硬盘,然后给数据库一个写入锁,其他实例的写入操作全部被阻塞,直到fsync
+lock释放锁为止。
这里就不测试了。
加锁: db.runCommand({"fsync":1,"lock":1})
释放锁: db.$cmd.unlock.findOne()
fsync
Forces themongodprocess to flush all pending writes from the storage layer to disk. Optionally, you can use
fsyncto lock the
mongodinstance and block write operations for the purpose of capturing backups.
As applications write data, MongoDB records the data in the storage layer and then writes the data to disk within the
syncPeriodSecsinterval, which is 60 seconds by default. Run
fsyncwhen you want to flush writes to disk ahead of that interval.
The
fsynccommand has the following syntax:
{ fsync: 1, async: <Boolean>, lock: <Boolean> }
The
fsynccommand has the following fields:
Field | Type | Description |
---|---|---|
fsync | integer | Enter “1” to apply fsync. |
async | boolean | Optional. Runs fsyncasynchronously. By default, the fsyncoperation is synchronous. |
lock | boolean | Optional. Locks mongodinstance and blocks all write operations. |
Examples
Run Asynchronously
Thefsyncoperation is synchronous by default. To run
fsyncasynchronously, use the
asyncfield set to
true:
{ fsync: 1, async: true }
The operation returns immediately. To view the status of the
fsyncoperation, check the output of
db.currentOp().
Lock mongod
Instance
NOTEChanged in version 3.2:
fsynccommand with the
lockoption 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,
fsynccommand with the
lockoption cannot guarantee a consistent set of files for low-level backups (e.g. via file copy
cp,
scp,
tar) for WiredTiger.
The primary use of
fsyncis to lock the
mongodinstance in order to back up the files within
mongod‘s
dbPath. The operation flushes all data to the storage layer and blocks all write operations until you unlock the
mongodinstance.
To lock the database, use the
lockfield set to
true:
{ fsync: 1, lock: true }
You may continue to perform read operations on a
mongodinstance that has a
fsynclock. However, after the first write operation all subsequent read operations wait until you unlock the
mongodinstance.
Unlock mongod
Instance
To unlock the mongod, use
db.fsyncUnlock():
db.fsyncUnlock();
见:https://docs.mongodb.com/manual/reference/command/fsync/
相关文章推荐
- c++primer第二章“c++定义了几种基本类型,还提供了可用于自定义数据类型的机制,此外,我们还能修改已有的类型以形成复合类型”
- Nancy之结合tinyfox给我们的应用提供简单的数据服务
- net控件中数据导到Excel的格式 首先,我们了解一下excel从web页面上导出的原理。当我们把这些数据发送到客户端时,我们想让客户端程序(浏览器)以excel的格式读取它,所以把mime类型设为:application/vnd.ms-excel,当excel读取文件时会以每个cell的格式呈现数据,如果cell没有规定的格式,则excel会以默认的格式去呈现该cell的数据。这样就给我们提供了自定义数据格式的空间,当然我们必须使用excel支持的格式。下面就列出常用的一些格式: 1) 文本
- Nancy之结合tinyfox给我们的应用提供简单的数据服务
- 邮件自动化服务开发:定时拉取MongoDB数据提供给运营人员
- C++中提供了多种基本的数据类型。实际上,这些远不能满足我们的需求,如复数(第10章的例子大多是处理虚数的),再如分数。本任务将设计一个简单的分数类,完成对分数的几个运算。一则巩固基于对象编程的方法,
- Nancy之结合tinyfox给我们的应用提供简单的数据服务
- Android应用开发中,给我们提供了4种数据的存储方式
- GridView是ASP.NET中功能强大的数据显示控件,它的RowDataBound事件为我们提供了方便的控制行、列数据的途径。
- 大数据技术到底给我们提供什么决策信息?——技术分享会实况
- 使用ADO.net转换数据到Excel格式并提供下载
- 采用 EFS 加密硬盘以保护数据
- 笔记本硬盘坏了,数据损失严重。看来备份是很必要的!教训
- ADO.NET的数据提供程序和数据连接——ADO.NET学习&应用笔记之二
- 系统崩溃后 我这样拯救我的硬盘数据
- 使用ADO.net转换数据到Excel格式并提供下载
- NetworkStream 类----提供用于网络访问的基础数据流
- 数据提供者
- 老庞互联网随想之五 谁能够提供我们想要的资讯,我们就用谁
- SQL Server .NET Framework 数据提供程序连接池(转贴)