Skip to content

Commit

Permalink
add commit failed cb (#550)
Browse files Browse the repository at this point in the history
* add revert failed cb

* add revert failed cb

* add commit failed cb

* add commit failed cb
  • Loading branch information
EvgeniiVR authored and krihal committed Sep 23, 2024
1 parent bc97734 commit a8e5f4d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions apps/backend/backend_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,20 @@ plugin_transaction_revert_all(clixon_handle h,
return retval; /* ignore errors */
}

/*! Revert a commit for failed plugin
* The commit failed is called for only failed plugin before revert all cb.
*/
static int
plugin_transaction_commit_failed(clixon_plugin_t *cp,
clixon_handle h,
transaction_data_t *td)
{
trans_cb_t *fn;

if ((fn = clixon_plugin_api_get(cp)->ca_trans_commit_failed) != NULL)
return plugin_transaction_call_one(h, cp, fn, __FUNCTION__, td);
return 0;
}

/*! Call single plugin transaction_commit() in a commit transaction
*
Expand Down Expand Up @@ -848,6 +862,8 @@ plugin_transaction_commit_all(clixon_handle h,
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
i++;
if (plugin_transaction_commit_one(cp, h, td) < 0){
/* First make an effort ro revert transaction for the failed plugin */
plugin_transaction_commit_failed(cp, h, td);
/* Make an effort to revert transaction */
plugin_transaction_revert_all(h, td, i-1);
goto done;
Expand Down
2 changes: 2 additions & 0 deletions lib/clixon/clixon_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ struct clixon_plugin_api{
trans_cb_t *cb_trans_complete; /* Transaction validation complete */
trans_cb_t *cb_trans_commit; /* Transaction commit */
trans_cb_t *cb_trans_commit_done; /* Transaction when commit done */
trans_cb_t *cb_trans_commit_failed; /* Transaction commit failed*/
trans_cb_t *cb_trans_revert; /* Transaction revert */
trans_cb_t *cb_trans_end; /* Transaction completed */
trans_cb_t *cb_trans_abort; /* Transaction aborted */
Expand All @@ -424,6 +425,7 @@ struct clixon_plugin_api{
#define ca_trans_complete u.cau_backend.cb_trans_complete
#define ca_trans_commit u.cau_backend.cb_trans_commit
#define ca_trans_commit_done u.cau_backend.cb_trans_commit_done
#define ca_trans_commit_failed u.cau_backend.cb_trans_commit_failed
#define ca_trans_revert u.cau_backend.cb_trans_revert
#define ca_trans_end u.cau_backend.cb_trans_end
#define ca_trans_abort u.cau_backend.cb_trans_abort
Expand Down

0 comments on commit a8e5f4d

Please sign in to comment.