TSI文件结构概览
- 一个TSI文件的定义和操作在
tsdb/index/tsi1/index_file.go
里实现的 - 一个TSI文件的结尾存储了这个文件相关的meta信息,主要是其他section在文件中的offset和size,这个meta信息被称为tsi文件的
IndexFileTrailer
,我们看一下它的Size的定义:
IndexFileTrailerSize = IndexFileVersionSize +
8 + 8 + // measurement block offset + size
8 + 8 + // series id set offset + size
8 + 8 + // tombstone series id set offset + size
8 + 8 + // series sketch offset + size
8 + 8 + // tombstone series sketch offset + size
0
从上面的定义我们可以得到两点收获: 1. 这个IndexFileTrailerSize在TSI文件结尾处有固定大小(82bytes),我们在解析TSI文件时,很容易读到并解析这个Trailer; 2. 我们可以知道这个TSI文件都包含哪些Section, 下图是TSI文件结构 2.1 Trailer部分 2.2 series id set block 2.3 tombstone series id set block 2.4 series sketch block 2.5 tombstone series sketch block
- 下面我们就分别来看一下各组成部分
Measurement block
- 定义在
tsdb/index/tsi1/measurement_block.go
- 它的结构也是由存储meta信息的
Trailer
部分和其他各section组成 - 定义:....
type MeasurementBlock struct {
data []byte
hashData []byte
// Measurement sketch and tombstone sketch for cardinality estimation.
sketchData, tSketchData []byte
version int // block version
}
基础上是按照其在文件中的结构定义的,记录了measurement包括的tagset和series id信息; * 我们来看一张完整的结构图
![8cb6a552142bdd4a83bed1bbc8b5e23a.png](https://img-blog.csdnimg.cn/img_convert/8cb6a552142bdd4a83bed1bbc8b5e23a.png)
- 一图抵千言
Trailer
部分是整个MeasuermentBlock的索引,存储着其他部分的offset和sizeData block set
部分是所有MeasurementBlockElement
的集合, 2.1 measurement 基本属性,比如name等; 2.2 对应的tag set在文件中的offset和size; 2.3 包括的所有series id信息, 这个series id有两种表示方式:roaring bitmap和 数组,flag指示了用哪种表示方法hash index部分
:以hash索引的方式存储了MeasurementBlockElement
在文件中的offset, 可以在不用读取整体的tsi文件的前提下,快速定位对某个measurementblockElement的文件位置,然后读取并解析tombstome sketch