Skip to content

Commit 66a4e73

Browse files
committed
fix(aggregator): use StartPeriodicSaving instead of custom loop
1 parent 99e7561 commit 66a4e73

File tree

3 files changed

+4
-10
lines changed

3 files changed

+4
-10
lines changed

internal/aggregator/aggregator.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,7 @@ func MakeAggregator(dc pcache.DiskCache, fj *os.File, fjCompact *os.File, mappin
363363

364364
sh2.Run(a.aggregatorHost, a.shardKey, a.replicaKey)
365365

366-
go func() {
367-
for {
368-
time.Sleep(time.Hour) // arbitrary
369-
_, _ = mappingsCache.Save()
370-
a.SaveJournals()
371-
}
372-
}()
366+
mappingsCache.StartPeriodicSaving()
373367

374368
return a, nil
375369
}

internal/metajournal/journal_fast.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,9 +572,8 @@ func (ms *JournalFast) StartPeriodicSaving() {
572572

573573
func (ms *JournalFast) goPeriodicSaving() {
574574
for {
575-
sleepDuration := ms.periodicSaveInterval + time.Duration(rand.Intn(int(ms.periodicSaveInterval)))*time.Second
575+
sleepDuration := ms.periodicSaveInterval + time.Duration(rand.Intn(int(ms.periodicSaveInterval)))
576576
time.Sleep(sleepDuration)
577-
578577
ok, version, err := ms.Save()
579578
if err != nil {
580579
log.Printf("Periodic journal save failed: %v", err)

internal/pcache/mappings_cache.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ func (c *MappingsCache) AddValues(nowUnix uint32, pairs []MappingPair) {
329329
for _, p := range pairs {
330330
c.addItem(p.Str, p.Value, nowUnix)
331331
}
332+
c.version += 1
332333
return
333334
}
334335
removeSize := c.sumSize + newItemsSizeMem - maxSize
@@ -542,7 +543,7 @@ func (c *MappingsCache) StartPeriodicSaving() {
542543

543544
func (c *MappingsCache) goPeriodicSaving() {
544545
for {
545-
sleepDuration := c.periodicSaveInterval + time.Duration(rand.Intn(int(c.periodicSaveInterval)))*time.Second
546+
sleepDuration := c.periodicSaveInterval + time.Duration(rand.Intn(int(c.periodicSaveInterval)))
546547
time.Sleep(sleepDuration)
547548

548549
ok, err := c.Save()

0 commit comments

Comments
 (0)