diff --git a/internal/sync/map.go b/internal/sync/map.go index 3dc69a8dc8..38093a8597 100644 --- a/internal/sync/map.go +++ b/internal/sync/map.go @@ -15,6 +15,6 @@ package sync import gache "github.com/kpango/gache/v2" -type Map[K, V comparable] struct { +type Map[K comparable, V any] struct { gache.Map[K, V] } diff --git a/pkg/agent/core/ngt/service/vqueue/queue.go b/pkg/agent/core/ngt/service/vqueue/queue.go index a63fcd1f2e..bc724529a4 100644 --- a/pkg/agent/core/ngt/service/vqueue/queue.go +++ b/pkg/agent/core/ngt/service/vqueue/queue.go @@ -43,7 +43,7 @@ type Queue interface { } type vqueue struct { - il, dl valdsync.Map[string, *index] + il, dl valdsync.Map[string, index] ic, dc uint64 } @@ -83,10 +83,10 @@ func (v *vqueue) PushInsert(uuid string, vector []float32, date int64) error { vector: vector, date: date, } - oidx, loaded := v.il.LoadOrStore(uuid, &idx) + oidx, loaded := v.il.LoadOrStore(uuid, idx) if loaded { if date > oidx.date { // if data already exists and existing index is older than new one - v.il.Store(uuid, &idx) + v.il.Store(uuid, idx) } } else { _ = atomic.AddUint64(&v.ic, 1) @@ -102,10 +102,10 @@ func (v *vqueue) PushDelete(uuid string, date int64) error { uuid: uuid, date: date, } - oidx, loaded := v.dl.LoadOrStore(uuid, &idx) + oidx, loaded := v.dl.LoadOrStore(uuid, idx) if loaded { if date > oidx.date { // if data already exists and existing index is older than new one - v.dl.Store(uuid, &idx) + v.dl.Store(uuid, idx) } } else { _ = atomic.AddUint64(&v.dc, 1) @@ -173,7 +173,7 @@ func (v *vqueue) DVExists(uuid string) bool { func (v *vqueue) RangePopInsert(ctx context.Context, now int64, f func(uuid string, vector []float32, date int64) bool) { uii := make([]index, 0, atomic.LoadUint64(&v.ic)) - v.il.Range(func(uuid string, idx *index) bool { + v.il.Range(func(uuid string, idx index) bool { if idx.date > now { return true } @@ -185,7 +185,7 @@ func (v *vqueue) RangePopInsert(ctx context.Context, now int64, f func(uuid stri } return true } - uii = append(uii, *idx) + uii = append(uii, idx) select { case <-ctx.Done(): return false @@ -213,11 +213,11 @@ func (v *vqueue) RangePopInsert(ctx context.Context, now int64, f func(uuid stri func (v *vqueue) RangePopDelete(ctx context.Context, now int64, f func(uuid string) bool) { udi := make([]index, 0, atomic.LoadUint64(&v.dc)) - v.dl.Range(func(_ string, idx *index) bool { + v.dl.Range(func(uuid string, idx index) bool { if idx.date > now { return true } - udi = append(udi, *idx) + udi = append(udi, idx) select { case <-ctx.Done(): return false diff --git a/pkg/discoverer/k8s/service/discover.go b/pkg/discoverer/k8s/service/discover.go index c6450f5e4a..c98931ee6f 100644 --- a/pkg/discoverer/k8s/service/discover.go +++ b/pkg/discoverer/k8s/service/discover.go @@ -50,7 +50,7 @@ type discoverer struct { maxPods int nodes valdsync.Map[string, *node.Node] nodeMetrics valdsync.Map[string, mnode.Node] - pods valdsync.Map[string, *[]pod.Pod] + pods valdsync.Map[string, []pod.Pod] podMetrics valdsync.Map[string, mpod.Pod] podsByNode atomic.Value podsByNamespace atomic.Value @@ -134,9 +134,9 @@ func New(selector *config.Selectors, opts ...Option) (dsc Discoverer, err error) if len(pods) > d.maxPods { d.maxPods = len(pods) } - d.pods.Store(name, &pods) + d.pods.Store(name, pods) } - d.pods.Range(func(name string, _ *[]pod.Pod) bool { + d.pods.Range(func(name string, _ []pod.Pod) bool { _, ok := podList[name] if !ok { d.pods.Delete(name) @@ -232,12 +232,12 @@ func (d *discoverer) Start(ctx context.Context) (<-chan error, error) { return true } }) - d.pods.Range(func(appName string, pods *[]pod.Pod) bool { + d.pods.Range(func(appName string, pods []pod.Pod) bool { select { case <-ctx.Done(): return false default: - for _, p := range *pods { + for _, p := range pods { select { case <-ctx.Done(): return false @@ -271,23 +271,23 @@ func (d *discoverer) Start(ctx context.Context) (<-chan error, error) { } _, ok = podsByNode[p.NodeName][p.Namespace] if !ok { - podsByNode[p.NodeName][p.Namespace] = make(map[string][]*payload.Info_Pod, len(*pods)) + podsByNode[p.NodeName][p.Namespace] = make(map[string][]*payload.Info_Pod, len(pods)) } _, ok = podsByNamespace[p.Namespace] if !ok { - podsByNamespace[p.Namespace] = make(map[string][]*payload.Info_Pod, len(*pods)) + podsByNamespace[p.Namespace] = make(map[string][]*payload.Info_Pod, len(pods)) } _, ok = podsByNode[p.NodeName][p.Namespace][appName] if !ok { - podsByNode[p.NodeName][p.Namespace][appName] = make([]*payload.Info_Pod, 0, len(*pods)) + podsByNode[p.NodeName][p.Namespace][appName] = make([]*payload.Info_Pod, 0, len(pods)) } _, ok = podsByNamespace[p.Namespace][appName] if !ok { - podsByNamespace[p.Namespace][appName] = make([]*payload.Info_Pod, 0, len(*pods)) + podsByNamespace[p.Namespace][appName] = make([]*payload.Info_Pod, 0, len(pods)) } _, ok = podsByName[appName] if !ok { - podsByName[appName] = make([]*payload.Info_Pod, 0, len(*pods)) + podsByName[appName] = make([]*payload.Info_Pod, 0, len(pods)) } podsByNode[p.NodeName][p.Namespace][appName] = append(podsByNode[p.NodeName][p.Namespace][appName], pi) podsByNamespace[p.Namespace][appName] = append(podsByNamespace[p.Namespace][appName], pi)