Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add revert failed cb #550

Merged
merged 6 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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