From c3d02ee75a169fe7f30d0407d8fda3854825c629 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 7 Feb 2022 23:41:08 +0200 Subject: [PATCH] vendor: update github.com/VictoriaMetrics/fastcache from v1.8.0 to v1.9.0 --- go.mod | 2 +- go.sum | 5 +-- .../VictoriaMetrics/fastcache/fastcache.go | 37 ++++++++++--------- .../VictoriaMetrics/fastcache/file.go | 4 +- .../VictoriaMetrics/fastcache/malloc_heap.go | 1 + .../VictoriaMetrics/fastcache/malloc_mmap.go | 1 + vendor/modules.txt | 2 +- 7 files changed, 29 insertions(+), 23 deletions(-) diff --git a/go.mod b/go.mod index 64c006711..83f0c68fc 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.17 require ( cloud.google.com/go/storage v1.20.0 - github.com/VictoriaMetrics/fastcache v1.8.0 + github.com/VictoriaMetrics/fastcache v1.9.0 // Do not use the original github.com/valyala/fasthttp because of issues // like https://github.com/valyala/fasthttp/commit/996610f021ff45fdc98c2ce7884d5fa4e7f9199b diff --git a/go.sum b/go.sum index e1750b8ca..48c2a0f88 100644 --- a/go.sum +++ b/go.sum @@ -110,8 +110,8 @@ github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdko github.com/SAP/go-hdb v0.14.1/go.mod h1:7fdQLVC2lER3urZLjZCm0AuMQfApof92n3aylBPEkMo= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= -github.com/VictoriaMetrics/fastcache v1.8.0 h1:ybZqS7kRy8YVzYsI09GLzQhs7iqS6cOEH2avtknD1SU= -github.com/VictoriaMetrics/fastcache v1.8.0/go.mod h1:n7Sl+ioh/HlWeYHLSIBIE8TcZFHg/+xgvomWSS5xuEE= +github.com/VictoriaMetrics/fastcache v1.9.0 h1:oMwsS6c8abz98B7ytAewQ7M1ZN/Im/iwKoE1euaFvhs= +github.com/VictoriaMetrics/fastcache v1.9.0/go.mod h1:otoTS3xu+6IzF/qByjqzjp3rTuzM3Qf0ScU1UTj97iU= github.com/VictoriaMetrics/fasthttp v1.1.0 h1:3crd4YWHsMwu60GUXRH6OstowiFvqrwS4a/ueoLdLL0= github.com/VictoriaMetrics/fasthttp v1.1.0/go.mod h1:/7DMcogqd+aaD3G3Hg5kFgoFwlR2uydjiWvoLp5ZTqQ= github.com/VictoriaMetrics/metrics v1.18.1 h1:OZ0+kTTto8oPfHnVAnTOoyl0XlRhRkoQrD2n2cOuRw0= @@ -1299,7 +1299,6 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210917161153-d61c044b1678/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/vendor/github.com/VictoriaMetrics/fastcache/fastcache.go b/vendor/github.com/VictoriaMetrics/fastcache/fastcache.go index 342b67d8d..daa3db773 100644 --- a/vendor/github.com/VictoriaMetrics/fastcache/fastcache.go +++ b/vendor/github.com/VictoriaMetrics/fastcache/fastcache.go @@ -271,20 +271,18 @@ func (b *bucket) Reset() { b.mu.Unlock() } -func (b *bucket) Clean() { - b.mu.Lock() +func (b *bucket) cleanLocked() { bGen := b.gen & ((1 << genSizeBits) - 1) bIdx := b.idx bm := b.m for k, v := range bm { gen := v >> bucketSizeBits idx := v & ((1 << bucketSizeBits) - 1) - if gen == bGen && idx < bIdx || gen+1 == bGen && idx >= bIdx || gen == maxGen && bGen == 1 && idx >= bIdx { + if (gen+1 == bGen || gen == maxGen && bGen == 1) && idx >= bIdx || gen == bGen && idx < bIdx { continue } delete(bm, k) } - b.mu.Unlock() } func (b *bucket) UpdateStats(s *Stats) { @@ -296,19 +294,17 @@ func (b *bucket) UpdateStats(s *Stats) { b.mu.RLock() s.EntriesCount += uint64(len(b.m)) + bytesSize := uint64(0) for _, chunk := range b.chunks { - s.BytesSize += uint64(cap(chunk)) + bytesSize += uint64(cap(chunk)) } - s.MaxBytesSize += uint64(len(b.chunks))*chunkSize + s.BytesSize += bytesSize + s.MaxBytesSize += uint64(len(b.chunks)) * chunkSize b.mu.RUnlock() } func (b *bucket) Set(k, v []byte, h uint64) { - setCalls := atomic.AddUint64(&b.setCalls, 1) - if setCalls%(1<<14) == 0 { - b.Clean() - } - + atomic.AddUint64(&b.setCalls, 1) if len(k) >= (1<<16) || len(v) >= (1<<16) { // Too big key or value - its length cannot be encoded // with 2 bytes (see below). Skip the entry. @@ -326,13 +322,15 @@ func (b *bucket) Set(k, v []byte, h uint64) { return } + chunks := b.chunks + needClean := false b.mu.Lock() idx := b.idx idxNew := idx + kvLen chunkIdx := idx / chunkSize chunkIdxNew := idxNew / chunkSize if chunkIdxNew > chunkIdx { - if chunkIdxNew >= uint64(len(b.chunks)) { + if chunkIdxNew >= uint64(len(chunks)) { idx = 0 idxNew = kvLen chunkIdx = 0 @@ -340,14 +338,15 @@ func (b *bucket) Set(k, v []byte, h uint64) { if b.gen&((1<= b.idx || gen == maxGen && bGen == 1 && idx >= b.idx { chunkIdx := idx / chunkSize - if chunkIdx >= uint64(len(b.chunks)) { + if chunkIdx >= uint64(len(chunks)) { // Corrupted data during the load from file. Just skip it. atomic.AddUint64(&b.corruptions, 1) goto end } - chunk := b.chunks[chunkIdx] + chunk := chunks[chunkIdx] idx %= chunkSize if idx+4 >= chunkSize { // Corrupted data during the load from file. Just skip it. diff --git a/vendor/github.com/VictoriaMetrics/fastcache/file.go b/vendor/github.com/VictoriaMetrics/fastcache/file.go index bab5484e8..dfbc0701d 100644 --- a/vendor/github.com/VictoriaMetrics/fastcache/file.go +++ b/vendor/github.com/VictoriaMetrics/fastcache/file.go @@ -272,7 +272,9 @@ func loadBuckets(buckets []bucket, dataPath string, maxChunks uint64) error { } func (b *bucket) Save(w io.Writer) error { - b.Clean() + b.mu.Lock() + b.cleanLocked() + b.mu.Unlock() b.mu.RLock() defer b.mu.RUnlock() diff --git a/vendor/github.com/VictoriaMetrics/fastcache/malloc_heap.go b/vendor/github.com/VictoriaMetrics/fastcache/malloc_heap.go index 79a71832a..810d460b7 100644 --- a/vendor/github.com/VictoriaMetrics/fastcache/malloc_heap.go +++ b/vendor/github.com/VictoriaMetrics/fastcache/malloc_heap.go @@ -1,3 +1,4 @@ +//go:build appengine || windows // +build appengine windows package fastcache diff --git a/vendor/github.com/VictoriaMetrics/fastcache/malloc_mmap.go b/vendor/github.com/VictoriaMetrics/fastcache/malloc_mmap.go index e0cd0e761..e24d578bf 100644 --- a/vendor/github.com/VictoriaMetrics/fastcache/malloc_mmap.go +++ b/vendor/github.com/VictoriaMetrics/fastcache/malloc_mmap.go @@ -1,3 +1,4 @@ +//go:build !appengine && !windows // +build !appengine,!windows package fastcache diff --git a/vendor/modules.txt b/vendor/modules.txt index bf53fe0de..8aef6b48f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -15,7 +15,7 @@ cloud.google.com/go/iam ## explicit; go 1.11 cloud.google.com/go/storage cloud.google.com/go/storage/internal/apiv2 -# github.com/VictoriaMetrics/fastcache v1.8.0 +# github.com/VictoriaMetrics/fastcache v1.9.0 ## explicit; go 1.13 github.com/VictoriaMetrics/fastcache # github.com/VictoriaMetrics/fasthttp v1.1.0