From 56e0c6adf84df0767f9b137b685c8a0b7ddb57e8 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Fri, 15 May 2020 06:46:36 +0200 Subject: [PATCH] Track if bloom filter is dirty (#9601) Only save bloom filter on cycles and updates. Fixes #9600 --- cmd/data-update-tracker.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/data-update-tracker.go b/cmd/data-update-tracker.go index 77c84eddf..033b13feb 100644 --- a/cmd/data-update-tracker.go +++ b/cmd/data-update-tracker.go @@ -69,6 +69,7 @@ type dataUpdateTracker struct { save chan struct{} debug bool saveExited chan struct{} + dirty bool Current dataUpdateFilter History dataUpdateTrackerHistory @@ -87,6 +88,7 @@ func newDataUpdateTracker() *dataUpdateTracker { saveExited: make(chan struct{}), } d.Current.bf = d.newBloomFilter() + d.dirty = true return d } @@ -235,11 +237,16 @@ func (d *dataUpdateTracker) startSaver(ctx context.Context, interval time.Durati } buf.Reset() d.mu.Lock() + if !d.dirty { + d.mu.Unlock() + return + } d.Saved = UTCNow() err := d.serialize(&buf) if d.debug { logger.Info(color.Green("dataUpdateTracker:")+" Saving: %v bytes, Current idx: %v", buf.Len(), d.Current.idx) } + d.dirty = false d.mu.Unlock() if err != nil { logger.LogIf(ctx, err, "Error serializing usage tracker data") @@ -459,6 +466,7 @@ func (d *dataUpdateTracker) startCollector(ctx context.Context) { hashPath(path.Join(split[:i+1]...)).bytes(tmp[:]) d.Current.bf.Add(tmp[:]) } + d.dirty = d.dirty || len(split) > 0 d.mu.Unlock() } } @@ -527,7 +535,6 @@ func (d *dataUpdateTracker) filterFrom(ctx context.Context, oldest, newest uint6 func (d *dataUpdateTracker) cycleFilter(ctx context.Context, oldest, current uint64) (*bloomFilterResponse, error) { d.mu.Lock() defer d.mu.Unlock() - if current == 0 { if len(d.History) == 0 { return d.filterFrom(ctx, d.Current.idx, d.Current.idx), nil @@ -538,6 +545,7 @@ func (d *dataUpdateTracker) cycleFilter(ctx context.Context, oldest, current uin // Move current to history if new one requested if d.Current.idx != current { + d.dirty = true if d.debug { logger.Info(color.Green("dataUpdateTracker:")+" cycle bloom filter: %v -> %v", d.Current.idx, current) }