mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/encoding/zstd: switch back from atomic.Pointer to atomic.Value for map[...]...
The map[...]... is already a pointer type, so atomic.Pointer[map[...]...] results in double pointer.
This is a follow-up for 140e7b6b74
This commit is contained in:
parent
c94a5d95a2
commit
dcf5b42670
2 changed files with 10 additions and 8 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue