Merge pull request #5775 from jonseymour/jss-5499-extend-tsm-cache-stats
tsm: cache: during writes, update the memSize statistic outside the lockpull/5778/merge
commit
2ab79e75eb
|
@ -122,19 +122,21 @@ func NewCache(maxSize uint64, path string) *Cache {
|
||||||
// It returns an error if the cache has exceeded its max size.
|
// It returns an error if the cache has exceeded its max size.
|
||||||
func (c *Cache) Write(key string, values []Value) error {
|
func (c *Cache) Write(key string, values []Value) error {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
|
||||||
|
|
||||||
// Enough room in the cache?
|
// Enough room in the cache?
|
||||||
newSize := c.size + uint64(Values(values).Size())
|
addedSize := Values(values).Size()
|
||||||
|
newSize := c.size + uint64(addedSize)
|
||||||
if c.maxSize > 0 && newSize+c.snapshotsSize > c.maxSize {
|
if c.maxSize > 0 && newSize+c.snapshotsSize > c.maxSize {
|
||||||
|
c.mu.Unlock()
|
||||||
return ErrCacheMemoryExceeded
|
return ErrCacheMemoryExceeded
|
||||||
}
|
}
|
||||||
|
|
||||||
c.write(key, values)
|
c.write(key, values)
|
||||||
c.size = newSize
|
c.size = newSize
|
||||||
|
c.mu.Unlock()
|
||||||
|
|
||||||
// Update the memory size stat
|
// Update the memory size stat
|
||||||
c.updateMemSize(newSize)
|
c.updateMemSize(int64(addedSize))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -164,7 +166,7 @@ func (c *Cache) WriteMulti(values map[string][]Value) error {
|
||||||
c.mu.Unlock()
|
c.mu.Unlock()
|
||||||
|
|
||||||
// Update the memory size stat
|
// Update the memory size stat
|
||||||
c.updateMemSize(newSize)
|
c.updateMemSize(int64(totalSz))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -186,7 +188,7 @@ func (c *Cache) Snapshot() *Cache {
|
||||||
c.snapshots = append(c.snapshots, snapshot)
|
c.snapshots = append(c.snapshots, snapshot)
|
||||||
c.snapshotsSize += snapshot.size
|
c.snapshotsSize += snapshot.size
|
||||||
|
|
||||||
c.updateMemSize(0)
|
c.updateMemSize(-int64(snapshot.size))
|
||||||
c.updateCachedBytes(snapshot.size)
|
c.updateCachedBytes(snapshot.size)
|
||||||
c.updateSnapshots()
|
c.updateSnapshots()
|
||||||
|
|
||||||
|
@ -453,10 +455,8 @@ func (c *Cache) updateCachedBytes(b uint64) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the memSize level
|
// Update the memSize level
|
||||||
func (c *Cache) updateMemSize(b uint64) {
|
func (c *Cache) updateMemSize(b int64) {
|
||||||
memSizeStat := new(expvar.Int)
|
c.statMap.Add(statCacheMemoryBytes, b)
|
||||||
memSizeStat.Set(int64(b))
|
|
||||||
c.statMap.Set(statCacheMemoryBytes, memSizeStat)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the snapshotsCount and the diskSize levels
|
// Update the snapshotsCount and the diskSize levels
|
||||||
|
|
Loading…
Reference in New Issue