From c93da21a613d01786cd2117041b6abf1572603fe Mon Sep 17 00:00:00 2001 From: Jon Seymour Date: Mon, 22 Feb 2016 15:13:57 +1100 Subject: [PATCH] tsm: cache: only use NewCache for engine cache's snapshots use a simpler constructor The intent of this change is to avoid writing caches created for snapshot cache instances into the tsm1_cache measurement. We can do this by avoiding use of the NewCache constructor. All other methods are only intended to be called from on the engine cache - never on a snapshot. Signed-off-by: Jon Seymour --- tsdb/engine/tsm1/cache.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tsdb/engine/tsm1/cache.go b/tsdb/engine/tsm1/cache.go index 2d056575be..574cf50030 100644 --- a/tsdb/engine/tsm1/cache.go +++ b/tsdb/engine/tsm1/cache.go @@ -94,20 +94,17 @@ type Cache struct { snapshots []*Cache snapshotsSize uint64 - statMap *expvar.Map + statMap *expvar.Map // nil for snapshots. lastSnapshot time.Time - - // path is only used to track stats - path string } // NewCache returns an instance of a cache which will use a maximum of maxSize bytes of memory. +// Only used for engine caches, never for snapshots func NewCache(maxSize uint64, path string) *Cache { c := &Cache{ maxSize: maxSize, store: make(map[string]*entry), statMap: influxdb.NewStatistics("tsm1_cache:"+path, "tsm1_cache", map[string]string{"path": path}), - path: path, lastSnapshot: time.Now(), } c.UpdateAge() @@ -177,9 +174,10 @@ func (c *Cache) Snapshot() *Cache { c.mu.Lock() defer c.mu.Unlock() - snapshot := NewCache(c.maxSize, c.path+"!snapshot") - snapshot.store = c.store - snapshot.size = c.size + snapshot := &Cache{ + store: c.store, + size: c.size, + } c.store = make(map[string]*entry) c.size = 0