Skip to content

Commit

Permalink
Merge pull request #288 from fahadnaeemkhan/gnmi_server_cache_miss
Browse files Browse the repository at this point in the history
fixed: target not in cache to stop subscription
  • Loading branch information
karimra authored Nov 11, 2023
2 parents cf389f6 + c5874f8 commit b2f2ba9
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions pkg/cache/oc_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ package cache

import (
"context"
"fmt"
"io"
"log"
"strings"
Expand All @@ -29,7 +28,7 @@ import (
)

const (
loggingPrefixOC = "[cache:%s] "
loggingPrefixOC = "[cache:oc] "
defaultTimeout = 10 * time.Second
)

Expand Down Expand Up @@ -73,7 +72,7 @@ func newGNMICache(cfg *Config, loggingPrefix string, opts ...Option) *gnmiCache
if loggingPrefix == "" {
loggingPrefix = "oc"
}
gc.logger.SetPrefix(fmt.Sprintf(loggingPrefixOC, loggingPrefix))
gc.logger.SetPrefix(loggingPrefixOC)
}
return gc
}
Expand Down Expand Up @@ -199,6 +198,12 @@ func (gc *gnmiCache) handleSingleQuery(ctx context.Context, ro *ReadOpts, ch cha
for name, c := range caches {
go func(name string, c *subCache) {
defer wg.Done()
if !c.c.HasTarget(ro.Target) {
if gc.debug {
gc.logger.Printf("subscription-cache %q doesn't have target: %q", name, ro.Target)
}
return
}
for _, p := range ro.Paths {
fp, err := path.CompletePath(p, nil)
if err != nil {
Expand Down Expand Up @@ -306,6 +311,12 @@ func (gc *gnmiCache) handleOnChangeQuery(ctx context.Context, ro *ReadOpts, ch c
for name, c := range caches {
go func(name string, c *subCache) {
defer wg.Done()
if !c.c.HasTarget(ro.Target) {
if gc.debug {
gc.logger.Printf("subscription-cache %q doesn't have target: %q", name, ro.Target)
}
return
}
for _, p := range ro.Paths {
// handle updates only
if !ro.UpdatesOnly {
Expand Down

0 comments on commit b2f2ba9

Please sign in to comment.