Skip to content

Commit 4870bb8

Browse files
authored
Merge pull request #764 from deniszh/dzhdanov/cache64
Make cache size 64 bit
2 parents 7c0021b + b5d3df4 commit 4870bb8

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

cache/cache.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const (
3030
const shardCount = 1024
3131

3232
type cacheSettings struct {
33-
maxSize int32
33+
maxSize int64
3434
xlog io.Writer
3535
tagsEnabled bool
3636
}
@@ -50,7 +50,7 @@ type Cache struct {
5050
settings atomic.Value // cacheSettings
5151

5252
stat struct {
53-
size int32 // changing via atomic
53+
size int64 // changing via atomic
5454
queueBuildCnt uint32 // number of times writeout queue was built
5555
queueBuildTimeMs uint32 // time spent building writeout queue in milliseconds
5656
queueWriteoutTime uint32 // in milliseconds
@@ -129,10 +129,10 @@ func (c *Cache) SetWriteStrategy(s string) (err error) {
129129
}
130130

131131
// SetMaxSize of cache
132-
func (c *Cache) SetMaxSize(maxSize uint32) {
132+
func (c *Cache) SetMaxSize(maxSize uint64) {
133133
s := c.settings.Load().(*cacheSettings)
134134
newSettings := *s
135-
newSettings.maxSize = int32(maxSize)
135+
newSettings.maxSize = int64(maxSize)
136136
c.settings.Store(&newSettings)
137137
}
138138

@@ -274,8 +274,8 @@ func (c *Cache) NotConfirmedLength() int32 {
274274
return int32(l)
275275
}
276276

277-
func (c *Cache) Size() int32 {
278-
return atomic.LoadInt32(&c.stat.size)
277+
func (c *Cache) Size() int64 {
278+
return atomic.LoadInt64(&c.stat.size)
279279
}
280280

281281
func (c *Cache) DivertToXlog(w io.Writer) {
@@ -353,7 +353,7 @@ func (c *Cache) Add(p *points.Points) {
353353
}
354354

355355
}
356-
atomic.AddInt32(&c.stat.size, int32(count))
356+
atomic.AddInt64(&c.stat.size, int64(count))
357357
}
358358

359359
// Pop removes an element from the map and returns it
@@ -366,7 +366,7 @@ func (c *Cache) Pop(key string) (p *points.Points, exists bool) {
366366
shard.Unlock()
367367

368368
if exists {
369-
atomic.AddInt32(&c.stat.size, -int32(len(p.Data)))
369+
atomic.AddInt64(&c.stat.size, -int64(len(p.Data)))
370370
}
371371

372372
return p, exists
@@ -390,7 +390,7 @@ func (c *Cache) PopNotConfirmed(key string) (p *points.Points, exists bool) {
390390
shard.Unlock()
391391

392392
if exists {
393-
atomic.AddInt32(&c.stat.size, -int32(len(p.Data)))
393+
atomic.AddInt64(&c.stat.size, -int64(len(p.Data)))
394394
}
395395

396396
return p, exists

cache/dump_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func fillCacheForDump() *Cache {
2121
pointsCount := 5
2222

2323
c := New()
24-
c.SetMaxSize(uint32(pointsCount*metrics + 1))
24+
c.SetMaxSize(uint64(pointsCount*metrics + 1))
2525

2626
baseTimestamp := time.Now().Unix()
2727

carbon/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ type whisperConfig struct {
7979
}
8080

8181
type cacheConfig struct {
82-
MaxSize uint32 `toml:"max-size"`
82+
MaxSize uint64 `toml:"max-size"`
8383
WriteStrategy string `toml:"write-strategy"`
8484
BloomSize uint64 `toml:"bloom-size"`
8585
}

carbon/grace.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (app *App) DumpStop() error {
9494
}
9595

9696
logger.Info("cache dump finished",
97-
zap.Int("records", int(cacheSize)),
97+
zap.Int64("records", int64(cacheSize)),
9898
zap.Duration("runtime", time.Since(dumpStart)),
9999
)
100100

0 commit comments

Comments
 (0)