...
...
...
...
...
- 最新的不为空值的
- 为了对每一条时间序列都缓存最新点,因此在元数据树上开辟lastCache字段。
- 代码结构
- 新建LastCacheManager,将MManager中与lastCache相关的操作代码尽可能迁移至 LastCacheManager,MManager中仅保留必要的mtree调用以及mnode获取操作。
- 适配物理量模板:
类名 | 职责 |
L | |
I | |
L | |
I | |
MManager对外接口
功能 | 接口 | 解释 |
---|---|---|
更新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进行调用。
- LastCacheAccessor通过调用MManager.getNodeByPath(PartialPath path)获取序列对应的MeasurementMNode
- 如果是普通序列,则正常返回MeasurementMNode
- 如果是template表示的序列,则将对应的序列schema与封装为临时的MeasurementMNode返回
- LastCacheAccessor调用MManager.getLastCache
- 若1中的操作成功,则可传入node,避免MManager对measurementMNode的二次查找。
- 若1中节点获取失败,则尝试仅基于path查找lastCache结果,此时MManager会基于path进行MeasurementMNode查找
- MManager调用LastCacheMManager的getLastCache接口
- 判断是否为template表示的序列,即判断传入的measurementMNode的parent EntityMNode是否有对应的子节点,若无则从EntityMNode中获取到LastCacheContainer并赋予该measurementMNode
- 如果是普通序列,获取measurementMNode中的lastCacheContainer后获取其持有的lastCacheValue
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接口。
与getLastCache接口类似,updateLastCache接口也可以path和node双参数传入。
- 如果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下与其相匹配的时间序列。
lastCache的删除过程中需根据删除数据的起始时间进行判断是否要清空缓存。
因此MManager提供deleteLastCacheByDevice(PartialPath deviceId, PartialPath originalPath, long startTime, long endTime)接口,MManager获取节点后,具体清除逻辑由LastCacheManager进行执行。
EntityMNode中template的LastCacheContainer与MeasurementMNode的LastCacheContainer均需检查是否需要清空。
3.3.2. upload tsfile执行过程中的last cache清除
upload tsfile后由于引入了新数据,需将对应序列的last cache清空,此过程也是以device为单位进行执行。
MManager提供deleteLastCacheByDevice(PartialPath deviceId)接口,具体过程与3.3.1类似。