From e4e45a8831dd60ba4f91f9847fc2c6a51982b216 Mon Sep 17 00:00:00 2001 From: Alessio Garzi Date: Wed, 13 Jul 2022 08:29:39 +0200 Subject: [PATCH] TT#184400 No autocommit+rollback if no active watchers kamailio patch Backport from upstream presence module https://github.com/kamailio/kamailio/commit/c80cccd996dcc3b91d4f0f68a2de51104a16d1a5 Change-Id: Ic1a4efb6f780dd1119a5f199a3e38e5c50018694 --- debian/patches/series | 1 + ...commit-rollback-if-no-active-watcher.patch | 72 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 debian/patches/upstream/presence-No-autocommit-rollback-if-no-active-watcher.patch diff --git a/debian/patches/series b/debian/patches/series index 15a3c5c4a..b8afd2bc3 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -41,6 +41,7 @@ upstream/dialog-fix-ki_dlg_get_var-introduced-previously.patch upstream/dialog-dlg_get_var-assure-return-null-on-error.patch upstream/dialog-w_dlg_get_var-fix-incompatible-pointer.patch upstream/topos-skip-adding-contact-header-for-BYE-CANCEL-PRAC.patch +upstream/presence-No-autocommit-rollback-if-no-active-watcher.patch ### relevant for upstream sipwise/core-fix-freeaddrinfo-coredump.patch sipwise/pua_dialoginfo-refresh_pubruri_avps_flag.patch diff --git a/debian/patches/upstream/presence-No-autocommit-rollback-if-no-active-watcher.patch b/debian/patches/upstream/presence-No-autocommit-rollback-if-no-active-watcher.patch new file mode 100644 index 000000000..858786589 --- /dev/null +++ b/debian/patches/upstream/presence-No-autocommit-rollback-if-no-active-watcher.patch @@ -0,0 +1,72 @@ +From c80cccd996dcc3b91d4f0f68a2de51104a16d1a5 Mon Sep 17 00:00:00 2001 +From: Alessio Garzi +Date: Thu, 7 Jul 2022 15:22:12 +0200 +Subject: [PATCH] presence: No autocommit+rollback if no active watchers + +- In case the active_watcher query returns no elements there + is a weird situation where kamailio first runs the select for + active_watcher then rollbacks. + This can happen a lot of times for each second since function + process_dialogs() runs repeatedly. + For this reason trying to avoid the rollback can result + in a quite good performance boost. +--- + src/modules/presence/notify.c | 20 ++++++++++++-------- + 1 file changed, 12 insertions(+), 8 deletions(-) + +diff --git a/src/modules/presence/notify.c b/src/modules/presence/notify.c +index cf52c21c22..4980dc4b0a 100644 +--- a/src/modules/presence/notify.c ++++ b/src/modules/presence/notify.c +@@ -2867,6 +2867,7 @@ int process_dialogs(int round, int presence_winfo) + str ev_sname, winfo = str_init("presence.winfo"); + int now = (int)time(NULL); + int updated = 0; ++ int no_active_watchers = 0; + db_query_f query_fn = pa_dbf.query_lock ? pa_dbf.query_lock : pa_dbf.query; + + query_cols[n_query_cols] = &str_updated_col; +@@ -2900,13 +2901,6 @@ int process_dialogs(int round, int presence_winfo) + goto error; + } + +- if(pa_dbf.start_transaction) { +- if(pa_dbf.start_transaction(pa_db, pres_db_table_lock) < 0) { +- LM_ERR("in start_transaction\n"); +- goto error; +- } +- } +- + /* Step 1: Find active_watchers that require notification */ + if(query_fn(pa_db, query_cols, query_ops, query_vals, result_cols, + n_query_cols, n_result_cols, 0, &dialog_list) +@@ -2920,7 +2914,17 @@ int process_dialogs(int round, int presence_winfo) + } + + if(dialog_list->n <= 0) ++ { ++ no_active_watchers = 1; + goto done; ++ } ++ ++ if(pa_dbf.start_transaction) { ++ if(pa_dbf.start_transaction(pa_db, pres_db_table_lock) < 0) { ++ LM_ERR("in start_transaction\n"); ++ goto error; ++ } ++ } + + /* Step 2: Update the records so they are not notified again */ + if(pa_dbf.update(pa_db, query_cols, query_ops, query_vals, update_cols, +@@ -3164,7 +3168,7 @@ error: + if(dialog) + pa_dbf.free_result(pa_db, dialog); + +- if(pa_dbf.abort_transaction) { ++ if(no_active_watchers == 0 && pa_dbf.abort_transaction) { + if(pa_dbf.abort_transaction(pa_db) < 0) + LM_ERR("in abort_transaction\n"); + } +-- +2.25.1 +