ConfD User Community

How should i design rollback mechanism

Hello Folks,

U know that, when client set a value over the netconf, after some validation confd immediatly save the value into the its database. but i want to save the same data to another database or apply another app. If i couldn’t save or apply the data, how can i rollback them? as an another things, i should save or apply in validation callback?

Many thanks,
With My Best Regards,
Onur.

One way (probably the best option) is to set the data to the other database in the prepare phase from where you can still abort the transaction. I.e. you subscribe to the configuration changes using a “two-phase subscriber”.

A two-phase subscriber subscribes and is notified of configuration changes in both the prepare and commit phase of the transaction that set the configuration to CDB. If the transaction is aborted by the subscriber (or the client) in the prepare phase, the configuration changes are undone automatically by ConfD.

See examples.confd/cdb_subscription/twophase for an example of a two-phase subscriber application.

1 Like

Hmmm i like this functionality, it seems very cool. I have never seen before this example. I’ll try this.

Many thanks in advance.
With My Best Regards,

Hello @cohult

Nowadays, I’m working on it.
I have two question.

First → What is the correct order?
Prephase callback → validation callback → subscriber callbak ?
If i register a callback into the prephase as a two phase subsrier and then i register a callback into the validation state, what will be calling order ?

Second →
I couldn’t very well get two phase app. I just want to check at prephase, so that i should just implement CDB_SUB_PREPARE case, do i need to impelement other case, can i leave it as a default?

Last but not least,
Do u know that, what is the timeout during the prephase. Because i want to rest call another service at prephase, so it may take a long time. how can i handle that situatuan?

With My Best Regards,
Many Thanks