[sr-dev] git:master: dispatcher(k): removed constraint for ds_reload and alg 10

Daniel-Constantin Mierla miconda at gmail.com
Fri Mar 30 13:28:54 CEST 2012


Module: sip-router
Branch: master
Commit: 86646d0d512be27b61a821f297aba53178563e2b
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=86646d0d512be27b61a821f297aba53178563e2b

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Fri Mar 30 13:24:03 2012 +0200

dispatcher(k): removed constraint for ds_reload and alg 10

- ds_reload can be executed even when using call load distribution
- old list of active calls is destroyed, the module starts counting from
  0 with the next new call calls

---

 modules_k/dispatcher/README                   |    8 +++---
 modules_k/dispatcher/dispatch.c               |   15 +++++++++----
 modules_k/dispatcher/dispatcher.c             |    6 -----
 modules_k/dispatcher/doc/dispatcher_admin.xml |    9 ++++---
 modules_k/dispatcher/ds_ht.c                  |   26 +++++++++++++++++++++++++
 modules_k/dispatcher/ds_ht.h                  |    1 +
 6 files changed, 46 insertions(+), 19 deletions(-)

diff --git a/modules_k/dispatcher/README b/modules_k/dispatcher/README
index cffcc6d..e68a2a8 100644
--- a/modules_k/dispatcher/README
+++ b/modules_k/dispatcher/README
@@ -909,10 +909,10 @@ onreply_route {
 
 5.3. ds_reload
 
-   It reloads the groups and included destinations. The command is
-   disabled for call load based dispatching (algorithm 10) since removal
-   of destinations may leave the list of active calls with broken
-   references.
+   It reloads the groups and included destinations. For algorithm 10 (call
+   load distribution), old internal list of active calls is destroyed
+   (because it is bould to the previous list of gateways), meaning that
+   the module is starting to count active calls again from 0.
 
    Name: ds_reload
 
diff --git a/modules_k/dispatcher/dispatch.c b/modules_k/dispatcher/dispatch.c
index 2196992..ae0c51b 100644
--- a/modules_k/dispatcher/dispatch.c
+++ b/modules_k/dispatcher/dispatch.c
@@ -595,9 +595,10 @@ next_line:
 
 	fclose(f);
 	f = NULL;
-	/* Update list */
+	/* Update list - should it be sync'ed? */
 	_ds_list_nr = setn;
 	*crt_idx = *next_idx;
+	ds_ht_clear_slots(_dsht_load);
 	ds_print_sets();
 	return 0;
 
@@ -774,9 +775,10 @@ int ds_load_db(void)
 		goto err2;
 	}
 
-	/*update data*/
+	/* update data - should it be sync'ed? */
 	_ds_list_nr = setn;
 	*crt_idx = *next_idx;
+	ds_ht_clear_slots(_dsht_load);
 
 	ds_print_sets();
 
@@ -1327,7 +1329,8 @@ int ds_load_replace(struct sip_msg *msg, str *duid)
 
 	ds_unlock_cell(_dsht_load, &msg->callid->body);
 	ds_del_cell(_dsht_load, &msg->callid->body);
-	idx->dlist[olddst].dload--;
+	if(idx->dlist[olddst].dload>0)
+		idx->dlist[olddst].dload--;
 
 	if(ds_load_add(msg, idx, set, newdst)<0)
 	{
@@ -1384,7 +1387,8 @@ int ds_load_remove(struct sip_msg *msg)
 
 	ds_unlock_cell(_dsht_load, &msg->callid->body);
 	ds_del_cell(_dsht_load, &msg->callid->body);
-	idx->dlist[olddst].dload--;
+	if(idx->dlist[olddst].dload>0)
+		idx->dlist[olddst].dload--;
 
 	return 0;
 }
@@ -1423,7 +1427,8 @@ int ds_load_remove_byid(int set, str *duid)
 		return -1;
 	}
 
