Home Database Mysql Tutorial LevelDB系列之SSTable(Sorted Strings Table)文件

LevelDB系列之SSTable(Sorted Strings Table)文件

Jun 07, 2016 pm 05:37 PM
leveldb sorted series

SSTable是Bigtable中至关重要的一块,对于LevelDb来说也是如此,对LevelDb的SSTable实现细节的了解也有助于了解Bigtable中一些实现细节。 本节内容主要讲述SSTable的静态布局结构,我们曾在整体架构中说过,SSTable文件形成了不同Level的层级结构,至于这个

 

SSTable是Bigtable中至关重要的一块,对于LevelDb来说也是如此,对LevelDb的SSTable实现细节的了解也有助于了解Bigtable中一些实现细节。

本节内容主要讲述SSTable的静态布局结构,我们曾在“整体架构”中说过,SSTable文件形成了不同Level的层级结构,至于这个层级结构是如何形成的我们放在后面Compaction一节细说。本节主要介绍SSTable某个文件的物理布局和逻辑布局结构,这对了解LevelDb的运行过程很有帮助。

LevelDb不同层级有很多SSTable文件(以后缀.sst为特征),所有.sst文件内部布局都是一样的。上节介绍Log文件是物理分块的,SSTable也一样会将文件划分为固定大小的物理存储块,但是两者逻辑布局大不相同,,根本原因是:Log文件中的记录是Key无序的,即先后记录的key大小没有明确大小关系,而.sst文件内部则是根据记录的Key由小到大排列的,从下面介绍的SSTable布局可以体会到Key有序是为何如此设计.sst文件结构的关键。

wps_clip_image-18291

图4.1 .sst文件的分块结构

图4.1展示了一个.sst文件的物理划分结构,同Log文件一样,也是划分为固定大小的存储块,每个Block分为三个部分,红色部分是数据存储区,蓝色的Type区用于标识数据存储区是否采用了数据压缩算法(Snappy压缩或者无压缩两种),CRC部分则是数据校验码,用于判别数据是否在生成和传输中出错。

以上是.sst的物理布局,下面介绍.sst文件的逻辑布局,所谓逻辑布局,就是说尽管大家都是物理块,但是每一块存储什么内容,内部又有什么结构等。图4.2展示了.sst文件的内部逻辑解释。

wps_clip_image-4580

图4.2逻辑布局

从图4.2可以看出,从大的方面,可以将.sst文件划分为数据存储区和数据管理区,数据存储区存放实际的Key:Value数据,数据管理区则提供一些索引指针等管理数据,目的是更快速便捷的查找相应的记录。两个区域都是在上述的分块基础上的,就是说文件的前面若干块实际存储KV数据,后面数据管理区存储管理数据。管理数据又分为四种不同类型:紫色的Meta Block,红色的MetaBlock 索引和蓝色的数据索引块以及一个文件尾部块。

LevelDb 1.2版对于Meta Block尚无实际使用,只是保留了一个接口,估计会在后续版本中加入内容,下面我们看看数据索引区和文件尾部Footer的内部结构。

wps_clip_image-18980

图4.3数据索引

图4.3是数据索引的内部结构示意图。再次强调一下,Data Block内的KV记录是按照Key由小到大排列的,数据索引区的每条记录是对某个Data Block建立的索引信息,每条索引信息包含三个内容,以图4.3所示的数据块i的索引Index i来说:红色部分的第一个字段记载大于等于数据块i中最大的Key值的那个Key,第二个字段指出数据块i在.sst文件中的起始位置,第三个字段指出Data Block i的大小(有时候是有数据压缩的)。后面两个字段好理解,是用于定位数据块在文件中的位置的,第一个字段需要详细解释一下,在索引里保存的这个Key值未必一定是某条记录的Key,以图4.3的例子来说,假设数据块i 的最小Key=“samecity”,最大Key=“the best”;数据块i+1的最小Key=“the fox”,最大Key=“zoo”,那么对于数据块i的索引Index i来说,其第一个字段记载大于等于数据块i的最大Key(“the best”)同时要小于数据块i+1的最小Key(“the fox”),所以例子中Index i的第一个字段是:“the c”,这个是满足要求的;而Index i+1的第一个字段则是“zoo”,即数据块i+1的最大Key。

