Use cdb_set_object to set a leaf in a container

Hi, I am using some autogen code above cdb APIs which currently supports only cdb_set_elem, when i subscribe for list with container having N leafs, i get N notifications.

I want to replace cdb_set_element with cdb_set_object, but now the question is, for some lists i need to update individual leafs.
can i update individual leafs using cdb_set_object?

Hi,

To set arbitrary (sub)elements of a container or list-entry you can use cdb_set_values. The omitted elements will remain unchanged.
If I understood your use case correctly, I would also look into an alternative way in which the generated code performs commits after some batch of cdb_set_elem calls.

Regards,
Erdem

Hi,

@harminder, I would use either the CDB API cdb_set_values() as a single operation for changes so that the CDB operational subscriber is invoked just once (or at least a minimum number of times), or even better, as @eaksu hints, use MAAPI towards the operational datastore where there can be multiple operations but the CDB operational subscriber will not be invoked until maapi_apply_trans() (commit) is called by the application. I would still use maapi_set_values() instead of set_elem() or set_object() operations as set_values() is more efficient.

See examples.confd/intro/13-c_stats_push for a simple maapi_set_values() to the operational datastore example. cdb_set_values() work the same way. See the confd_lib_cdb(3) and confd_lib_maapi(3) man pages for details.

The ConfD Developer GitHub also has a couple of examples:

2 Likes

Thanks for the help. i am using maapi apis now.