In-place update in WiredTiger

本文涉及的产品
RDS PostgreSQL Serverless,0.5-4RCU 50GB 3个月
推荐场景:
对影评进行热评分析
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS SQL Server,基础系列 2核4GB
简介:

There is a great new feature in the release note of MongoDB 3.5.12.

Faster In-place Updates in WiredTiger

This work brings improvements to in-place update workloads for users running the WiredTiger engine, especially for updates to large documents. Some workloads may see a reduction of up to 7x in disk utilization (from 24 MB/s to 3 MB/s) as well as a 20% improvement in throughput.

I thought wiredtiger has impeletementd the delta page feature introduced in the bw-tree paper, that is, writing pages that are deltas from previously written pages. But after I read the source code, I found it's a totally diffirent idea, in-place update only impacted the in-meomry and journal format, the on disk layout of data is not changed.

I will explain the core of the in-place update implementation.

MongoDB introduced mutable bson to descirbe document update as incremental(delta) update.

Mutable BSON provides classes to facilitate the manipulation of existing BSON objects or the construction of new BSON objects from scratch in an incremental fashion.

Suppose you have a very large document, see 1MB

{
   _id: ObjectId("59097118be4a61d87415cd15"),
   name: "ZhangYoudong",
   birthday: "xxxx",
   fightvalue: 100,
   xxx: .... // many other fields
}

If the fightvalue is changed from 100 to 101, you can use a DamageEvent to describe the update, it just tells you the offset、size、content(kept in another array) of the change.

struct DamageEvent {
    typedef uint32_t OffsetSizeType;
    // Offset of source data (in some buffer held elsewhere).
    OffsetSizeType sourceOffset;

    // Offset of target data (in some buffer held elsewhere).
    OffsetSizeType targetOffset;

    // Size of the damage region.
    size_t size;
};

So if you have many small changes for a document, you will have DamageEvent array, MongoDB add a new storage interface to support inserting DamageEvent array (DamageVector).

bool WiredTigerRecordStore::updateWithDamagesSupported() const {
    return true;
}

StatusWith<RecordData> WiredTigerRecordStore::updateWithDamages(
    OperationContext* opCtx,
    const RecordId& id,
    const RecordData& oldRec,
    const char* damageSource,
    const mutablebson::DamageVector& damages) {

}

WiredTiger added a new update type called WT_UPDATE_MODIFIED to support MongoDB, when a WT_UPDATE_MODIFIED update happened, wiredTiger first logged a change list which is transformed from DamageVector into journal, then kept the change list in memory associated with the original record.

When the record is read, wiredTiger will first read the original record, then apply every operation in change list, returned the final record to the client.

So the core for in-place update:

  1. WiredTiger support delta update in memory and journal, so the IO of writing journal will be greatly reduced for large document.
  2. WiredTiger's data layout is kept unchanged, so the IO of writing data is not changed.
相关文章
|
JavaScript 小程序 前端开发
【手把手教教学物联网项目】01 视频大纲
《手把手教教学物联网项目》是一系列视频教程,旨在引导初学者掌握物联网技术。视频涵盖物联网基础,如物联网概述、架构和技术;STM32微控制器的介绍、编程及外设使用;网关开发,涉及ESP8266和ESP32;物联网通信协议如TCP、MQTT、Modbus等;物联网总线协议如单总线、CAN、IIC和SPI;OLED显示原理与驱动;MQTT服务器搭建;物联网云平台介绍,包括阿里云平台的使用;微信小程序开发入门及前端VUE项目实践。此外,教程还涉及UniAPP和SpringBoot后台开发,最后通过“智能取餐柜”项目将理论知识付诸实践。视频可在B站找到,适合学生、爱好者和开发人员学习物联网技术。
1024 12
【手把手教教学物联网项目】01 视频大纲
|
Java BI 开发工具
静态代码自动扫描p3c的使用
静态代码自动扫描p3c的使用
1052 0
|
Oracle JavaScript Java
JDK的版本迭代特性(JDK9 - JDK20)
JDK的版本迭代特性(JDK9 - JDK20)
|
存储 NoSQL
MongoDB无法启动,如何恢复数据?
近日有 MongoDB 用户遇到一个问题,使用 Wiredtiger 存储引擎的 MongoDB 无法启动,咨询我数据能否恢复回来,能恢复多少是多少 ... 问题出现的场景据用户描述是「mongod磁盘写满了,导致进程 crash」,尝试重新启动,结果 wiredtiger 报错,错误信息类似如下,类似的问题 mongodb jira 上也有人提过,可以参考 SERVER-26924,说明此时 MongoDB 数据文件已经损坏。
|
12月前
|
存储 缓存 NoSQL
【赵渝强老师】MongoDB的WiredTiger存储引擎
MongoDB WiredTiger存储引擎自3.2版本起成为默认选择,提供文档级别的并发控制、检查点、数据压缩和本地加密等功能。本文详细介绍了WiredTiger的并发控制机制、预写日志与检查点、内存使用、数据压缩及磁盘空间回收等特性。
471 0
|
存储 NoSQL 算法
MongoDB存储引擎发展及WiredTiger深入解析(二)
MongoDB存储引擎发展及WiredTiger深入解析(二)
|
前端开发 JavaScript
前端 CSS 经典:3D Hover Effect 效果
前端 CSS 经典:3D Hover Effect 效果
191 0
【Linux C 几种锁的性能对比】 1.读写锁 2.互斥锁 3.自旋锁 4.信号量 5.rcu
【Linux C 几种锁的性能对比】 1.读写锁 2.互斥锁 3.自旋锁 4.信号量 5.rcu
|
存储 并行计算 关系型数据库
12306的西天取经路 - 春节抢票与PostgreSQL数据库设计思考
标签 PostgreSQL , 12306 , 春节 , 一票难求 , 门禁广告 , 数组 , 范围类型 , 抢购 , 排他约束 , 大盘分析 , 广告查询 , 火车票
27851 0