Closed fahadnaeemkhan closed 1 year ago
While your description of how the oc_cache works is correct, the subscription does not fail in case data does not exist in the cache. The subscribe function fails in these cases:
The only error that could count as a cache miss here is the 3rd one (The specified target does not exist in one of the subscriptions caches). All the other errors should result in a failure of the subscription.
The case of missing target for one of the subscription scaches can be solved by calling cache.HasTarget()
before running the query.
Let me know if you want to give this a shot in a PR.
Yeah I was trying to refer to case 3.
Sure, would love to submit a PR for this.
PR submitted: https://github.com/openconfig/gnmic/pull/288
oc_cache
stores data per subscriptions so targets can be spread across multiple subscriptions (depending on configuration) and when we try to subscribes, it looks for match in all the subscriptions and create one goroutine per subscription for finding/query:https://github.com/openconfig/gnmic/blob/e1e58b86eb33f50038c2393a260cbbfa666b3099/pkg/cache/oc_cache.go#L186
Issue here is that these query goroutines sends errors to channel which
gnmi_server
is reading from and incase of cache miss from any of the goroutines, error is send tognmi_server
which returns immediately after seeing error even though data might me present under another subscription. https://github.com/openconfig/gnmic/blob/e1e58b86eb33f50038c2393a260cbbfa666b3099/pkg/app/gnmi_server.go#L683There are multiple solutions here:
gnmi_server
is reading from. We can have a separate channel b/wsubscription
goroutine and the query goroutines for errors. Subscription goroutine can collect all the errors and from here we could send error tognmi_server
after going through all the errors.cache_hit
b/w all the query go routines and if any of the goroutines finds the data, they can set the flag to true. Once all the query go routines are done, check the flag, if its unset then sends the error on the channel tognmi_server
. We can use https://pkg.go.dev/sync#Once for setting the flag.gnmi_server
, this will allow other query goroutines to send the notifications if availableLet me know if this is making sense or more info is needed