Fix race in (*tsm1.Cache).values

Without this read lock, this race would happen during a concurrent
snapshot compaction and query.
pull/7809/head
Mark Rushakoff 2017-01-09 12:12:31 -08:00
parent 4a559c4620
commit 3b3604e362
1 changed files with 7 additions and 3 deletions

View File

@ -554,14 +554,18 @@ func (c *Cache) SetMaxSize(size uint64) {
c.mu.Unlock()
}
// values returns the values for the key. It doesn't lock and assumes the data is
// already sorted. Should only be used in compact.go in the CacheKeyIterator
// values returns the values for the key. It assumes the data is already sorted.
// It doesn't lock the cache but it does read-lock the entry if there is one for the key.
// values should only be used in compact.go in the CacheKeyIterator.
func (c *Cache) values(key string) Values {
e, _ := c.store.entry(key)
if e == nil {
return nil
}
return e.values
e.mu.RLock()
v := e.values
e.mu.RUnlock()
return v
}
// ApplyEntryFn applies the function f to each entry in the Cache.