lib/storage: compress contents of cache for tagFilters -> TSIDs

This should increase cache capacity
This commit is contained in:
Aliaksandr Valialkin 2019-08-14 01:50:20 +03:00
parent b8bbe92de1
commit f1d81b9405

View File

@ -303,20 +303,36 @@ func (db *indexDB) decRef() {
} }
func (db *indexDB) getFromTagCache(key []byte) ([]TSID, bool) { func (db *indexDB) getFromTagCache(key []byte) ([]TSID, bool) {
value := db.tagCache.GetBig(nil, key) compressedBuf := tagBufPool.Get()
if len(value) == 0 { defer tagBufPool.Put(compressedBuf)
compressedBuf.B = db.tagCache.GetBig(compressedBuf.B[:0], key)
if len(compressedBuf.B) == 0 {
return nil, false return nil, false
} }
tsids, err := unmarshalTSIDs(nil, value) buf := tagBufPool.Get()
defer tagBufPool.Put(buf)
var err error
buf.B, err = encoding.DecompressZSTD(buf.B[:0], compressedBuf.B)
if err != nil {
logger.Panicf("FATAL: cannot decompress tsids from tagCache: %s", err)
}
tsids, err := unmarshalTSIDs(nil, buf.B)
if err != nil { if err != nil {
logger.Panicf("FATAL: cannot unmarshal tsids from tagCache: %s", err) logger.Panicf("FATAL: cannot unmarshal tsids from tagCache: %s", err)
} }
return tsids, true return tsids, true
} }
var tagBufPool bytesutil.ByteBufferPool
func (db *indexDB) putToTagCache(tsids []TSID, key []byte) { func (db *indexDB) putToTagCache(tsids []TSID, key []byte) {
value := marshalTSIDs(nil, tsids) buf := tagBufPool.Get()
db.tagCache.SetBig(key, value) buf.B = marshalTSIDs(buf.B[:0], tsids)
compressedBuf := tagBufPool.Get()
compressedBuf.B = encoding.CompressZSTDLevel(compressedBuf.B[:0], buf.B, 1)
tagBufPool.Put(buf)
db.tagCache.SetBig(key, compressedBuf.B)
tagBufPool.Put(compressedBuf)
} }
func (db *indexDB) getFromMetricIDCache(dst *TSID, metricID uint64) error { func (db *indexDB) getFromMetricIDCache(dst *TSID, metricID uint64) error {