How to reject changes when using CDB

Chapter 5 (CDB) of the ConfD User Guide says the following:

Note that even though the notifications are delivered within the transaction it is not possible for a subscriber to reject the changes (since this would break the two-phase commit protocol used by the ConfD backplane towards all data-providers).

The problem is that errors might happen when trying to apply a configuration change, especially when trying to allocate resources (e.g. sockets). In these cases the configuration changes must be rejected instead of ignoring the errors silently. Is it possible to do that when using CDB?

It seems to me that, when using the external database API, it’s possible to use the prepare transaction callback to allocate resources and check for errors. But I believe it’s not possible to register transaction callbacks and subscribe to CDB in the same program.

One other possibility I thought about is to confd_register_valpoint_cb() to perform error checking, but apparently the purpose of this API is to do semantic validation of the data.

I’m kind of lost here on how to handle resource allocation errors. I’d appreciate if someone could shed some light on what to do.

Regards,
Renato.

It seems like cdb_subscribe2() with the CDB_SUB_RUNNING_TWOPHASE flag is exactly what I’m looking for. I’ll try this here.

Yes If you want the CDB subscriber to cause a transaction to fail because of some error, for example there aren’t enough resources for the configuration change to take effect, then the you will need to use a two-phase CDB subscriber. For simple CDB subscribers, the subscriber is notified during commit time, at which point it is too late to cause the transaction to fail. With the two-phase subscriber, the application is notified during the prepare phase, when it is possible to cause the transaction to fail, as well as during the commit phase. There is an example of this $CONFD_DIR/examples.confd/cdb_subscription/twophase.

1 Like

Thanks @cohult, the two-phase subscriber indeed solved my problem. The example you pointed out was very useful to see how to use this API. Thanks again!