cacheFor evaluates the cacheInfo and returns the appropriate cache.
(cacheInfo *backend.CacheInfo)
| 174 | |
| 175 | // cacheFor evaluates the cacheInfo and returns the appropriate cache. |
| 176 | func (r *readerWriter) cacheFor(cacheInfo *backend.CacheInfo) cache.Cache { |
| 177 | if cacheInfo == nil { |
| 178 | return nil |
| 179 | } |
| 180 | |
| 181 | switch cacheInfo.Role { |
| 182 | case cache.RoleParquetFooter: |
| 183 | return r.footerCache |
| 184 | case cache.RoleParquetColumnIdx: |
| 185 | return r.columnIdxCache |
| 186 | case cache.RoleParquetOffsetIdx: |
| 187 | return r.offsetIdxCache |
| 188 | case cache.RoleParquetPage: |
| 189 | return r.pageCache |
| 190 | case cache.RoleTraceIDIdx: |
| 191 | return r.traceIDIdxCache |
| 192 | case cache.RoleBloom: |
| 193 | // if there is no bloom cfg then there are no restrictions on bloom filter caching |
| 194 | if r.cfgBloom == nil { |
| 195 | return r.bloomCache |
| 196 | } |
| 197 | |
| 198 | if cacheInfo.Meta == nil { |
| 199 | return nil |
| 200 | } |
| 201 | |
| 202 | // compaction level is _atleast_ CacheMinCompactionLevel |
| 203 | if r.cfgBloom.CacheMinCompactionLevel > 0 && cacheInfo.Meta.CompactionLevel > uint32(r.cfgBloom.CacheMinCompactionLevel) { |
| 204 | return nil |
| 205 | } |
| 206 | |
| 207 | curTime := time.Now() |
| 208 | // block is not older than CacheMaxBlockAge |
| 209 | if r.cfgBloom.CacheMaxBlockAge > 0 && curTime.Sub(cacheInfo.Meta.StartTime) > r.cfgBloom.CacheMaxBlockAge { |
| 210 | return nil |
| 211 | } |
| 212 | |
| 213 | return r.bloomCache |
| 214 | } |
| 215 | |
| 216 | return nil |
| 217 | } |
| 218 | |
| 219 | func store(ctx context.Context, cache cache.Cache, role cache.Role, key string, val []byte) { |
| 220 | write := val |