Fix comment and remove snapshot stutter

pull/4989/head
Philip O'Toole 2015-12-04 07:29:58 -08:00
parent b73b21f062
commit f939e49f0f
1 changed files with 10 additions and 10 deletions

View File

@ -55,11 +55,11 @@ type Cache struct {
size uint64 size uint64
maxSize uint64 maxSize uint64
// flushingCaches are the cache objects that are currently being written to tsm files // snapshots are the cache objects that are currently being written to tsm files
// they're kept in memory while flushing so they can be queried along with the cache. // they're kept in memory while flushing so they can be queried along with the cache.
// they are read only and should never be modified // they are read only and should never be modified
snapshotCaches []*Cache snapshots []*Cache
snapshotCachesSize uint64 snapshotsSize uint64
} }
// NewCache returns an instance of a cache which will use a maximum of maxSize bytes of memory. // NewCache returns an instance of a cache which will use a maximum of maxSize bytes of memory.
@ -78,7 +78,7 @@ func (c *Cache) Write(key string, values []Value) error {
// Enough room in the cache? // Enough room in the cache?
newSize := c.size + uint64(Values(values).Size()) newSize := c.size + uint64(Values(values).Size())
if c.maxSize > 0 && newSize+c.snapshotCachesSize > c.maxSize { if c.maxSize > 0 && newSize+c.snapshotsSize > c.maxSize {
return ErrCacheMemoryExceeded return ErrCacheMemoryExceeded
} }
@ -101,7 +101,7 @@ func (c *Cache) WriteMulti(values map[string][]Value) error {
// Enough room in the cache? // Enough room in the cache?
newSize := c.size + uint64(totalSz) newSize := c.size + uint64(totalSz)
if c.maxSize > 0 && newSize+c.snapshotCachesSize > c.maxSize { if c.maxSize > 0 && newSize+c.snapshotsSize > c.maxSize {
return ErrCacheMemoryExceeded return ErrCacheMemoryExceeded
} }
@ -126,8 +126,8 @@ func (c *Cache) Snapshot() *Cache {
c.store = make(map[string]*entry) c.store = make(map[string]*entry)
c.size = 0 c.size = 0
c.snapshotCaches = append(c.snapshotCaches, snapshot) c.snapshots = append(c.snapshots, snapshot)
c.snapshotCachesSize += snapshot.size c.snapshotsSize += snapshot.size
// sort the snapshot before returning it. The compactor and any queries // sort the snapshot before returning it. The compactor and any queries
// coming in while it writes will need the values sorted // coming in while it writes will need the values sorted
@ -147,10 +147,10 @@ func (c *Cache) ClearSnapshot(snapshot *Cache) {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock() defer c.mu.Unlock()
for i, cache := range c.snapshotCaches { for i, cache := range c.snapshots {
if cache == snapshot { if cache == snapshot {
c.snapshotCaches = append(c.snapshotCaches[:i], c.snapshotCaches[i+1:]...) c.snapshots = append(c.snapshots[:i], c.snapshots[i+1:]...)
c.snapshotCachesSize -= snapshot.size c.snapshotsSize -= snapshot.size
break break
} }
} }