Is there a way to iterate over the entire configuration via MAAPI or CDB APIs? To walk the entire structure? I’ve looked for iteration functions, but all I find is diff_iterate – iterating over a recent change. I would like to iterate over the entire contents of the CDB. Thanks.
int cdb_trigger_subscriptions(int sock, int sub_points, int len);
This function makes it possible to trigger CDB subscriptions for configuration data even though the configuration has not been modified. The caller will trigger all subscription points passed in the sub_points array (or all subscribers if the array is of zero length) in priority order, and the call will not return until the last subscriber has called cdb_sync_subscription_socket().
The call is blocking and doesn’t return until all subscribers have acknowledged the notification. That means that it is not possible to use cdb_trigger_subscriptions() in a cdb subscriber process (without forking a process or spawning a thread) since it would cause a deadlock.
The subscription notification generated by this “synthetic” trigger will seem like a regular subscription notification to a subscription client. As such, it is possible to use cdb_diff_iterate() to traverse the changeset. CDB will make up this changeset in which all leafs in the configuration will appear to be set, and all list entries and presence containers will appear as if they are created.
Thank you, I will try it. It sounds like this will cause all subscribers in all other processes to also receive the updates. I don’t want that, but I might be able to call this before any other subscribers are running.
int maapi_iterate(int sock, int thandle,
enum maapi_iter_ret (*iter)(confd_hkeypath_t *kp,
confd_value_t *v, confd_attr_value_t *attr_vals,
int num_attr_vals, void *state), int flags,
void *initstate, const char *fmtpath, ...);
This function can be used to iterate over all the data in a transaction
and the underlying data store, as opposed to iterating over only the
changes like maapi_diff_iterate() and maapi_keypath_diff_iterate() do.
This looks perfect, as I would prefer to use the maapi rather than cdb calls. I found it in the man page as well. It’s not clear, though, what they mean by “all the data in a transaction”. Do you know for certain that it will iterate over the entire database?
Yes, like the description says: “… and the underlying data store”. But, it should perhaps say “as modified by the transaction” or something like that. E.g. if you have deleted something in the transaction, it won’t show up in this iteration even though it still exists in the “underlying data store”, while if you have created something in the transaction, it will show up, etc. I.e. basically it shows what the result would be if the transaction was successfully committed - but if you run it with a transaction where you haven’t done any modifications, it will show precisely the “underlying data store”.
And just to be precise - “data store” does not in the general case mean “CDB”, but e.g. “running” (when the transaction was started towards CONFD_RUNNING). If parts or all of the data store is provided by external data providers, those parts will be included in the iteration. (This is true for all data access through transactions, of course.)