Skip to content

Commit

Permalink
Include snapshot size in the total cache size
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jwilder committed May 3, 2017
1 parent c057bd4 commit 053064d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions tsdb/engine/tsm1/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func (c *Cache) Write(key string, values []Value) error {

// Enough room in the cache?
limit := c.maxSize
n := c.Size() + atomic.LoadUint64(&c.snapshotSize) + addedSize
n := c.Size() + addedSize

if limit > 0 && n > limit {
atomic.AddInt64(&c.stats.WriteErr, 1)
Expand Down Expand Up @@ -293,7 +293,7 @@ func (c *Cache) WriteMulti(values map[string][]Value) error {

// Enough room in the cache?
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 {
atomic.AddInt64(&c.stats.WriteErr, 1)
return ErrCacheMemorySizeLimitExceeded(n, limit)
Expand Down Expand Up @@ -416,7 +416,7 @@ func (c *Cache) ClearSnapshot(success bool) {

// Size returns the number of point-calcuated bytes the cache currently uses.
func (c *Cache) Size() uint64 {
return atomic.LoadUint64(&c.size)
return atomic.LoadUint64(&c.size) + atomic.LoadUint64(&c.snapshotSize)
}

// increaseSize increases size by delta.
Expand Down
2 changes: 1 addition & 1 deletion tsdb/engine/tsm1/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ func TestCache_Snapshot_Stats(t *testing.T) {
}

// 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)
}

Expand Down

0 comments on commit 053064d

Please sign in to comment.