能不能把数据暴力的刷到硬盘上,当然是可以的,mongodb给我们提供了fsync+lock机制就能满足我们提的需求。

fsync+lock首先会把缓冲区数据暴力刷入硬盘,然后给数据库一个写入锁,其他实例的写入操作全部被阻塞,直到fsync

+lock释放锁为止。

这里就不测试了。

加锁:    db.runCommand({"fsync":1,"lock":1})

释放锁: db.$cmd.unlock.findOne()

fsync

Forces the mongod process to flush all pending writes from the storage layer to disk. Optionally, you can use fsync to lock the mongod instance 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 syncPeriodSecs interval, which is 60 seconds by default. Run fsync when you want to flush writes to disk ahead of that interval.

The fsync command has the following syntax:

{ fsync: 1, async: <Boolean>, lock: <Boolean> } 

The fsync command has the following fields:

Field Type Description
fsync integer Enter “1” to apply fsync.
async boolean Optional. Runs fsync asynchronously. By default, the fsync operation is synchronous.
lock boolean Optional. Locks mongod instance and blocks all write operations.

Examples

Run Asynchronously

The fsync operation is synchronous by default. To run fsync asynchronously, use the async field set totrue:

{ fsync: 1, async: true } 

The operation returns immediately. To view the status of the fsync operation, check the output ofdb.currentOp().

Lock mongod Instance

NOTE

Changed in version 3.2: fsync command with the lock 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, fsync command with the lock option cannot guarantee a consistent set of files for low-level backups (e.g. via file copy cpscptar) for WiredTiger.

The primary use of fsync is to lock the mongod instance in order to back up the files within mongod‘sdbPath. The operation flushes all data to the storage layer and blocks all write operations until you unlock themongod instance.

To lock the database, use the lock field set to true:

{ fsync: 1, lock: true } 

You may continue to perform read operations on a mongod instance that has a fsync lock. However, after the first write operation all subsequent read operations wait until you unlock the mongod instance.

Unlock mongod Instance

To unlock the mongod, use db.fsyncUnlock():

db.fsyncUnlock();

见:https://docs.mongodb.com/manual/reference/command/fsync/

转载于:https://www.cnblogs.com/bonelee/p/6520521.html

mongodb给我们提供了fsync+lock机制把数据暴力的刷到硬盘上相关推荐

  1. Java并发编程(06):Lock机制下API用法详解

    本文源码:GitHub·点这里 || GitEE·点这里 一.Lock体系结构 1.基础接口简介 Lock加锁相关结构中涉及两个使用广泛的基础API:ReentrantLock类和Condition接 ...

  2. java 同步解决不安全类_「JAVA」Java 线程不安全分析,同步锁和Lock机制,哪个解决方案更好...

    线程不安全 线程不安全的问题分析:在小朋友抢气球的案例中模拟网络延迟来将问题暴露出来:示例代码如下: public class ImplementsDemo { public static void ...

  3. 我在MongoDB年终大会上获二等奖文章:由数据迁移至MongoDB导致的数据不一致问题及解决方案...

    作者 | 上海小胖 来源 | Python专栏(ID:xpchuiit) 故事背景 企业现状 2019年年初,我接到了一个神秘电话,电话那头竟然准确的说出了我的昵称:上海小胖. 我想这事情不简单,就回 ...

  4. “可扩展标记语言”(XML) 提供一种描述结构化数据的方法。

    摘要: "可扩展标记语言"(XML) 提供一种描述结构化数据的方法.与主要用于控制数据的显示和外观的 HTML 标记不同,XML 标记用于定义数据本身的结构和数据类型. XML 使 ...

  5. Redis的内存回收机制和数据过期淘汰策略

    本文来说下Redis的内存回收机制和数据过期淘汰策略 文章目录 概述 为什么需要内存回收 过期删除策略 定时删除 惰性删除 定期删除 删除策略比对 过期删除策略原理 redisDb结构体定义 expi ...

  6. HTML5项目笔记8:使用HTML5 的跨域通信机制进行数据同步

    离线应用系统的设计目标就是在网络离线情况下依然可以操作我们的应用系统,并在网络畅通的情况下与服务器进行数据交互. 所以离线应用系统最终会做成类似C/S架构的客户端应用程序.这边基于Chrome或者 S ...

  7. ECCV2022 | 人大提出轻量级基于注意力的特征融合机制,在多个公开数据集上有效!代码已开源!

    ECCV2022 | 人大提出轻量级基于注意力的特征融合机制,在多个公开数据集上有效!代码已开源! [写在前面] 本文在文本到视频检索的新背景下,作者重新探讨了特征融合这一古老的课题.与以往的研究只考 ...

  8. 2021年大数据Kafka(十一):❤️Kafka的消费者负载均衡机制和数据积压问题❤️

    全网最详细的大数据Kafka文章系列,强烈建议收藏加关注! 新文章都已经列出历史文章目录,帮助大家回顾前面的知识重点. 目录 系列历史文章 Kafka的消费者负载均衡机制和数据积压问题 一.kafka ...

  9. axis2 默认端口_基于 AXIS2/C 的 C 语言库实现对提供 REST API 的系统进行数据访问...

    基于 AXIS2/C 的 C 语言库实现对提供 REST API 的系统进行数据访问 宋 东平 和 赵 健 2013 年 3 月 07 日发布 AXIS2/C 简介和 REST 及 REST API ...

最新文章

  1. Testlink在linux上安装遇到的问题
  2. 网络主机托管的特点和优点_主机托管有哪些特点和优点
  3. 实例对象静态对象实例方法静态方法
  4. CentOS 初体验二十一:redis常用命令:String
  5. vector插入/删除元素
  6. 实用垃圾收集,第1部分–简介
  7. 年薪百万!这所高校一名本科生入选“天才少年”
  8. 超融合带来的IT人员问题 企业是否看到?
  9. paramiko模块实现堡垒机的思路
  10. JAVA 字符串格式化-String.format()的使用(转)
  11. java输入年月输出日历_java输入年份打印该年份的年历 | 学步园
  12. 100个Python实战项目(十二)Python 并发图像下载器
  13. 网易云音乐显示网络异常
  14. 计算机网络第5版答案完整版
  15. LTE学习笔记五:LTE两种帧结构
  16. uni-app 中使用外部第三方字体(非字体图标)
  17. python中shift函数_Pandas Shift函数的基础入门学习笔记
  18. thinkphp3.2 七牛 bad token
  19. 第一次任务完成经历的总结
  20. 基于多传感器数据融合的全自动泊车系统研究与应用(文献综述)

热门文章

  1. TextBoxSuggest,输入框提示工具,输入建议,输入匹配,辅助输入,输入即时提示,文本编辑器,Visual Studio效果,高速查询引擎,哈希树,模糊匹配,百万条零毫秒
  2. ajax返回304,jquery $ajax GET请求在IE浏览器兼容中遇到的304 cache请求的经验分享
  3. thinkphp5调用shell脚本_thinkphp5.x全版本任意代码执行getshell
  4. 【以太坊】web3.js的1.0版本和0.2.0版本的安装及区别
  5. PHP sprintf() 函数
  6. Java开发自学技巧!【漫画(1)
  7. java开发五年多少钱,附超全教程文档
  8. 字节跳动Java高级工程师:java队列实现停车场出入
  9. 数据库优化:Mysql慢查询的定位和分析
  10. 【深度学习】孪生网络(Siamese Network)的模式和训练过程