From 7353364ad35b01b334893d7e6e440317a37c3aa6 Mon Sep 17 00:00:00 2001 From: Denys Zhdanov Date: Fri, 29 Aug 2025 10:02:46 +0200 Subject: [PATCH 1/4] Make cache size 64 bit --- cache/cache.go | 18 +++++++++--------- carbon/config.go | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cache/cache.go b/cache/cache.go index 179b3e2f..9e82d1cf 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -30,7 +30,7 @@ const ( const shardCount = 1024 type cacheSettings struct { - maxSize int32 + maxSize int64 xlog io.Writer tagsEnabled bool } @@ -50,7 +50,7 @@ type Cache struct { settings atomic.Value // cacheSettings stat struct { - size int32 // changing via atomic + size int64 // changing via atomic queueBuildCnt uint32 // number of times writeout queue was built queueBuildTimeMs uint32 // time spent building writeout queue in milliseconds queueWriteoutTime uint32 // in milliseconds @@ -129,10 +129,10 @@ func (c *Cache) SetWriteStrategy(s string) (err error) { } // SetMaxSize of cache -func (c *Cache) SetMaxSize(maxSize uint32) { +func (c *Cache) SetMaxSize(maxSize uint64) { s := c.settings.Load().(*cacheSettings) newSettings := *s - newSettings.maxSize = int32(maxSize) + newSettings.maxSize = int64(maxSize) c.settings.Store(&newSettings) } @@ -274,8 +274,8 @@ func (c *Cache) NotConfirmedLength() int32 { return int32(l) } -func (c *Cache) Size() int32 { - return atomic.LoadInt32(&c.stat.size) +func (c *Cache) Size() int64 { + return atomic.LoadInt64(&c.stat.size) } func (c *Cache) DivertToXlog(w io.Writer) { @@ -353,7 +353,7 @@ func (c *Cache) Add(p *points.Points) { } } - atomic.AddInt32(&c.stat.size, int32(count)) + atomic.AddInt64(&c.stat.size, int64(count)) } // 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) { shard.Unlock() if exists { - atomic.AddInt32(&c.stat.size, -int32(len(p.Data))) + atomic.AddInt64(&c.stat.size, -int64(len(p.Data))) } return p, exists @@ -390,7 +390,7 @@ func (c *Cache) PopNotConfirmed(key string) (p *points.Points, exists bool) { shard.Unlock() if exists { - atomic.AddInt32(&c.stat.size, -int32(len(p.Data))) + atomic.AddInt64(&c.stat.size, -int64(len(p.Data))) } return p, exists diff --git a/carbon/config.go b/carbon/config.go index e97ffe42..bdea6b69 100644 --- a/carbon/config.go +++ b/carbon/config.go @@ -79,7 +79,7 @@ type whisperConfig struct { } type cacheConfig struct { - MaxSize uint32 `toml:"max-size"` + MaxSize uint64 `toml:"max-size"` WriteStrategy string `toml:"write-strategy"` BloomSize uint64 `toml:"bloom-size"` } From 0e46f4fa01a1a32e980dc81c7b28c8223adc0fe2 Mon Sep 17 00:00:00 2001 From: Denys Zhdanov Date: Fri, 29 Aug 2025 10:09:26 +0200 Subject: [PATCH 2/4] Fix tests --- cache/dump_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache/dump_test.go b/cache/dump_test.go index 9bdb318b..7e6172d0 100644 --- a/cache/dump_test.go +++ b/cache/dump_test.go @@ -21,7 +21,7 @@ func fillCacheForDump() *Cache { pointsCount := 5 c := New() - c.SetMaxSize(uint32(pointsCount*metrics + 1)) + c.SetMaxSize(uint64(pointsCount*metrics + 1)) baseTimestamp := time.Now().Unix() From c9a88429b60669b58b582b4a4bfc288bfc873b75 Mon Sep 17 00:00:00 2001 From: Denys Zhdanov Date: Fri, 29 Aug 2025 10:10:59 +0200 Subject: [PATCH 3/4] Fixing Potential Logging Bug --- carbon/grace.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/carbon/grace.go b/carbon/grace.go index e904354b..44e9616a 100644 --- a/carbon/grace.go +++ b/carbon/grace.go @@ -94,7 +94,7 @@ func (app *App) DumpStop() error { } logger.Info("cache dump finished", - zap.Int("records", int(cacheSize)), + zap.Int64("records", int(cacheSize)), zap.Duration("runtime", time.Since(dumpStart)), ) From b5d3df43c910845b04bb44777d265964621b099d Mon Sep 17 00:00:00 2001 From: Denys Zhdanov Date: Fri, 29 Aug 2025 10:12:46 +0200 Subject: [PATCH 4/4] typo --- carbon/grace.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/carbon/grace.go b/carbon/grace.go index 44e9616a..60efdfa7 100644 --- a/carbon/grace.go +++ b/carbon/grace.go @@ -94,7 +94,7 @@ func (app *App) DumpStop() error { } logger.Info("cache dump finished", - zap.Int64("records", int(cacheSize)), + zap.Int64("records", int64(cacheSize)), zap.Duration("runtime", time.Since(dumpStart)), )