Skip to content

Commit

Permalink
Revert ":bug: Fix internal/gache definition variable type (#2123)"
Browse files Browse the repository at this point in the history
This reverts commit b92e4bc.
  • Loading branch information
ykadowak committed Nov 30, 2023
1 parent ff917f6 commit 6b0333f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion internal/sync/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
18 changes: 9 additions & 9 deletions pkg/agent/core/ngt/service/vqueue/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions pkg/discoverer/k8s/service/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6b0333f

Please sign in to comment.