From 7b335b6dc3b822d92b2530f3457e5f96ec5efab8 Mon Sep 17 00:00:00 2001 From: Lukas Fittl Date: Wed, 29 Nov 2023 00:58:02 -0800 Subject: [PATCH] Compact snapshot stats: Fix incorrect counting for current snapshot (#481) Due to the way the code was written, we would either count the current snapshot, or emit statistics - but even if we emit statistics we still need to increment the snapshot count. --- output/compact.go | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/output/compact.go b/output/compact.go index afc7b1e02..39fecad67 100644 --- a/output/compact.go +++ b/output/compact.go @@ -142,26 +142,27 @@ func submitCompactSnapshot(ctx context.Context, server *state.Server, collection if server.CompactLogTime.IsZero() { server.CompactLogTime = time.Now().Truncate(time.Minute) server.CompactLogStats = make(map[string]uint8) - } else if time.Now().Sub(server.CompactLogTime) > time.Minute { - var keys []string - for k := range server.CompactLogStats { - keys = append(keys, k) - } - sort.Strings(keys) - details := "" - for i, kind := range keys { - details += fmt.Sprintf("%d %s", server.CompactLogStats[kind], kind) - if i < len(keys)-1 { - details += ", " - } - } - if len(details) > 0 { - logger.PrintInfo("Compact snapshots submitted: " + details) - } - server.CompactLogTime = time.Now().Truncate(time.Minute) - server.CompactLogStats = make(map[string]uint8) } else { server.CompactLogStats[kind] = server.CompactLogStats[kind] + 1 + if time.Since(server.CompactLogTime) > time.Minute { + var keys []string + for k := range server.CompactLogStats { + keys = append(keys, k) + } + sort.Strings(keys) + details := "" + for i, kind := range keys { + details += fmt.Sprintf("%d %s", server.CompactLogStats[kind], kind) + if i < len(keys)-1 { + details += ", " + } + } + if len(details) > 0 { + logger.PrintInfo("Compact snapshots submitted: " + details) + } + server.CompactLogTime = time.Now().Truncate(time.Minute) + server.CompactLogStats = make(map[string]uint8) + } } }