Browse code

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

Daniel-Constantin Mierla authored on 30/03/2012 11:24:03
Showing 6 changed files
... ...
@@ -909,10 +909,10 @@ onreply_route {
909 909
 
910 910
 5.3. ds_reload
911 911
 
912
-   It reloads the groups and included destinations. The command is
913
-   disabled for call load based dispatching (algorithm 10) since removal
914
-   of destinations may leave the list of active calls with broken
915
-   references.
912
+   It reloads the groups and included destinations. For algorithm 10 (call
913
+   load distribution), old internal list of active calls is destroyed
914
+   (because it is bould to the previous list of gateways), meaning that
915
+   the module is starting to count active calls again from 0.
916 916
 
917 917
    Name: ds_reload
918 918
 
... ...
@@ -595,9 +595,10 @@ next_line:
595 595
 
596 596
 	fclose(f);
597 597
 	f = NULL;
598
-	/* Update list */
598
+	/* Update list - should it be sync'ed? */
599 599
 	_ds_list_nr = setn;
600 600
 	*crt_idx = *next_idx;
601
+	ds_ht_clear_slots(_dsht_load);
601 602
 	ds_print_sets();
602 603
 	return 0;
603 604
 
... ...
@@ -774,9 +775,10 @@ int ds_load_db(void)
774 775
 		goto err2;
775 776
 	}
776 777
 
777
-	/*update data*/
778
+	/* update data - should it be sync'ed? */
778 779
 	_ds_list_nr = setn;
779 780
 	*crt_idx = *next_idx;
781
+	ds_ht_clear_slots(_dsht_load);
780 782
 
781 783
 	ds_print_sets();
782 784
 
... ...
@@ -1327,7 +1329,8 @@ int ds_load_replace(struct sip_msg *msg, str *duid)
1327 1329
 
1328 1330
 	ds_unlock_cell(_dsht_load, &msg->callid->body);
1329 1331
 	ds_del_cell(_dsht_load, &msg->callid->body);
1330
-	idx->dlist[olddst].dload--;
1332
+	if(idx->dlist[olddst].dload>0)
1333
+		idx->dlist[olddst].dload--;
1331 1334
 
1332 1335
 	if(ds_load_add(msg, idx, set, newdst)<0)
1333 1336
 	{
... ...
@@ -1384,7 +1387,8 @@ int ds_load_remove(struct sip_msg *msg)
1384 1387
 
1385 1388
 	ds_unlock_cell(_dsht_load, &msg->callid->body);
1386 1389
 	ds_del_cell(_dsht_load, &msg->callid->body);
1387
-	idx->dlist[olddst].dload--;
1390
+	if(idx->dlist[olddst].dload>0)
1391
+		idx->dlist[olddst].dload--;
1388 1392
 
1389 1393
 	return 0;
1390 1394
 }
... ...
@@ -1423,7 +1427,8 @@ int ds_load_remove_byid(int set, str *duid)
1423 1427
 		return -1;
1424 1428
 	}
1425 1429
 
1426
-	idx->dlist[olddst].dload--;
1430
+	if(idx->dlist[olddst].dload>0)
1431
+		idx->dlist[olddst].dload--;
1427 1432
 
1428 1433
 	return 0;
1429 1434
 }
... ...
@@ -772,12 +772,6 @@ static struct mi_root* ds_mi_list(struct mi_root* cmd_tree, void* param)
772 772
 
773 773
 static struct mi_root* ds_mi_reload(struct mi_root* cmd_tree, void* param)
774 774
 {
775
-	if(dstid_avp_name.n!=0) {
776
-		LM_ERR("No reload support when call load dispatching is enabled."
777
-				" Do not set dstid_avp param if you do not use alg 10.\n");
778
-		return init_mi_tree(500, MI_ERR_DSLOAD, MI_ERR_DSLOAD_LEN);
779
-	}
780
-
781 775
 	if(!ds_db_url.s) {
782 776
 		if (ds_load_list(dslistfile)!=0)
783 777
 			return init_mi_tree(500, MI_ERR_RELOAD, MI_ERR_RELOAD_LEN);
... ...
@@ -1111,10 +1111,11 @@ onreply_route {
1111 1111
 		<function moreinfo="none">ds_reload</function>
1112 1112
 		</title>
1113 1113
 		<para>
1114
-		It reloads the groups and included destinations. The command is
1115
-		disabled for call load based dispatching (algorithm 10) since
1116
-		removal of destinations may leave the list of active
1117
-		calls with broken references.
1114
+		It reloads the groups and included destinations. For algorithm 10
1115
+		(call load distribution), old internal list of active calls is
1116
+		destroyed (because it is bould to the previous list of gateways),
1117
+		meaning that the module is starting to count active calls again
1118
+		from 0.
1118 1119
 		</para>
1119 1120
 		<para>
1120 1121
 		Name: <emphasis>ds_reload</emphasis>
... ...
@@ -149,6 +149,32 @@ int ds_ht_destroy(ds_ht_t *dsht)
149 149
 	return 0;
150 150
 }
151 151
 
152
+int ds_ht_clear_slots(ds_ht_t *dsht)
153
+{
154
+	int i;
155
+	ds_cell_t *it, *it0;
156
+
157
+	if(dsht==NULL)
158
+		return -1;
159
+
160
+	for(i=0; i<dsht->htsize; i++)
161
+	{
162
+		lock_get(&dsht->entries[i].lock);
163
+		/* free entries */
164
+		it = dsht->entries[i].first;
165
+		while(it)
166
+		{
167
+			it0 = it;
168
+			it = it->next;
169
+			ds_cell_free(it0);
170
+		}
171
+		dsht->entries[i].first = NULL;
172
+		dsht->entries[i].esize = 0;
173
+		lock_destroy(&dsht->entries[i].lock);
174
+	}
175
+	return 0;
176
+}
177
+
152 178
 
153 179
 int ds_add_cell(ds_ht_t *dsht, str *cid, str *duid, int dset)
154 180
 {
... ...
@@ -69,5 +69,6 @@ int ds_unlock_cell(ds_ht_t *dsht, str *cid);
69 69
 
70 70
 int ds_ht_dbg(ds_ht_t *dsht);
71 71
 int ds_cell_free(ds_cell_t *cell);
72
+int ds_ht_clear_slots(ds_ht_t *dsht);
72 73
 
73 74
 #endif