[sr-dev] git:master:e6a7a3f3: presence: limit the number of subscriptions handled in timer_dbonly

lazedo luis.azedo at factorlusitano.com
Thu Aug 2 00:36:27 CEST 2018


Module: kamailio
Branch: master
Commit: e6a7a3f37e80683d941321a6e10b636f0bfb4478
URL: https://github.com/kamailio/kamailio/commit/e6a7a3f37e80683d941321a6e10b636f0bfb4478

Author: lazedo <luis.azedo at factorlusitano.com>
Committer: lazedo <luis.azedo at factorlusitano.com>
Date: 2018-08-01T23:36:22+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.

---

Modified: src/modules/presence/subscribe.c

---

Diff:  https://github.com/kamailio/kamailio/commit/e6a7a3f37e80683d941321a6e10b636f0bfb4478.diff
Patch: https://github.com/kamailio/kamailio/commit/e6a7a3f37e80683d941321a6e10b636f0bfb4478.patch

---

diff --git a/src/modules/presence/subscribe.c b/src/modules/presence/subscribe.c
index 4c74ac7980..e3352b1615 100644
--- a/src/modules/presence/subscribe.c
+++ b/src/modules/presence/subscribe.c
@@ -2026,14 +2026,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;
@@ -2072,27 +2072,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));
 
@@ -2173,12 +2172,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