Include snapshot size in the total cache size
This was causing a shard to appear idle when in fact a snapshot compaction was running. If the time was write, the compactions would be disabled and the snapshot compaction would be aborted.pull/8348/head
parent
88848a9426
commit
b4ea523910
|
@ -260,7 +260,7 @@ func (c *Cache) Write(key string, values []Value) error {
|
||||||
|
|
||||||
// Enough room in the cache?
|
// Enough room in the cache?
|
||||||
limit := c.maxSize
|
limit := c.maxSize
|
||||||
n := c.Size() + atomic.LoadUint64(&c.snapshotSize) + addedSize
|
n := c.Size() + addedSize
|
||||||
|
|
||||||
if limit > 0 && n > limit {
|
if limit > 0 && n > limit {
|
||||||
atomic.AddInt64(&c.stats.WriteErr, 1)
|
atomic.AddInt64(&c.stats.WriteErr, 1)
|
||||||
|
@ -293,7 +293,7 @@ func (c *Cache) WriteMulti(values map[string][]Value) error {
|
||||||
|
|
||||||
// Enough room in the cache?
|
// Enough room in the cache?
|
||||||
limit := c.maxSize // maxSize is safe for reading without a lock.
|
limit := c.maxSize // maxSize is safe for reading without a lock.
|
||||||
n := c.Size() + atomic.LoadUint64(&c.snapshotSize) + addedSize
|
n := c.Size() + addedSize
|
||||||
if limit > 0 && n > limit {
|
if limit > 0 && n > limit {
|
||||||
atomic.AddInt64(&c.stats.WriteErr, 1)
|
atomic.AddInt64(&c.stats.WriteErr, 1)
|
||||||
return ErrCacheMemorySizeLimitExceeded(n, limit)
|
return ErrCacheMemorySizeLimitExceeded(n, limit)
|
||||||
|
@ -416,7 +416,7 @@ func (c *Cache) ClearSnapshot(success bool) {
|
||||||
|
|
||||||
// Size returns the number of point-calcuated bytes the cache currently uses.
|
// Size returns the number of point-calcuated bytes the cache currently uses.
|
||||||
func (c *Cache) Size() uint64 {
|
func (c *Cache) Size() uint64 {
|
||||||
return atomic.LoadUint64(&c.size)
|
return atomic.LoadUint64(&c.size) + atomic.LoadUint64(&c.snapshotSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
// increaseSize increases size by delta.
|
// increaseSize increases size by delta.
|
||||||
|
|
|
@ -448,7 +448,7 @@ func TestCache_Snapshot_Stats(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store size should have been reset.
|
// Store size should have been reset.
|
||||||
if got, exp := c.Size(), uint64(0); got != exp {
|
if got, exp := c.Size(), uint64(16); got != exp {
|
||||||
t.Fatalf("got %v, expected %v", got, exp)
|
t.Fatalf("got %v, expected %v", got, exp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue