You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

1. 0.12版本lastCache实现

1.1. 存储方式

在MeasurementMNode中存储一个TimeValuePair;

由MeasurementMNode提供操作接口。

1.2. lastCache触发时机

  1. insertPlan执行完后updateLastCache
  2. last查询,先从缓存中查找,若miss则从文件获取数据后updateLastCache
  3. delete数据时,根据删除数据的起始时间清空lastCache
  4. upload Tsfile时,由于数据更新,lastCache可能失效,故清空

1.3. lastCache操作执行过程

  1. getLastCache:首先通过调用getNodeByPath,获取指定路径/序列对应的 MeasurementMNode,template对应的序列会封装一个临时节点对象,调用MeasurementMNode的get接口
  2. updateLastCache:与getLastCache类似
  3. resetCache:storageGroupProccessor通过device获取子节点,调用子节点的reset接口

2. 适配物理量模板Template

2.1. Template的lastCache失败原因

获取template中序列对应的measurementMNode时,仅返回临时变量,对临时MeasurementMNode中lastCache的操作并未保存回MTree。

2.2. 适配方案

由于Template由EntityMNode进行使用,因此在EntityMNode中增加Map<String, ILastCacheEntry>字段,用于存储template所表示的时间序列的lastCache。

对MeasurementMNode中的lastCache进行操作时,先判断该节点是否是为了template而创建的临时节点,如果是,则先拿到entityMNode中的lastCache引用,然后再进行操作。

3. 适配多元时间序列

3.1. 多元时间序列的lastCache失败原因

  1. MeasurementMNode中简单的TimeValuePair无法满足多元分量的lastCache的存储。
  2. LastQueryPlan的执行过程中,path被转化为vectorPartiaPath之后,仅到多元序列层,未基于分量路径subsensorPath进行lastCache查找
  3. insertPlan执行过程中,对于aligned plan不进行lastCache的更新

3.2. 适配方案

  1. 建立VectorLastCacheValue,存储多元时间序列的lastCache;由于目前last查找是查找最新的不为空值的时间点,故不同分量的LastCache时间可能不同,需要存储多个timestamp和 TsPrimitiveValue。
  2. 修改LastQueryExecutor中seriesPath的使用,使其应用到subsensor层即分量对应的路径。
  3. 实现insertPlan过程的vector lastCache更新。

4. LastCache方案详情

4.1. 设计思路

  1. 为了提升功能代码的内聚性,将LastCache功能与MNode解耦,设计ILastCacheEntry接口,由LasCacheEntry进行实现并封装lastCache数据,同时提供简单的lastCacheValue操作
  2. 新建LastCacheManager,将MManager中与lastCache相关的操作代码尽可能迁移至 LastCacheManager,MManager中仅保留必要的mtree调用以及mnode获取操作。
  3. EntityMNode中增加Map<String, ILastCacheEntry>字段,用于存储template中序列的lastCache;MeasurementMNode中将原来的TimeValuePair替换为ILastCacheEntry,用于存储普通序列的lastCache。

4.2. 类设计


类名

职责

StorageGroupProccessor

与MManager进行交互,在数据插入、数据删除以及上传新tsfile的时候清空对应序列的lastCache

LastQueryExecutor

Last查询执行类,调用MManager进行lastCache操作

MManager

  1. 对IoTDB的其他模块提供lastCache的操作接口
  2. 为LastCacheManager提供node查找功能

IEntityMNode与EntityMNode

实体节点,存储由物理量模板所表示的时间序列的lastCache,即Map<String, ILastCacheEntry>

IMeasurementMNode与MeasurementMNode

物理量节点,手动创建时间序列时产生,存储其表示的时间序列的lastCache

LastCacheManager

封装所有的lastCache处理逻辑,并向mmanager提供lastCache操作接口

ILastCacheEntry

最新点缓存项接口,声明最新点缓存的操作接口

LastCacheEntry

实现ILastCacheEntry,定义对于一个最新点缓存值的基本操作

ILastCacheValue

最新点缓存值接口,声明

MonadLastCacheValue

一元序列的最新点缓存值

VectorLastCacheValue

多元序列的最新点缓存值,存储各分量对应的最新点的时间戳与数值


4.2. LastCache扩展方向

  1. LastCache缓存多条数据,LastCacheEntry向BatchedLastCacheEntry扩展
  2. 底层实现重写,如lastCache存储Memtable中最新的批量数据
  • No labels