-	idx->dlist[olddst].dload--;
+	if(idx->dlist[olddst].dload>0)
+		idx->dlist[olddst].dload--;
 
 	return 0;
 }
diff --git a/modules_k/dispatcher/dispatcher.c b/modules_k/dispatcher/dispatcher.c
index e376bb6..2ef1af4 100644
--- a/modules_k/dispatcher/dispatcher.c
+++ b/modules_k/dispatcher/dispatcher.c
@@ -772,12 +772,6 @@ static struct mi_root* ds_mi_list(struct mi_root* cmd_tree, void* param)
 
 static struct mi_root* ds_mi_reload(struct mi_root* cmd_tree, void* param)
 {
-	if(dstid_avp_name.n!=0) {
-		LM_ERR("No reload support when call load dispatching is enabled."
-				" Do not set dstid_avp param if you do not use alg 10.\n");
-		return init_mi_tree(500, MI_ERR_DSLOAD, MI_ERR_DSLOAD_LEN);
-	}
-
 	if(!ds_db_url.s) {
 		if (ds_load_list(dslistfile)!=0)
 			return init_mi_tree(500, MI_ERR_RELOAD, MI_ERR_RELOAD_LEN);
diff --git a/modules_k/dispatcher/doc/dispatcher_admin.xml b/modules_k/dispatcher/doc/dispatcher_admin.xml
index 83f6c70..3453210 100644
--- a/modules_k/dispatcher/doc/dispatcher_admin.xml
+++ b/modules_k/dispatcher/doc/dispatcher_admin.xml
@@ -1111,10 +1111,11 @@ onreply_route {
 		<function moreinfo="none">ds_reload</function>
 		</title>
 		<para>
-		It reloads the groups and included destinations. The command is
-		disabled for call load based dispatching (algorithm 10) since
-		removal of destinations may leave the list of active
-		calls with broken references.
+		It reloads the groups and included destinations. For algorithm 10
+		(call load distribution), old internal list of active calls is
+		destroyed (because it is bould to the previous list of gateways),
+		meaning that the module is starting to count active calls again
+		from 0.
 		</para>
 		<para>
 		Name: <emphasis>ds_reload</emphasis>
diff --git a/modules_k/dispatcher/ds_ht.c b/modules_k/dispatcher/ds_ht.c
index 8322f50..1599fa4 100644
--- a/modules_k/dispatcher/ds_ht.c
+++ b/modules_k/dispatcher/ds_ht.c
@@ -149,6 +149,32 @@ int ds_ht_destroy(ds_ht_t *dsht)
 	return 0;
 }
 
+int ds_ht_clear_slots(ds_ht_t *dsht)
+{
+	int i;
+	ds_cell_t *it, *it0;
+
+	if(dsht==NULL)
+		return -1;
+
+	for(i=0; i<dsht->htsize; i++)
+	{
+		lock_get(&dsht->entries[i].lock);
+		/* free entries */
+		it = dsht->entries[i].first;
+		while(it)
+		{
+			it0 = it;
+			it = it->next;
+			ds_cell_free(it0);
+		}
+		dsht->entries[i].first = NULL;
+		dsht->entries[i].esize = 0;
+		lock_destroy(&dsht->entries[i].lock);
+	}
+	return 0;
+}
+
 
 int ds_add_cell(ds_ht_t *dsht, str *cid, str *duid, int dset)
 {
diff --git a/modules_k/dispatcher/ds_ht.h b/modules_k/dispatcher/ds_ht.h
index f705889..8bfc02f 100644
--- a/modules_k/dispatcher/ds_ht.h
+++ b/modules_k/dispatcher/ds_ht.h
@@ -69,5 +69,6 @@ int ds_unlock_cell(ds_ht_t *dsht, str *cid);
 
 int ds_ht_dbg(ds_ht_t *dsht);
 int ds_cell_free(ds_cell_t *cell);
+int ds_ht_clear_slots(ds_ht_t *dsht);
 
 #endif




More information about the sr-dev mailing list