文件末尾Footer块的内部结构见图4.4,metaindex_handle指出了metaindex block的起始位置和大小;inex_handle指出了index Block的起始地址和大小;这两个字段可以理解为索引的索引,是为了正确读出索引值而设立的,后面跟着一个填充区和魔数。

wps_clip_image-24284

图4.4Footer

上面主要介绍的是数据管理区的内部结构,下面我们看看数据区的一个Block的数据部分内部是如何布局的(图4.1中的红色部分),图4.5是其内部布局示意图。

wps_clip_image-7105

图4.5数据Block内部结构

从图中可以看出,其内部也分为两个部分,前面是一个个KV记录,其顺序是根据Key值由小到大排列的,在Block尾部则是一些“重启点”(Restart Point),其实是一些指针,指出Block内容中的一些记录位置。

“重启点”是干什么的呢?我们一再强调,Block内容里的KV记录是按照Key大小有序的,这样的话,相邻的两条记录很可能Key部分存在重叠,比如key i=“the Car”,Key i+1=“the color”,那么两者存在重叠部分“the c”,为了减少Key的存储量,Key i+1可以只存储和上一条Key不同的部分“olor”,两者的共同部分从Key i中可以获得。记录的Key在Block内容部分就是这么存储的,主要目的是减少存储开销。“重启点”的意思是:在这条记录开始,不再采取只记载不同的Key部分,而是重新记录所有的Key值,假设Key i+1是一个重启点,那么Key里面会完整存储“the color”,而不是采用简略的“olor”方式。Block尾部就是指出哪些记录是这些重启点的。

wps_clip_image-6552

图4.6记录格式

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Xiaomi 15 series full codenames revealed: Dada, Haotian, Xuanyuan Xiaomi 15 series full codenames revealed: Dada, Haotian, Xuanyuan Aug 22, 2024 pm 06:47 PM

The Xiaomi Mi 15 series is expected to be officially released in October, and its full series codenames have been exposed in the foreign media MiCode code base. Among them, the flagship Xiaomi Mi 15 Ultra is codenamed "Xuanyuan" (meaning "Xuanyuan"). This name comes from the Yellow Emperor in Chinese mythology, which symbolizes nobility. Xiaomi 15 is codenamed "Dada", while Xiaomi 15Pro is named "Haotian" (meaning "Haotian"). The internal code name of Xiaomi Mi 15S Pro is "dijun", which alludes to Emperor Jun, the creator god of "The Classic of Mountains and Seas". Xiaomi 15Ultra series covers

The best time to buy Huawei Mate 60 series, new AI elimination + image upgrade, and enjoy autumn promotions The best time to buy Huawei Mate 60 series, new AI elimination + image upgrade, and enjoy autumn promotions Aug 29, 2024 pm 03:33 PM

Since the Huawei Mate60 series went on sale last year, I personally have been using the Mate60Pro as my main phone. In nearly a year, Huawei Mate60Pro has undergone multiple OTA upgrades, and the overall experience has been significantly improved, giving people a feeling of being constantly new. For example, recently, the Huawei Mate60 series has once again received a major upgrade in imaging capabilities. The first is the new AI elimination function, which can intelligently eliminate passers-by and debris and automatically fill in the blank areas; secondly, the color accuracy and telephoto clarity of the main camera have been significantly upgraded. Considering that it is the back-to-school season, Huawei Mate60 series has also launched an autumn promotion: you can enjoy a discount of up to 800 yuan when purchasing the phone, and the starting price is as low as 4,999 yuan. Commonly used and often new products with great value

