how mongodbs journaling works

I was working on a section on the gooey innards of journaling for The Definitive Guide, but then I realized it’s an implementation detail that most people won’t care about. However, I had all of these nice diagrams just laying around.
Good idea, Patrick! So, how does journaling work? Your disk has your data files and your journal files, which we’ll represent like this:
When you start up mongod, it maps your data files to a shared view. Basically, the operating system says: “Okay, your data file is 2,000 bytes on disk. I’ll map that to memory address 1,000,000-1,002,000. So, if you read the memory at memory address 1,000,042, you’ll be getting the 42nd byte of the file.“ (Also, the data won’t necessary be loaded until you actually access that memory.)
This memory is still backed by the file: if you make changes in memory, the operating system will flush these changes to the underlying file. This is basically how mongod works without journaling: it asks the operating system to flush in-memory changes every 60 seconds. However, with journaling, mongod makes a second mapping, this one to a private view. Incidentally, this is why enabling journalling doubles the amount of virtual memory mongod uses.
Note that the private view is not connected to the data file, so the operating system cannot flush any changes from the private view to disk. Now, when you do a write, mongod writes this to the private view.
mongod will then write this change to the journal file, creating a little description of which bytes in which file changed.
The journal appends each change description it gets.
At this point, the write is safe. If mongod crashes, the journal can replay the change, even though it hasn’t made it to the data file yet. The journal will then replay this change on the shared view.
Finally, at a glacial speed compared to everything else, the shared view will be flushed to disk. By default, mongod requests that the OS do this every 60 seconds.
The last step is that mongod remaps the shared view to the private view. This prevents the private view from getting too “dirty” (having too many changes from the shared view it was mapped from).
And that’s how journaling works. Thanks to Richard, who gave the best explanation of this I’ve heard (Richard is going to be teaching an online course on MongoDB this fall, if you’re interested in more wisdom from the source).

mongodb journal相关推荐

  1. mongodb journal占用磁盘处理

    1.停止mongodb服务 service mongodb stop 或 kill -2 进程号 2.修改mongodb配置信息 vim /etc/mongodb.conf nojournal = t ...

  2. mongodb journal文件格式(不错)

    如果开启journal,在dbpath选项指定的目录下会创建journal目录来存放journal文件,文件名形如j._<n>.journal文件用于数据库异常退出时恢复数据.这里是解析j ...

  3. mongodb journal文件格式

    如果开启journal,在dbpath选项指定的目录下会创建journal目录来存放journal文件,文件名形如j._<n>.journal文件用于数据库异常退出时恢复数据.这里是解析j ...

  4. mysql和mongodb配合_MongoDB和Mysql怎样结合

    二者结构有何不同? SQL中的许多概念都与MongoDB的文档结构相关.让我们来看一个简单的MongoDB环境结构,以更好地了解MongoDB的布局. 下面的图表涉及MySQL与MongoDB的不同点 ...

  5. Linux下的Mongodb部署应用梳理

    一.Mongodb简介 官网地址:http://www.mongodb.org/ MongoDB是一个高性能,开源,无模式的文档型数据库,是当前NoSql数据库中比较热门的一种.MongoDB 是一个 ...

  6. mongodb 初学 意外 连接服务器异常(Connection refused)

    啦啦啦 这种情况 root@localhost:/# mongo MongoDB shell version: 3.2.13 connecting to: test 2017-05-31T07:40: ...

  7. MongoDB 3.0 WiredTiger Compression and Performance

    MongoDB3.0中的压缩选项 在MongoDB 3.0中,WiredTiger为集合提供三个压缩选项: 无压缩 Snappy(默认启用) – 很不错的压缩,有效利用资源 zlib(类似gzip) ...

  8. mongodb 搜索速度_初识 MongoDB 数据库

    初识 MongoDB 数据库 前言 Flask 基础框架在之前的三篇文章中写完了.想要学习 web 相关的同学可以自己回顾翻一下,相信看完了,你也可以写出来一个简单的小案例来炫耀一波! 说到 web ...

  9. MongoDB安装步骤

    MongoDB安装 第一步 1.下载安装mongodb-win32-i386-3.2.9-signed.msi 2.打开cmd,输入mongod,会出现错误 第二步 1.进入MongoDB安装目录下的 ...

最新文章

  1. java图片16帧动画_Java实现帧动画的实例代码
  2. Bootstrap(自助法),Bagging,Boosting(提升)
  3. 10以内的分解与组成怎么教_狗狗酷炫的飞盘游戏怎么玩?分解步骤教你快速学会...
  4. 六张图了解Python的赋值、浅复制、深复制
  5. notepad++批量操作笔记(持续更新..)
  6. 概率统计笔记:二维随机变量及其联合概率分布
  7. myBattery电池应用正式登陆WP8
  8. Oracle 、SqlServer 根据日期逐日、逐月递增累加、逐行累加
  9. 期望收益率、方差、协方差、相关系数的计算公式
  10. _itemmod_extract_enchant
  11. 力扣刷题 DAY_76 贪心
  12. 关于创新创业的书,看这两本就够了
  13. AURIX TC397 CAN MCMCAN
  14. python画玫瑰曲线_turtle画玫瑰花,表白必备
  15. A7 ~ A11处理器(iphone5s~iphoneX) 14.0 ~ 14.8.1免越狱安装Trollstore教程
  16. 抖音这样拍摄短视频,能让你轻松上热门涨粉丨国仁网络资讯
  17. android自动秒杀脚本,gg修改器执行脚本按键代码秒杀安卓
  18. 一闪之间_李孟_新浪博客
  19. 0727Python总结-内置方法,数学模块,random随机模块,序列化模块pickle
  20. 用asp.net建立自己的网站过时了吗?vs2017建站测试笔记

热门文章

  1. mysql 快照 理解_MySQL - 当前读和快照读
  2. 常见六大 Web 安全攻防解析
  3. 简单电子病历功能设计
  4. win7更新_Win7用户福音:微软集成更新的新版Windows 7镜像泄露
  5. win7更新,360手机安装谷歌框架
  6. 为什么我电脑一开机显示器不亮要重启显示器才亮
  7. 如何安装husky_利用huskylint-staged构建代码检查工作流
  8. 从永远到永远-Spring Cloud(一)
  9. WordPress发布新文章Email通知注册用户
  10. Docker的安装部署及优化详解(汇总版,学习docker这一篇就够了)