[sr-dev] git:5.1:4868a1a1: presence: limit the number of subscriptions handled in timer_dbonly

Luis Azedo luis at 2600hz.com
Thu Aug 2 00:41:54 CEST 2018


Module: kamailio
Branch: 5.1
Commit: 4868a1a18b54b0fb337453c8257b2466b78fb71b
URL: https://github.com/kamailio/kamailio/commit/4868a1a18b54b0fb337453c8257b2466b78fb71b

Author: lazedo <luis.azedo at factorlusitano.com>
Committer: Luis Azedo <luis at 2600hz.com>
Date: 2018-08-01T23:38:20+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/4868a1a18b54b0fb337453c8257b2466b78fb71b.diff
Patch: https://github.com/kamailio/kamailio/commit/4868a1a18b54b0fb337453c8257b2466b78fb71b.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