mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/storage: compress contents of cache for tagFilters -> TSIDs
This should increase cache capacity
This commit is contained in:
parent
b8bbe92de1
commit
f1d81b9405
1 changed files with 21 additions and 5 deletions
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue