Tsm file
(.tsm
)真正用于数据持久化存储。文件格式主要由为4 部分组成: Header
、Blocks
、Index
、Footer
。
-
Header
由两部分组成MagicNumber
和Version
,MagicNumber
用于描述文件存储引擎,Version
记录引擎版本。 -
Blocks
内部是一些连续的Block
,Block
是influxdb
中的最小读取对象,每次读取操作都会读取一个Block
。每一个Block
分为CRC32
值和Data
两部分,CRC32
值用于校验Data
的内容是否有问题。 -
Index
存放的是Blocks
里内容的索引。influxdb
在做查询操作时,可以根据Index
的信息快速定位到Tsm file
中需要查询的block
的位置。 -
Footer
位于Tsm file
的最后8字节,存放了Index
的起始位置在Tsm file
中的偏移量,方便将索引信息加载到内存中。
Compactor
组件在后台持续运行,每隔 1 秒会检查一次是否有需要压缩合并的数据。其主要有两种操作:
-
cache
中的数据大小达到阀值后,进行快照,之后转存到一个新的Tsm
文件中。 -
合并
Tsm
文件。将多个小的Tsm
文件合并成一个,使每一个文件尽量达到单个文件的最大值,减少Tsm
文件的数量,并且一些数据的删除操作也是在这个时候完成。
=====================================================================================
Shard groups are logical containers for shards. Shard groups are organized by time and retention policy.
Every retention policy that contains data has at least one associated shard group.
A given shard group contains all shards with data for the interval covered by the shard group.
The interval spanned by each shard group is the shard duration.
每一个retention policy
至少有一个shard group
,每一个shard group
至少有一个shard
。数据都会带一个time
时间戳,当写入数据时,先通过时间判断