Skip to content

Commit

Permalink
update op_add and op_remove function for support round_robin load_bal…
Browse files Browse the repository at this point in the history
…ance
  • Loading branch information
王发康 committed Nov 5, 2015
1 parent ebb7a4e commit 4cf13b9
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/ngx_dynamic_upstream_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ ngx_dynamic_upstream_op_add(ngx_http_request_t *r, ngx_dynamic_upstream_op_t *op
__LINE__);
return NGX_ERROR;
}
peers->number++;

last->next->name = u.url;
last->next->server = u.url;
Expand All @@ -309,8 +308,12 @@ ngx_dynamic_upstream_op_add(ngx_http_request_t *r, ngx_dynamic_upstream_op_t *op

if (op->op_param & NGX_DYNAMIC_UPSTEAM_OP_PARAM_WEIGHT) {
last->next->weight = op->weight;
last->next->effective_weight = op->weight;
last->next->current_weight = 0;
} else {
last->next->weight = 1;
last->next->effective_weight = 1;
last->next->current_weight = 0;
}

if (op->op_param & NGX_DYNAMIC_UPSTEAM_OP_PARAM_MAX_FAILS) {
Expand All @@ -329,6 +332,11 @@ ngx_dynamic_upstream_op_add(ngx_http_request_t *r, ngx_dynamic_upstream_op_t *op
last->next->down = op->down;
}

peers->number++;
peers->total_weight += last->next->weight;
peers->single = (peers->number == 1);
peers->weighted = (peers->total_weight != peers->number);

ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
"added server %s", op->server.data);

Expand All @@ -342,6 +350,7 @@ ngx_dynamic_upstream_op_remove(ngx_http_request_t *r, ngx_dynamic_upstream_op_t
{
ngx_http_upstream_rr_peer_t *peer, *target, *prev;
ngx_http_upstream_rr_peers_t *peers;
ngx_uint_t weight;

peers = uscf->peer.data;

Expand Down Expand Up @@ -371,7 +380,8 @@ ngx_dynamic_upstream_op_remove(ngx_http_request_t *r, ngx_dynamic_upstream_op_t
__LINE__);
return NGX_ERROR;
}


weight = target->weight;
/* released removed peer and attributes */
if (ngx_dynamic_upstream_is_shpool_range(r, shpool, target->name.data)) {
ngx_slab_free_locked(shpool, target->name.data);
Expand Down Expand Up @@ -400,6 +410,9 @@ ngx_dynamic_upstream_op_remove(ngx_http_request_t *r, ngx_dynamic_upstream_op_t

ok:
peers->number--;
peers->total_weight -= weight;
peers->single = (peers->number == 1);
peers->weighted = (peers->total_weight != peers->number);

ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
"removed server %s", op->server.data);
Expand Down

0 comments on commit 4cf13b9

Please sign in to comment.