[sr-dev] git:5.0:d67652f9: presence: limit the number of subscriptions handled in timer_dbonly
Luis Azedo
luis at 2600hz.com
Thu Aug 2 00:42:36 CEST 2018
Module: kamailio
Branch: 5.0
Commit: d67652f9688f72c91841b4ad8bc906d9957733bd
URL: https://github.com/kamailio/kamailio/commit/d67652f9688f72c91841b4ad8bc906d9957733bd
Author: lazedo <luis.azedo at factorlusitano.com>
Committer: Luis Azedo <luis at 2600hz.com>
Date: 2018-08-01T23:38:51+01:00
presence: limit the number of subscriptions handled in timer_dbonly
due to the way update_db_subs_timer_dbonly handles the query to the
database (getting all records), if for some reason a burst of
terminating subscriptions occurs, most likely there will be no package
memory to process all expiring subscriptions.
this commit uses the same pattern as other routines in presence by using
db_fetch_query with fetch_rows parameter module.
because we create the subs in the loop and then call handle_expired_subs
to avoid locking issues the subscription should already be deleted from
the database when it returns from handle_expired_subs, there's no reason
to issue the last delete, and that was removed.
(cherry picked from commit e6a7a3f37e80683d941321a6e10b636f0bfb4478)
---
Modified: src/modules/presence/subscribe.c
---
Diff: https://github.com/kamailio/kamailio/commit/d67652f9688f72c91841b4ad8bc906d9957733bd.diff
Patch: https://github.com/kamailio/kamailio/commit/d67652f9688f72c91841b4ad8bc906d9957733bd.patch
---
diff --git a/src/modules/presence/subscribe.c b/src/modules/presence/subscribe.c
index 8b53500c18..754d1bf2ca 100644
--- a/src/modules/presence/subscribe.c
+++ b/src/modules/presence/subscribe.c
@@ -2010,14 +2010,14 @@ void update_db_subs_timer_dbonly(void)
db_val_t qvals[1];
db_key_t result_cols[18];
int pres_uri_col, to_user_col, to_domain_col, from_user_col, from_domain_col,
- callid_col, totag_col, fromtag_col, event_col, event_id_col,
- local_cseq_col, expires_col, rr_col, sockinfo_col,
- contact_col, lcontact_col, watcher_user_col, watcher_domain_col;
+ callid_col, totag_col, fromtag_col, event_col, event_id_col,
+ local_cseq_col, expires_col, rr_col, sockinfo_col,
+ contact_col, lcontact_col, watcher_user_col, watcher_domain_col;
int n_result_cols = 0;
db1_res_t *result= NULL;
- db_row_t *row = NULL;
+ db_row_t *rows;
db_val_t *row_vals= NULL;
- int i;
+ int i, res;
subs_t s, *s_new, *s_array = NULL, *s_del;
str ev_name;
pres_ev_t* event;
@@ -2056,27 +2056,26 @@ void update_db_subs_timer_dbonly(void)
return;
}
- if (pa_dbf.query(pa_db, qcols, qops, qvals, result_cols,
- 1, n_result_cols, 0, &result) < 0) {
+ res = db_fetch_query(&pa_dbf, pres_fetch_rows, pa_db, qcols, qops, qvals, result_cols,1, n_result_cols, 0, &result );
+ if (res < 0)
+ {
LM_ERR("failed to query database for expired subscriptions\n");
- if(result)
+ if (result) {
pa_dbf.free_result(pa_db, result);
+ }
return;
}
- if(result== NULL)
- return;
-
- if(result->n <=0 ) {
- pa_dbf.free_result(pa_db, result);
+ if(result == NULL) {
+ LM_DBG("no results returned\n");
return;
}
- LM_DBG("found %d dialogs\n", result->n);
- for(i=0; i<result->n; i++)
- {
- row = &result->rows[i];
- row_vals = ROW_VALUES(row);
+ LM_DBG("processing %d dialogs\n", RES_ROW_N(result));
+ s_array = NULL;
+ rows = RES_ROWS(result);
+ for (i = 0; i < RES_ROW_N(result); i++) {
+ row_vals = ROW_VALUES(&rows[i]);
memset(&s, 0, sizeof(subs_t));
@@ -2157,12 +2156,6 @@ void update_db_subs_timer_dbonly(void)
s_new = s_new->next;
pkg_free(s_del);
}
-
- /* delete the expired subscriptions */
- if(pa_dbf.delete(pa_db, qcols, qops, qvals, 1) < 0)
- {
- LM_ERR("deleting expired information from database\n");
- }
}
void update_db_subs_timer_dbnone(int no_lock)
More information about the sr-dev
mailing list