Find_next() being called twice with same kp and type {same_or_next}

Hi,

I tried the examples in dp/find_next.
When get the ports by CLI, find_next() callback is called twice. Why is that? What’s the different between them?

CLI command:

show port 4 *

SLOT PORT STATUS

4 0 error
4 2 disabled

callbacks log:

TRACE New user session: 14 for user:admin ctx:cli → CONFD_OK
TRACE CALL trans init(thandle=12,mode=“r”,db=running) → CONFD_OK
TRACE CALL data find_next(thandle=12, /port, same_or_next, {4}) → CONFD_OK
TRACE CALL data find_next(thandle=12, /port, same_or_next, {4}) → CONFD_OK
TRACE CALL data get_elem(thandle=12,/port{4 0}/status) (enum<2>) → CONFD_OK
TRACE CALL data get_next(thandle=12, /port, 6) → CONFD_OK
TRACE CALL data get_elem(thandle=12,/port{4 2}/status) (enum<0>) → CONFD_OK
TRACE CALL data get_next(thandle=12, /port, 7) → CONFD_OK
TRACE NULL trans finish(thandle=12)
TRACE Close user sess 14
→ CONFD_OK

When use netconf command, find_next() callback is called once, as below:

netconf-console --get -x ‘/port[slot=4]/status’

callbacks log:

TRACE New user session: 17 for user:admin ctx:netconf → CONFD_OK
TRACE CALL trans init(thandle=14,mode=“r”,db=running) → CONFD_OK
TRACE CALL data find_next(thandle=14, /port, same_or_next, {4}) → CONFD_OK
TRACE CALL data get_next(thandle=14, /port, 6) → CONFD_OK
TRACE CALL data get_next(thandle=14, /port, 7) → CONFD_OK
TRACE CALL data get_elem(thandle=14,/port{4 0}/status) (enum<2>) → CONFD_OK
TRACE CALL data get_elem(thandle=14,/port{4 2}/status) (enum<0>) → CONFD_OK
TRACE NULL trans finish(thandle=14)
TRACE Close user sess 17
→ CONFD_OK

Thanks!

Hi,

The CLI is a human-to-machine interface so ConfD must fetch things like tab-complete, table look-ahead, etc. data.

Hi,

If so, how to reply to these find_next() callbacks? Especially when the list with lots of items and performance need to be considered. Is there a general way to handle this?

If performance is of concern, I suggest you focus on the get_elem()/get_next() calls that occur for each list entry, and not the first two find_next() (that will not be called for each list entry) when you show the data from the CLI.

To avoid get_elem()/get_next() calls for each list entry you can also implement find_next_object(). In addition, find_next_object() will be the only callback called and will only be called once for the use case you describe here. See https://github.com/ConfD-Developer/ConfD-Demos/tree/master/dp-performance for a demo.

Hi,

I did some test on find_next_object() callbacks. it’s same as find_next(), being called twice. In my code, confd_data_reply_next_object_tag_value_arrays() is used to reply each find_next_object() callback including all list items and an end-of-list indication. These two callbacks contains different traversal_id.

Is it correct?

Yes, they will be called twice.
However, there will be no get_elem()/get_next() calls if you skip registering them as the demo I pointed you to show.
There is no need for keeping track of any traversal id if you skip get_next() and register find_next() + find_next_object() only as the demo show as well.