From a693a6c091bc5484ac706cc93256145df9740b24 Mon Sep 17 00:00:00 2001 From: Akmal Date: Fri, 8 Mar 2024 10:11:28 +0700 Subject: [PATCH] Use binary.Read to check if error when reading expire ts --- main.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 9153b12..f24bb47 100644 --- a/main.go +++ b/main.go @@ -78,7 +78,7 @@ func main() { // Initialize zerolog zerolog.TimeFieldFormat = zerolog.TimeFormatUnix - zerolog.SetGlobalLevel(zerolog.WarnLevel) + zerolog.SetGlobalLevel(zerolog.DebugLevel) // Parse grid-cache-size gridCacheSizeParsed, err := byteSizeStrToInt(*gridCacheSize) @@ -153,8 +153,16 @@ func evictCache() { batch := data.DB.NewBatch() curTime := uint64(time.Now().UnixNano()) for iter.First(); iter.Valid(); iter.Next() { - timestamp := bytes.Trim(iter.Key(), "exp-") - if binary.LittleEndian.Uint64(timestamp) < curTime { + expireTimestamp := bytes.Trim(iter.Key(), "exp-") + + var timestamp uint64 + err := binary.Read(bytes.NewBuffer(expireTimestamp[:]), binary.LittleEndian, ×tamp) + if err != nil { + log.Error().Err(err).Msg("Failed to read expire timestamp") + continue + } + + if timestamp < curTime { batch.Delete(iter.Key(), pebble.NoSync) batch.Delete(iter.Value(), pebble.NoSync) }