# Candidate DB subscription

**URL:** <https://dmap-community.ductus.global/t/candidate-db-subscription/4672>\
**Category:** CDB and CDB API\
**Created:** [April 3, 2024, 3:56pm UTC](https://dmap-community.ductus.global/t/candidate-db-subscription/4672 "2024-04-03T15:56:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kamala.V](https://avatars.discourse-cdn.com/v4/letter/k/e56c9b/32.png) [@Kamala.V](https://dmap-community.ductus.global/u/Kamala.V)\
**Post date:** [April 3, 2024, 3:56pm UTC](https://dmap-community.ductus.global/t/candidate-db-subscription/4672/1 "2024-04-03T15:56:49Z")

</div>

Hello all, I need some clarification on reading data from candidate DB.  
My requirement is as below, currently i have enabled candidate DB with confd implimentation , and running DB as writtable through candidate.

Now from application side i need to subscribe to candidate dB and whenever any edit config operation got performed on candidate , need to read the data (xpath and values) , similar way cdb\_subscribe got triggered for edit config on running DB.

Is there any Direct confd API similar to cdb\_subscribe to subscribe into candidate DB?  
Two phase validation will help here? as per my understanding two phase validation is for running DB, or is it possible for candidate DB? went through example available on confd, but getting confused as here some callbacks are getting registered. is this really need this way to serve my requirement?  
Kindly help me with the information and also if any example code kindly refer

Thanks

---

<div class="post-metadata">

**Author:** ![mnovak](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/mnovak/32/183_2.png) [@mnovak](https://dmap-community.ductus.global/u/mnovak)\
**Post date:** [April 4, 2024, 5:36am UTC](https://dmap-community.ductus.global/t/candidate-db-subscription/4672/2 "2024-04-04T05:36:25Z")

</div>

Hi Kamala,

perhaps you can try maapi\_diff\_iterate. One option may be to create validation point on top of your datamodel you want to iterate and call maapi\_diff\_iterate from validation callback.

Br,

Michal

---

<div class="post-metadata">

**Author:** ![Kamala.V](https://avatars.discourse-cdn.com/v4/letter/k/e56c9b/32.png) [@Kamala.V](https://dmap-community.ductus.global/u/Kamala.V)\
**Post date:** [April 5, 2024, 7:02am UTC](https://dmap-community.ductus.global/t/candidate-db-subscription/4672/3 "2024-04-05T07:02:11Z")

</div>

Hi @mnovak , Thanks for the reply,

below are my queries  
1.If we use the validation point on top of data model, whenever edit config happened in candidate DB ,the validation callpoint will get invoked or only upon committing to running DB?  
2. maapi\_diff\_iterate will iterate through all the paths under datamodel path where validation point been added right not only the edited paths, but need to fetch only xpaths which been modified via edit config similar to cdb\_diff\_iterate, is this possible with maapi\_diff\_iterate?

Thanks  
kamala

---

<div class="post-metadata">

**Author:** ![mnovak](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/mnovak/32/183_2.png) [@mnovak](https://dmap-community.ductus.global/u/mnovak)\
**Post date:** [April 12, 2024, 9:13am UTC](https://dmap-community.ductus.global/t/candidate-db-subscription/4672/4 "2024-04-12T09:13:50Z")

</div>

Hi @Kamala.V ,

1. The validation point is part of transaction processing and with candidate it is invoked when commit starts. You can test it on small example.

2. `maapi_diff_iterate` is not related to validation point, it will iterate over all changed (diff) paths.  
But you can invoke `maapi_diff_iterate` from validation point. This can be used if you want to check (or sort) changed configuration before transaction goes to commit phase.

Looking at your original question, maybe you can use also two phase subscription. See documentation to `cdb_subscribe2`. With two phase subscription you can still abort transaction in PREPARE phase, if something goes wrong. (Even though it is not primarily intended for validation I guess).

Michal

---

<div class="post-metadata">

**Author:** ![Kamala.V](https://avatars.discourse-cdn.com/v4/letter/k/e56c9b/32.png) [@Kamala.V](https://dmap-community.ductus.global/u/Kamala.V)\
**Post date:** [April 12, 2024, 9:31am UTC](https://dmap-community.ductus.global/t/candidate-db-subscription/4672/5 "2024-04-12T09:31:35Z")

</div>

got it, Thanks @mnovak .  
yes two phase subscription will serve my requirement.will check on it more.

one small query i have on two phase subscription is,  
using netconf console interface performing  
lock DB, edit-config and then unlock,  
then using any cdb/maapi api can trigger commit operation? this is possible right?

or we need to follow lock,edit-config.commit and unlock always?

---

<div class="post-metadata">

**Author:** ![mnovak](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/mnovak/32/183_2.png) [@mnovak](https://dmap-community.ductus.global/u/mnovak)\
**Post date:** [April 12, 2024, 10:56am UTC](https://dmap-community.ductus.global/t/candidate-db-subscription/4672/6 "2024-04-12T10:56:42Z")

</div>

Hi,

With two phase subscription, I suggest you do all validation and work in the PREPARE phase.  
In the COMMIT phase you just do nothing. If you get ABORT flag, then you have to be prepared to revert everything you did in PREPARE phase (e.g. configuration of devices). But if you use ti just for validation, then probably nothing is needed. Also note, the ABORT receives only subscriber that successfully performed PREPARE phase.

Here is sequence diagram for two phase subscription and multiple subscribers.

 ![subscriber_seq_two_phase](https://canada1.discourse-cdn.com/flex010/uploads/ductus_dmap/original/1X/dcbfe84ce65647d292055d6f0ab81632c04e7af7.png)

You cannot perform commit operation with CDB API. You can do it with maapi, but I guess you need to be in the same transaction and you will not have transaction ID from netconf console. My guess is it will not work for sure for CLI, but I’m not sure when you edit candidate with NETCONF. Please, try.
