diff --git a/lib/encoding/zstd/zstd_pure.go b/lib/encoding/zstd/zstd_pure.go index 5336337e3..a6aa98056 100644 --- a/lib/encoding/zstd/zstd_pure.go +++ b/lib/encoding/zstd/zstd_pure.go @@ -15,13 +15,13 @@ var ( decoder *zstd.Decoder mu sync.Mutex - av atomic.Pointer[registry] + + // do not use atomic.Pointer, since the stored map there is already a pointer type. + av atomic.Value ) -type registry map[int]*zstd.Encoder - func init() { - r := make(registry) + r := make(map[int]*zstd.Encoder) av.Store(r) var err error @@ -45,7 +45,7 @@ func CompressLevel(dst, src []byte, compressionLevel int) []byte { } func getEncoder(compressionLevel int) *zstd.Encoder { - r := av.Load() + r := av.Load().(map[int]*zstd.Encoder) e := r[compressionLevel] if e != nil { return e @@ -54,10 +54,10 @@ func getEncoder(compressionLevel int) *zstd.Encoder { mu.Lock() // Create the encoder under lock in order to prevent from wasted work // when concurrent goroutines create encoder for the same compressionLevel. - r1 := av.Load() + r1 := av.Load().(map[int]*zstd.Encoder) if e = r1[compressionLevel]; e == nil { e = newEncoder(compressionLevel) - r2 := make(registry) + r2 := make(map[int]*zstd.Encoder) for k, v := range r1 { r2[k] = v } diff --git a/lib/tenantmetrics/counter_map.go b/lib/tenantmetrics/counter_map.go index 3ab106679..cc47c423c 100644 --- a/lib/tenantmetrics/counter_map.go +++ b/lib/tenantmetrics/counter_map.go @@ -18,7 +18,9 @@ type TenantID struct { // CounterMap is a map of counters keyed by tenant. type CounterMap struct { metric string - m atomic.Value + + // do not use atomic.Pointer, since the stored map there is already a pointer type. + m atomic.Value } // NewCounterMap creates new CounterMap for the given metric.