You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
« Previous
Version 9
Next »
1. 0.12版本lastCache实现
1.1. 存储方式
在MeasurementMNode中存储一个TimeValuePair;
由MeasurementMNode提供操作接口。
1.2. lastCache触发时机
- insertPlan执行完后updateLastCache
- last查询,先从缓存中查找,若miss则从文件获取数据后updateLastCache
- delete数据时,根据删除数据的起始时间清空lastCache
- upload Tsfile时,由于数据更新,lastCache可能失效,故清空
1.3. lastCache操作执行过程
- getLastCache:首先通过调用getNodeByPath,获取指定路径/序列对应的 MeasurementMNode,template对应的序列会封装一个临时节点对象,调用MeasurementMNode的get接口
- updateLastCache:与getLastCache类似
- resetCache:storageGroupProccessor通过device获取子节点,调用子节点的reset接口
2. 0.13版本lastCache功能实现
2.1. 适配物理量模板Template
Template的lastCache失败原因
获取template中序列对应的measurementMNode时,仅返回临时变量,对临时MeasurementMNode中lastCache的操作并未保存回MTree。
适配方案
由于Template由EntityMNode进行使用,因此在EntityMNode中增加Map<String, ILastCacheContainer>字段,用于存储template所表示的时间序列的lastCache。
对MeasurementMNode中的lastCache进行操作时,先判断该节点是否是为了template而创建的临时节点,如果是,则先拿到entityMNode中的lastCache引用,然后再进行操作。
2.2. 适配多元时间序列
多元时间序列的lastCache失败原因
- MeasurementMNode中简单的TimeValuePair无法满足多元分量的lastCache的存储。
- LastQueryPlan的执行过程中,path被转化为vectorPartiaPath之后,仅到多元序列层,未基于分量路径subsensorPath进行lastCache查找
- insertPlan执行过程中,对于aligned plan不进行lastCache的更新
适配方案
- 建立VectorLastCacheValue,存储多元时间序列的lastCache;由于目前last查找是查找最新的不为空值的时间点,故不同分量的LastCache时间可能不同,需要存储多个timestamp和 TsPrimitiveValue。
- 修改LastQueryExecutor中seriesPath的使用,使其应用到subsensor层即分量对应的路径。
- 实现insertPlan过程的vector lastCache更新。
2.3. LastCache方案详情
2.3.1. 设计思路
- 为了提升功能代码的内聚性,通过设计ILastCacheContainer接口,将LastCache操作与MNode解耦,由LasCacheContainer实现ILastCacheContainer接口,并封装lastCache数据,同时提供简单的lastCacheValue操作。
- 新建LastCacheManager,将MManager中与lastCache相关的操作代码尽可能迁移至 LastCacheManager,MManager中仅保留必要的mtree调用以及mnode获取操作。
- EntityMNode中增加Map<String, ILastCacheContainer>字段,用于存储template中序列的lastCache;MeasurementMNode中将原来的TimeValuePair替换为ILastCacheContainer,用于存储普通序列的lastCache。
2.3.2. 类设计
类名 | 职责 |
StorageGroupProccessor | 与MManager进行交互,在数据插入、数据删除以及上传新tsfile的时候清空对应序列的lastCache |
LastQueryExecutor | Last查询执行类,调用MManager进行lastCache操作 |
MManager | - 对IoTDB的其他模块提供lastCache的操作接口
- 为LastCacheManager提供node查找功能
|
IEntityMNode与EntityMNode | 实体节点,存储由物理量模板所表示的时间序列的lastCache,即Map<String, ILastCacheContainer> |
IMeasurementMNode与MeasurementMNode | 物理量节点,手动创建时间序列时产生,存储其表示的时间序列的lastCache |
LastCacheManager | 封装所有的lastCache处理逻辑,并向mmanager提供lastCache操作接口 |
ILastCacheContainer | 最新点缓存项接口,声明最新点缓存的操作接口 |
LastCacheContainer | 实现ILastCacheContainer,定义对于一个最新点缓存值的基本操作 |
ILastCacheValue | 最新点缓存值接口,声明 |
UnaryLastCacheValue | 一元序列的最新点缓存值 |
VectorLastCacheValue | 多元序列的最新点缓存值,存储各分量对应的最新点的时间戳与数值 |
2.4. LastCache扩展方向
- LastCache缓存多条数据,LastCacheContainer向BatchedLastCacheContainer扩展
- 底层实现重写,如lastCache存储Memtable中最新的批量数据