How to choose between iPhone 15 and iPhone 15 Pro? Nine major differences at once How to choose between iPhone 15 and iPhone 15 Pro? Nine major differences at once Sep 14, 2023 am 08:01 AM

iPhone15 and iPhone15Pro were officially released today. However, as high-end models, the Pro series not only has a higher price, but also has many exclusive features. Consumers must recognize the differences before buying, so as not to discover some problems after buying iPhone15. The function is only available in the Pro series. Although the monitors are equipped with the same display panel, the ProMotion automatic adaptive update frequency technology and the always-on display function are still exclusive to the Pro series. The rest of the iPhone 15 and iPhone 15 Pro series are the same in terms of resolution, contrast, peak brightness, etc. Action button The action button is currently an exclusive design for the iPhone 15 Pro series, allowing users to personalize it.

How to use java Sorted How to use java Sorted Apr 19, 2023 am 11:40 AM

Concept 1. Sorted is an intermediate operation that returns a sorted Stream. If you do not enter a custom Comparator, the features will be arranged in natural order. Usage Note 2. After performing the Sorted operation, the order of the elements in stringCollection has not changed. Sorted only sorts the elements in the stream without changing the order of the elements in the original collection. Example stringCollection.stream().sorted().filter((s)->s.startsWith("a")).forEach(System.out::printl

Installing LevelDB under CentOS and installing v2 on CentOS Installing LevelDB under CentOS and installing v2 on CentOS Feb 14, 2024 am 09:33 AM

Installing and configuring LevelDB in CentOS systems is a very useful skill. LevelDB is a high-performance key-value store that can be used to build various applications, such as databases, caches, and logging systems. This article will introduce in detail how to install and configure LevelDB on CentOS. The process of installing and configuring LevelDB on the system, and providing some practical commands and techniques. Installing LevelDB under CentOS The following are the steps to install LevelDB on CentOS system: Install dependencies Before starting to install LevelDB, you need to install some necessary dependencies. Open the terminal and execute the following command to install these dependencies: ``sudoyuminstallsnappy- deve

List sorting: Detailed explanation of Python's sort, sorted and numpy.argsort methods List sorting: Detailed explanation of Python's sort, sorted and numpy.argsort methods Jun 10, 2023 am 09:22 AM

In Python programming, it is often necessary to sort lists or arrays. Python provides a variety of sorting methods, including sort, sorted, numpy.argsort, etc. This article will introduce in detail the usage and precautions of these sorting methods. 1. Sort method The sort method is a built-in method in Python lists. It can sort the list in place (that is, it returns a value but does not generate a new sort object), and does not require additional import libraries. The sort method has two parameters: k

Introduction to Python functions: usage and examples of sorted function Introduction to Python functions: usage and examples of sorted function Nov 03, 2023 am 11:02 AM

Introduction to Python functions: Usage and examples of sorted function Python has many built-in functions, one of which is a very commonly used function is the sorted() function. The sorted() function is used to sort an iterable object and return a new sorted list. This article will introduce the usage of the sorted() function and provide some specific code examples. Basic usage of sorted() function The basic syntax of sorted() function is as follows: sorted(iterable

What series are there in the Hall of Fame? What series are there in the Hall of Fame? Feb 04, 2024 am 09:18 AM

Many users who want to buy memory modules want to know what series of memory modules the GALAX Hall of Fame brand has. In fact, this brand currently has three series, namely HOFEXTREME limited edition, HOFEXTREME, and HOFPRORGB. What are the series of Hall of Fame memory: A: HOFEXTREME limited edition, HOFEXTREME, HOFPRORGB. These three memory modules all have relatively good performance. Among them, the HOFEXTREME limited edition has the best performance. Compared with the previous two models, the HOFPRORGB is slightly weaker but the performance is also very good. Hall of Fame memory expansion introduction: 1. Using Samsung B-die particles, which is the king of memory particles and has a long service life.

See all articles