Skip to content

Commit

Permalink
dispatcher: sync on updating last used fields
Browse files Browse the repository at this point in the history
(cherry picked from commit e307432)
  • Loading branch information
miconda authored and henningw committed Oct 2, 2020
1 parent 773f6f4 commit 35df241
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/modules/dispatcher/dispatch.c
Expand Up @@ -2044,6 +2044,7 @@ int ds_manage_routes(sip_msg_t *msg, ds_select_state_t *rstate)
unsigned int hash;
ds_set_t *idx = NULL;
int ulast = 0;
int vlast = 0;

if(msg == NULL) {
LM_ERR("bad parameters\n");
Expand Down Expand Up @@ -2098,8 +2099,11 @@ int ds_manage_routes(sip_msg_t *msg, ds_select_state_t *rstate)
}
break;
case DS_ALG_ROUNDROBIN: /* 4 - round robin */
lock_get(&idx->lock);
hash = idx->last;
idx->last = (idx->last + 1) % idx->nr;
vlast = idx->last;
lock_release(&idx->lock);
ulast = 1;
break;
case DS_ALG_HASHAUTHUSER: /* 5 - hash auth username */
Expand All @@ -2110,8 +2114,11 @@ int ds_manage_routes(sip_msg_t *msg, ds_select_state_t *rstate)
break;
case 1:
/* No Authorization found: Use round robin */
lock_get(&idx->lock);
hash = idx->last;
idx->last = (idx->last + 1) % idx->nr;
vlast = idx->last;
lock_release(&idx->lock);
ulast = 1;
break;
default:
Expand All @@ -2132,8 +2139,10 @@ int ds_manage_routes(sip_msg_t *msg, ds_select_state_t *rstate)
hash = 0;
break;
case DS_ALG_WEIGHT: /* 9 - weight based distribution */
lock_get(&idx->lock);
hash = idx->wlist[idx->wlast];
idx->wlast = (idx->wlast + 1) % 100;
lock_release(&idx->lock);
break;
case DS_ALG_CALLLOAD: /* 10 - call load based distribution */
/* only INVITE can start a call */
Expand Down Expand Up @@ -2163,8 +2172,10 @@ int ds_manage_routes(sip_msg_t *msg, ds_select_state_t *rstate)
}
break;
case DS_ALG_RELWEIGHT: /* 11 - relative weight based distribution */
lock_get(&idx->lock);
hash = idx->rwlist[idx->rwlast];
idx->rwlast = (idx->rwlast + 1) % 100;
lock_release(&idx->lock);
break;
case DS_ALG_PARALLEL: /* 12 - parallel dispatching */
hash = 0;
Expand Down Expand Up @@ -2214,10 +2225,13 @@ int ds_manage_routes(sip_msg_t *msg, ds_select_state_t *rstate)
rstate->emode = 1;
}

/* update last field for next select to point after the current active used */
if(ulast) {
/* update last field for next select to point after the current active used,
* if not updated meanwhile */
lock_get(&idx->lock);
if(ulast && (vlast == idx->last)) {
idx->last = (hash + 1) % idx->nr;
}
lock_release(&idx->lock);

LM_DBG("selected [%d-%d-%d/%d] <%.*s>\n", rstate->alg, rstate->setid,
rstate->umode, hash,
Expand Down

0 comments on commit 35df241

Please sign in to comment.