From 87ceb7426a094c4296f95854bf7dba8a7c0baea4 Mon Sep 17 00:00:00 2001 From: Jason Wilder Date: Fri, 1 Apr 2016 09:50:11 -0600 Subject: [PATCH] Don't lock the cache while adding entries Entries have their own locking so the cache doesn't need to be lock when adding to them. --- tsdb/engine/tsm1/cache.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tsdb/engine/tsm1/cache.go b/tsdb/engine/tsm1/cache.go index aefbab6e63..b1c83b722a 100644 --- a/tsdb/engine/tsm1/cache.go +++ b/tsdb/engine/tsm1/cache.go @@ -185,10 +185,10 @@ func (c *Cache) WriteMulti(values map[string][]Value) error { } c.mu.RUnlock() - c.mu.Lock() for k, v := range values { - c.write(k, v) + c.entry(k).add(v) } + c.mu.Lock() c.size = newSize c.mu.Unlock() @@ -416,6 +416,17 @@ func (c *Cache) write(key string, values []Value) { e.add(values) } +func (c *Cache) entry(key string) *entry { + c.mu.Lock() + e, ok := c.store[key] + if !ok { + e = newEntry() + c.store[key] = e + } + c.mu.Unlock() + return e +} + // CacheLoader processes a set of WAL segment files, and loads a cache with the data // contained within those files. Processing of the supplied files take place in the // order they exist in the files slice.