基本功能


TsFile 中会存储多个时间序列的数据,时间索引记录了这些时间序列的时间范围。


默认配置下:将此 TsFile 中所有时间序列的路径按照 (root - 倒数第二层)分组,每组为一个索引条目,包含:路径、起始时间、终止时间


示例:

如果 TsFile 文件中的各个序列的时间范围如下所示:


root.sg.d1.s1, 1, 10

root.sg.d1.s2, 1, 15

root.sg.d2.s1, 1, 10

root.sg.d3.s1, 5, 10


按倒数第二层分组后,则 时间索引 


root.sg.d1, 1, 15

root.sg.d2, 1, 10

root.sg.d3, 5, 10


不按照最后一层分组的原因是,时间序列可能过多,导致时间索引过大,因此选择了倒数第二层作为索引的路径,然而,当倒数第二层基数过多时(几十万、百万量级),时间索引仍然会较大。


时间索引粒度的影响:

在各个组的序列时间范围相同时(即写入是同步的),索引粒度越粗,越节省内存,且无任何副作用。

在各个组的序列时间范围不同时(如一个序列写入1-10,另一个写入20-30),索引粒度越粗,越容易多读不需要的文件元数据。


目标:支持多种分组粒度,1、按倒数第二级分组,2、按存储组分组(每个文件一个索引条目)

详细设计


将 TimeIndex 作为 TsFileResource 中的一个内部对象,其全部接口均由 TsFileResource 调用,不向外暴露;



具体而言,涉及到数据结构如下:

1. DeviceTimeIndex (后续“实现”的全部修改仅针对 TimeIndex

protected long[] startTimes; //  开始时间列表

protected long[] endTimes; // 结束时间列表,未封口则为 Long.MIN_VALUE

protected Map<String, Integer> deviceToIndex; // device设备名 => 开始 / 结束时间列表index


2. 第二步的修改(后续)涉及到【封口文件句柄SealedTsfileResource】和【未封口文件句柄UnsealedTsfileResource

因为封口文件句柄需要的字段较少,未封口文件句柄可以继承封口文件句柄;文件封口时再转化为封口文件句柄。


3. 总结

(1) 第一步接口化(本次)的修改中,可以从TsFileResource中转移走的字段:

protected long[] startTimes; //  开始时间列表

protected long[] endTimes; // 结束时间列表,未封口则为 Long.MIN_VALUE

protected Map<String, Integer> deviceToIndex; // device设备名 => 开始 / 结束时间列表index


(2) 目前TsFileResource文件句柄保留的功能和字段:

Map<String, String> cachedDevicePool // for reducing the String number in memory

File file // tsfile

TsFileProcessor processor 【未封口】

ModificationFile modFile // modification file

boolean closed【未封口】

boolean deleted【未封口】

boolean isMerging

TsFileLock tsFileLock

List<ChunkMetadata> chunkMetadataList // 【未封口】chunk metadata list of unsealed tsfile. Only be set in a temporal TsFileResource in a query process.

List<ReadOnlyMemChunk> readOnlyMemChunk // 【未封口】mem chunk data. Only be set in a temporal TsFileResource in a query process.

TimeseriesMetadata timeSeriesMetadata // 【未封口】get TimeseriesMetadata of unsealed file

List<TsFileResource> upgradedResources // 【升级】generated upgraded TsFile ResourceList used for upgrading v0.9.x/v1 -> 0.10/v2

UpgradeTsFileResourceCallBack upgradeTsFileResourceCallBack // 【升级】load upgraded TsFile Resources to storage group processor used for upgrading v0.9.x/v1 → 0.10/v2

boolean isSeq // 【升级】indicate if this tsfile resource belongs to a sequence tsfile or not used for upgrading v0.9.x/v1 -> 0.10/v2

TsFileResource originTsFileResource // 【未封口】current tsfile resource is a snapshot of the originTsFileResource. When we want to used the lock, we should try to acquire the lock of originTsFileResource

long maxPlanIndex // for cluster, max index of plans executed within this TsFile

long minPlanIndex // for cluster, min index of plans executed within this TsFile

  • No labels