- 为了对每一条时间序列都缓存最新点,因此在元数据树上开辟lastCache字段。
- 代码结构
- 新建LastCacheManager,将MManager中与lastCache相关的操作代码尽可能迁移至 LastCacheManager,MManager中仅保留必要的mtree调用以及mnode获取操作。
- 适配物理量模板:
类名 | 职责 |
L | |
I | |
L | |
I | |
...
功能 | 接口 | 解释 |
---|---|---|
更新lastCache | public void updateLastCache( | 接收seriesPath作为参数, 用于更新序列的lastCache, 需传入序列全路径。 |
public void updateLastCache( | 接收单个MeasurementMNode作为参数, 用于更新序列的lastCache | |
获取lastCache | public TimeValuePair getLastCache(PartialPath seriesPath) | 接收seriesPath作为参数, 用于获取序列的lastCache, 需传入序列的全路径 |
public TimeValuePair getLastCache(IMeasurementMNode node) | 接收单个MeasurementMNode作为参数, 用于获取序列的lastCache | |
删除lastCache | public void resetLastCache(PartialPath seriesPath) | 接收seriesPath作为参数, 用于清除序列的lastCache, 需传入序列的全路径 |
public void deleteLastCacheByDevice(PartialPath deviceId) | 用于清除一个device下所有序列的lastCache | |
public void deleteLastCacheByDevice( | 由于清除一个device下匹配originalPath的、且last值在startTime和endTime之间的所有序列的lastCache |
3. 调用场景及执行过程
3.1. last cache查询
last cache查询主要在Last Query的执行过程中,由LastQueryExecutor中的LastCacheAccessor进行调用。
...
2中情况的一个典型场景为分布式中,node的获取不会返回本地缓存的remote measurementMNode,但是lastCache查询可以先走remote measurementMNode中进行查询。
3.2. last cache更新
3.2.1. Last Query执行过程中的last cache更新
last查询过程中,若cache miss,则会从文件中读取last value,并且将该值进行缓存,此时LastCacheAccesso将调用MManager的updateLastCache接口。
...
- 如果LastCacheAccessor先前已成功获取node,则将node传入,MManager避免node的二次查找
- LastCacheAccessor先前未获取到node,则基于path更新lastCache,MManager将基于path查找对应node
- MManager调用LastCacheManager的updateLastCache接口,不同类型序列的处理逻辑与3.1中3的逻辑大致相同
3.2.2. insertPlan执行过程中的last cache更新
insertPlan执行过程中,插入的数据的最新点需缓存,由StorageGroupProcessor调用MManager的updateLastCache接口。
为了解决insert和last query的并发更新,updateLastCache中设置priority参数,insert的last cache更新优先级高于last query。
3.3. last cache 清除
3.3.1. delete执行过程中的last cache清除
StorageGroupProcessor在执行delete的过程中,会基于用户输入的originPath以device为单位进行删除操作,originPath是一个可以包含通配符*的路径,需筛选device下与其相匹配的时间序列。
...
EntityMNode中template的LastCacheContainer与MeasurementMNode的LastCacheContainer均需检查是否需要清空。
3.3.2. upload tsfile执行过程中的last cache清除
upload tsfile后由于引入了新数据,需将对应序列的last cache清空,此过程也是以device为单位进行执行。
MManager提供deleteLastCacheByDevice(PartialPath deviceId)接口,具体过程与3.3.1类似。