Ensure that cached series id sets are Go heap backed

pull/11835/head
Jeff Wendling 2019-02-12 14:47:07 -07:00
parent 007f5059c7
commit 26ca30e97a
2 changed files with 9 additions and 2 deletions

View File

@ -110,6 +110,11 @@ func (c *TagValueSeriesIDCache) Put(name, key, value []byte, ss *tsdb.SeriesIDSe
}
defer c.Unlock()
// Ensure our SeriesIDSet is go heap backed.
if ss != nil {
ss = ss.Clone()
}
// Create list item, and add to the front of the eviction list.
listElement := c.evictor.PushFront(&seriesIDCacheElement{
name: string(name),

View File

@ -147,7 +147,7 @@ func TestTagValueSeriesIDCache_addToSet(t *testing.T) {
cache.addToSet([]byte("m0"), []byte("k0"), []byte("v0"), tsdb.NewSeriesID(20)) // No non-nil set exists so one will be created
cache.addToSet([]byte("m0"), []byte("k0"), []byte("v1"), tsdb.NewSeriesID(101)) // No non-nil set exists so one will be created
cache.Has(t, "m0", "k0", "v1", s2)
cache.Has(t, "m0", "k0", "v1", newSeriesIDSet(100, 101))
ss := cache.GetByString("m0", "k0", "v0")
if !newSeriesIDSet(20).Equals(ss) {
@ -232,13 +232,15 @@ type TestCache struct {
}
func (c TestCache) Has(t *testing.T, name, key, value string, ss *tsdb.SeriesIDSet) {
if got, exp := c.Get([]byte(name), []byte(key), []byte(value)), ss; got != exp {
if got, exp := c.Get([]byte(name), []byte(key), []byte(value)), ss; !got.Equals(exp) {
t.Helper()
t.Fatalf("got set %v, expected %v", got, exp)
}
}
func (c TestCache) HasNot(t *testing.T, name, key, value string) {
if got := c.Get([]byte(name), []byte(key), []byte(value)); got != nil {
t.Helper()
t.Fatalf("got non-nil set %v for {%q, %q, %q}", got, name, key, value)
}
}