# Transaction hooks missing 'modify' data callback so better off using maapi\_diff\_iterate only?

**URL:** <https://dmap-community.ductus.global/t/transaction-hooks-missing-modify-data-callback-so-better-off-using-maapi-diff-iterate-only/2999>\
**Category:** CDB and CDB API\
**Created:** [March 30, 2020, 11:36am UTC](https://dmap-community.ductus.global/t/transaction-hooks-missing-modify-data-callback-so-better-off-using-maapi-diff-iterate-only/2999 "2020-03-30T11:36:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![f.barczyk](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/f.barczyk/32/222_2.png) [@f.barczyk](https://dmap-community.ductus.global/u/f.barczyk)\
**Post date:** [March 30, 2020, 11:36am UTC](https://dmap-community.ductus.global/t/transaction-hooks-missing-modify-data-callback-so-better-off-using-maapi-diff-iterate-only/2999/1 "2020-03-30T11:36:00Z")

</div>

Hello,  
based on documentation I think the regular approach to adding transaction hooks is to:  
1/ add transaction hook entries in YANG  
2/ start daemon who will do following:  
2.1/ register transaction callbacks (init, finish) in order to connect and attach to transaction and eventual do cleaning up  
2.2/ register data callbacks (create, remove, set\_elem).

It works if you accept one hindrance: there’s no ‘modify’ callback ?!?

Now this is strange, because if you do maapi\_diff\_iterate in your init callback then you are getting ‘modify’ operations.

And sometimes modify is what you need because you need to take one action based on overall change in parent (all children) not individual children. It’s awkward to implement the action if you get set\_elem, create or remove on each child separately…

This makes me wonder:  
A/ is it possible to somehow get this ‘modify’ callback?  
or  
B/ maybe init and finish is all I need to implement hooks by myself (without adding callpoints in YANG and no data callbacks):  
B1/ Just keep list of keypaths I’m interested in and use it with maapi\_diff\_iterate or maapi\_keypath\_iterate to filter them out in ‘init’ callback.  
B2/ I get ‘init’ callback’ for any transaction anyway, right?  
B3/ No need to modify/deploy changes in YANG if you need to add another hook, just application needs to be rebuilt and deployed.  
B4/ Or is it going to be too slow compared to regular approach because of all that maapi\_diff\_iterate on each transaction (suppose my app may add hooks anywhere in the YANG in future) ?

or C/ use hybrid approach, that is use regular callpoints for create, remove and set\_elem operations and maapi\_diff\_iterate for the ‘modify’ operations? That seems like the most efficient way?

---

<div class="post-metadata">

**Author:** ![cohult](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/cohult/32/221_2.png) [@cohult](https://dmap-community.ductus.global/u/cohult)\
**Post date:** [March 30, 2020, 11:40am UTC](https://dmap-community.ductus.global/t/transaction-hooks-missing-modify-data-callback-so-better-off-using-maapi-diff-iterate-only/2999/2 "2020-03-30T11:40:42Z")

</div>

Instead, see the confd\_lib\_dp(3) man page and the “write\_all()” callback that will be invoked once for a transaction hook specified with tailf:invocation- mode per-transaction. It is the only callback that should be registered for such a hook.  
See also the chapter Transformations, Hooks, Hidden Data and Symlinks in the User Guide.

---

<div class="post-metadata">

**Author:** ![f.barczyk](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/f.barczyk/32/222_2.png) [@f.barczyk](https://dmap-community.ductus.global/u/f.barczyk)\
**Post date:** [March 30, 2020, 12:27pm UTC](https://dmap-community.ductus.global/t/transaction-hooks-missing-modify-data-callback-so-better-off-using-maapi-diff-iterate-only/2999/3 "2020-03-30T12:27:38Z")

</div>

thank you @cohult, but according to the user’s guide:

> The kp parameter is currently always NULL, since the callback does not pertain to any particular data node.

So suppose I have several ‘per-transaction’ callbacks defined and all of the nodes are modified in the transaction.

How many times write\_all will be called? Once for whole transaction or once per node?

How to tell which node was modified in ‘write\_all’ callback other than calling maapi\_diff\_iterate?

Doesn’t this beats the purpose for me?

---

<div class="post-metadata">

**Author:** ![f.barczyk](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/f.barczyk/32/222_2.png) [@f.barczyk](https://dmap-community.ductus.global/u/f.barczyk)\
**Post date:** [March 30, 2020, 4:58pm UTC](https://dmap-community.ductus.global/t/transaction-hooks-missing-modify-data-callback-so-better-off-using-maapi-diff-iterate-only/2999/4 "2020-03-30T16:58:15Z")

</div>

Ok, this seems to work:  
1/ because p\_kp is NULL for write\_all callback we must use unique callpoint names for each per-transaction hook (=\> path, can’t reuse callpoint names as for other callpoints).  
2/ when registering data callbacks we use different write\_all callback functions (not scalable) or better we set cb\_opaque to different unique identifiers which will enable single write\_all callback function to tell which callpoint is it (same thing we do anyway for other types of hooks where p\_kp may be ambiguous).  
3/ we get single write\_all callback no matter how many instances were modified but we are able to tell which callpoint is it by cb\_opaque we set in step 2/ or based on which function of ours was invoked. We use this to determine path.  
4/ we don’t know keys for each of the instance modified so we do maapi\_keypath\_diff\_iterate(path) to find out actual keypaths and we’re good!

Thank you @cohult for directions! I only wished that ‘modify’ was available in addition to ‘create’, ‘remove’ and ‘set\_elem’ to use with a regular transaction hook…
