Skip to content

Commit

Permalink
Merge pull request #2342 from kamailio/grumvalski/ds_load_table
Browse files Browse the repository at this point in the history
dispatcher: don't reset load table when adding/removing a destination…
  • Loading branch information
grumvalski committed Jun 5, 2020
2 parents a118641 + 4099a6c commit 8e2c2e3
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/modules/dispatcher/dispatch.c
Expand Up @@ -878,7 +878,7 @@ int ds_load_list(char *lfile)
/* Update list - should it be sync'ed? */
_ds_list_nr = setn;
*crt_idx = *next_idx;
ds_ht_clear_slots(_dsht_load);

ds_log_sets();
return 0;

Expand Down Expand Up @@ -1126,7 +1126,6 @@ int ds_load_db(void)
/* update data - should it be sync'ed? */
_ds_list_nr = setn;
*crt_idx = *next_idx;
ds_ht_clear_slots(_dsht_load);

ds_log_sets();

Expand Down Expand Up @@ -1617,22 +1616,24 @@ int ds_load_replace(struct sip_msg *msg, str *duid)
break;
}
}
/* old destination has not been found: has been removed meanwhile? */
if(olddst == -1) {
ds_unlock_cell(_dsht_load, &msg->callid->body);
LM_ERR("old destination address not found for [%d, %.*s]\n", set,
LM_WARN("old destination address not found for [%d, %.*s]\n", set,
it->duid.len, it->duid.s);
return -1;
}
}
if(newdst == -1) {
/* new destination has not been found: has been removed meanwhile? */
ds_unlock_cell(_dsht_load, &msg->callid->body);
LM_ERR("new destination address not found for [%d, %.*s]\n", set,
duid->len, duid->s);
return -1;
return -2;
}

ds_unlock_cell(_dsht_load, &msg->callid->body);
ds_del_cell(_dsht_load, &msg->callid->body);
DS_LOAD_DEC(idx, olddst);

if(olddst != -1)
DS_LOAD_DEC(idx, olddst);

if(ds_load_add(msg, idx, set, newdst) < 0) {
LM_ERR("unable to replace destination load [%.*s / %.*s]\n", duid->len,
Expand Down Expand Up @@ -2336,6 +2337,7 @@ int ds_manage_routes(sip_msg_t *msg, ds_select_state_t *rstate)
int ds_update_dst(struct sip_msg *msg, int upos, int mode)
{

int ret;
socket_info_t *sock = NULL;
sr_xavp_t *rxavp = NULL;
sr_xavp_t *lxavp = NULL;
Expand All @@ -2348,6 +2350,7 @@ int ds_update_dst(struct sip_msg *msg, int upos, int mode)
}
}

next_dst:
rxavp = xavp_get(&ds_xavp_dst, NULL);
if(rxavp == NULL || rxavp->val.type != SR_XTYPE_XAVP) {
LM_DBG("no xavp with previous destination record\n");
Expand Down Expand Up @@ -2395,12 +2398,18 @@ int ds_update_dst(struct sip_msg *msg, int upos, int mode)
return 1;
}
if(upos == DS_USE_NEXT) {
if(ds_load_replace(msg, &lxavp->val.v.s) < 0) {
LM_ERR("cannot update load distribution\n");
return -1;
ret = ds_load_replace(msg, &lxavp->val.v.s);
switch(ret) {
case 0:
break;
case -2:
LM_ERR("cannot update load with %.*s, skipping dst.\n", lxavp->val.v.s.len, lxavp->val.v.s.s);
goto next_dst;
default:
LM_ERR("cannot update load distribution\n");
return -1;
}
}

return 1;
}

Expand Down Expand Up @@ -2448,7 +2457,7 @@ int ds_add_dst(int group, str *address, int flags, str *attrs)

_ds_list_nr = setn;
*crt_idx = *next_idx;
ds_ht_clear_slots(_dsht_load);

ds_log_sets();
return 0;

Expand Down Expand Up @@ -2503,7 +2512,7 @@ int ds_remove_dst(int group, str *address)

_ds_list_nr = setn;
*crt_idx = *next_idx;
ds_ht_clear_slots(_dsht_load);

ds_log_sets();
return 0;

Expand Down

0 comments on commit 8e2c2e3

Please sign in to comment.