Skip to Content
数据库系统内幕
book

数据库系统内幕

by Alex Petrov
May 2020
Beginner to intermediate
319 pages
7h 3m
Chinese
China Machine Press
Content preview from 数据库系统内幕
B
树的变体
|
103
所有写操作都必须经过根节点。在创建新根之后,旧根将无法进行新的读写操作。引用
旧树节的读操作一旦完成,其页就会被回收,并且可以被重新使用。由于 LMDB 的仅追
加设计,它不使用同级指针,所以在顺序扫描时必须上升到父节点。
在这种设计中,将陈旧数据留在复制出的节点中是不明智的:已经有一个副本可以用于
MVCC 并满足正在进行的读取事务了。这种数据库结构本质上是多版本的,读取者可以
在没有任何锁的情况下运行,因为它们不会以任何方式干扰写入者。
6.2
抽象节点更新
为了更新磁盘上的页,我们必须首先更新它在内存中的表示形式。然而,有多种方法
可以表示内存中的一个节点:我们可以直接访问节点的缓存版本,或者通过包装器
(wrapper)对象访问,抑或在实现语言中构建它的内存表示。
在具有非托管内存模型的语言中,存储在 B 树节点中的原始二进制数据是可以被重新解
释的,且可以被原生指针所操作。在这种情况下,节点是按照结构体定义的,这些结构
体使用指针和运行时类型转换来操作背后的原始二进制数据。最常见的情况是,它们指
向页缓存管理的内存区域,或者使用内存映射。
另一种方法是将 B 树节点物化为语言原生的对象或结构体。这些结构体可用于插入、更
新和删除。在刷写期间,更改应用于内存中的页,随后应用于磁盘上的页。这种方法的
优点是简化了并发访问,因为对底层原始页的更改与对中间对象的访问是分开管理的。
但是这会导致更高的内存开销,因为我们必须在内存中存储同一页的两个版本(原始二
进制版本和语言原生版本)。
第三种方法则是通过包装器对象来提供对节点背后缓冲区的访问 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

解密金融数据

解密金融数据

Justin Pauley

Publisher Resources

ISBN: 9787111655169