Commit ce30412a authored by Nils Goroll's avatar Nils Goroll

whitespace cleanup

parent 5e913b62
/*- /*-
* Copyright 2009-2015 UPLEX - Nils Goroll Systemoptimierung * Copyright 2009-2016 UPLEX - Nils Goroll Systemoptimierung
* All rights reserved. * All rights reserved.
* *
* Authors: Nils Goroll <nils.goroll@uplex.de> * Authors: Nils Goroll <nils.goroll@uplex.de>
...@@ -67,22 +67,23 @@ vslp_get_prefered_idx(const struct vslpdir *vslpd, const uint32_t key) ...@@ -67,22 +67,23 @@ vslp_get_prefered_idx(const struct vslpdir *vslpd, const uint32_t key)
const int n = vslpd->n_backend * vslpd->replicas; const int n = vslpd->n_backend * vslpd->replicas;
int idx = -1, high = n, low = 0, i; int idx = -1, high = n, low = 0, i;
do { do {
i = (high + low) >> 1; i = (high + low) >> 1;
if (vslpd->hashcircle[i].point == key) if (vslpd->hashcircle[i].point == key)
idx = i; idx = i;
else if (i == n - 1) else if (i == n - 1)
idx = n - 1; idx = n - 1;
else if (vslpd->hashcircle[i].point < key && vslpd->hashcircle[i+1].point >= key) else if (vslpd->hashcircle[i].point < key &&
idx = i + 1; vslpd->hashcircle[i+1].point >= key)
else if (vslpd->hashcircle[i].point > key) idx = i + 1;
if (i == 0) else if (vslpd->hashcircle[i].point > key)
idx = 0; if (i == 0)
else idx = 0;
high = i; else
else high = i;
low = i; else
} while (idx == -1); low = i;
} while (idx == -1);
return idx; return idx;
} }
...@@ -102,7 +103,8 @@ vslp_be_healthy(struct vslp_state *state, int chosen) ...@@ -102,7 +103,8 @@ vslp_be_healthy(struct vslp_state *state, int chosen)
now = time(NULL); now = time(NULL);
if(state->vslpd->bstate[chosen].recover_time == 0) if(state->vslpd->bstate[chosen].recover_time == 0)
state->vslpd->bstate[chosen].recover_time = now; state->vslpd->bstate[chosen].recover_time = now;
if (now >= (state->vslpd->bstate[chosen].recover_time + state->vslpd->rampup_time)) if (now >= (state->vslpd->bstate[chosen].recover_time +
state->vslpd->rampup_time))
{ {
state->vslpd->bstate[chosen].state = 1; state->vslpd->bstate[chosen].state = 1;
state->vslpd->bstate[chosen].recover_time = 0; state->vslpd->bstate[chosen].recover_time = 0;
...@@ -147,11 +149,12 @@ vslp_choose_next(struct vslp_state *state, uint32_t n_retry) ...@@ -147,11 +149,12 @@ vslp_choose_next(struct vslp_state *state, uint32_t n_retry)
i = state->idx + n_retry; i = state->idx + n_retry;
if(i >= (state->vslpd->n_backend * state->vslpd->replicas)) if(i >= (state->vslpd->n_backend * state->vslpd->replicas))
i = i - (state->vslpd->n_backend * state->vslpd->replicas); i = i - (state->vslpd->n_backend * state->vslpd->replicas);
chosen = state->vslpd->hashcircle[i].host; chosen = state->vslpd->hashcircle[i].host;
n_retry++; n_retry++;
if(n_retry > (state->vslpd->n_backend * state->vslpd->replicas) + state->vslpd->n_backend) if(n_retry >
state->vslpd->n_backend * state->vslpd->replicas +
state->vslpd->n_backend)
return -1; return -1;
} while (state->picklist & (1 << chosen)); } while (state->picklist & (1 << chosen));
state->picklist |= 1 << chosen; state->picklist |= 1 << chosen;
...@@ -253,7 +256,7 @@ vslpdir_set_rampup_ratio(struct vslpdir *vslpd, VCL_REAL ratio) ...@@ -253,7 +256,7 @@ vslpdir_set_rampup_ratio(struct vslpdir *vslpd, VCL_REAL ratio)
assert(ratio >= 0.0 && ratio < 1.0); assert(ratio >= 0.0 && ratio < 1.0);
CHECK_OBJ_NOTNULL(vslpd, VSLPDIR_MAGIC); CHECK_OBJ_NOTNULL(vslpd, VSLPDIR_MAGIC);
vslpdir_lock(vslpd); vslpdir_lock(vslpd);
vslpd->altsrv_p = ratio; vslpd->altsrv_p = ratio;
vslpdir_unlock(vslpd); vslpdir_unlock(vslpd);
} }
...@@ -266,7 +269,7 @@ vslpdir_set_rampup_time(struct vslpdir *vslpd, VCL_DURATION duration) ...@@ -266,7 +269,7 @@ vslpdir_set_rampup_time(struct vslpdir *vslpd, VCL_DURATION duration)
time_t t = (time_t) floor(duration); time_t t = (time_t) floor(duration);
vslpdir_lock(vslpd); vslpdir_lock(vslpd);
vslpd->rampup_time = t; vslpd->rampup_time = t;
vslpdir_unlock(vslpd); vslpdir_unlock(vslpd);
} }
...@@ -299,29 +302,31 @@ vslpdir_init_hashcircle(struct vslpdir *vslpd, VCL_INT replicas) ...@@ -299,29 +302,31 @@ vslpdir_init_hashcircle(struct vslpdir *vslpd, VCL_INT replicas)
WRONG("VSLP director doesn't have any backends"); WRONG("VSLP director doesn't have any backends");
} }
vslpd->replicas = replicas; vslpd->replicas = replicas;
for (i = 0; i < vslpd->n_backend; i++) {
for (i = 0; i < vslpd->n_backend; i++) { for (j = 0; j < replicas; j++) {
for (j = 0; j < replicas; j++) { int len = strlen(vslpd->backend[i]->vcl_name)
int len = strlen(vslpd->backend[i]->vcl_name) + (j == 0 ? 0 : log10(j)) + 2;
+ (j == 0 ? 0 : log10(j)) + 2; char s[len];
char s[len];
sprintf(s, "%s%d", vslpd->backend[i]->vcl_name, j);
sprintf(s, "%s%d", vslpd->backend[i]->vcl_name, j); vslpd->hashcircle[i * replicas + j].point =
vslpd->hashcircle[i * replicas + j].point = vslp_hash_sha256(s);
vslp_hash_sha256(s); vslpd->hashcircle[i * replicas + j].host = i;
vslpd->hashcircle[i * replicas + j].host = i; }
} vslpd->bstate[i].canon_point =
vslpd->bstate[i].canon_point = vslpd->hashcircle[i * replicas].point; vslpd->hashcircle[i * replicas].point;
} }
qsort( (void *) vslpd->hashcircle, vslpd->n_backend * replicas, qsort( (void *) vslpd->hashcircle, vslpd->n_backend * replicas,
sizeof (struct vslp_hostnode), (compar) hostnode_compare); sizeof (struct vslp_hostnode), (compar) hostnode_compare);
for (i = 0; i < vslpd->n_backend; i++) for (i = 0; i < vslpd->n_backend; i++)
{ {
for (j = 0; j < replicas; j++) for (j = 0; j < replicas; j++)
{ {
VSL(SLT_Debug, 0, "VSLP hashcircle[%5ld] = {point = %8x, host = %2d}\n", VSL(SLT_Debug, 0,
"VSLP hashcircle[%5ld] = "
"{point = %8x, host = %2d}\n",
i * replicas + j, i * replicas + j,
vslpd->hashcircle[i * replicas + j].point, vslpd->hashcircle[i * replicas + j].point,
vslpd->hashcircle[i * replicas + j].host); vslpd->hashcircle[i * replicas + j].host);
...@@ -360,12 +365,12 @@ unsigned ...@@ -360,12 +365,12 @@ unsigned
vslpdir_any_healthy(struct vslpdir *vslpd) vslpdir_any_healthy(struct vslpdir *vslpd)
{ {
unsigned retval = 0; unsigned retval = 0;
VCL_BACKEND be; VCL_BACKEND be;
unsigned u; unsigned u;
CHECK_OBJ_NOTNULL(vslpd, VSLPDIR_MAGIC); CHECK_OBJ_NOTNULL(vslpd, VSLPDIR_MAGIC);
vslpdir_lock(vslpd); vslpdir_lock(vslpd);
for (u = 0; u < vslpd->n_backend; u++) { for (u = 0; u < vslpd->n_backend; u++) {
be = vslpd->backend[u]; be = vslpd->backend[u];
CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC); CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC);
if (be->healthy(be, NULL, NULL)) { if (be->healthy(be, NULL, NULL)) {
...@@ -373,19 +378,20 @@ vslpdir_any_healthy(struct vslpdir *vslpd) ...@@ -373,19 +378,20 @@ vslpdir_any_healthy(struct vslpdir *vslpd)
break; break;
} }
} }
vslpdir_unlock(vslpd); vslpdir_unlock(vslpd);
return (retval); return (retval);
} }
VCL_BACKEND vslpdir_pick_be(struct vslpdir *vslpd, const struct vrt_ctx *ctx, uint32_t hash, VCL_BACKEND vslpdir_pick_be(struct vslpdir *vslpd,
const struct vrt_ctx *ctx, uint32_t hash,
VCL_INT n_retry, VCL_BOOL altsrv_p, VCL_BOOL healthy) VCL_INT n_retry, VCL_BOOL altsrv_p, VCL_BOOL healthy)
{ {
VCL_BACKEND be; VCL_BACKEND be;
int chosen, be_choice = 0, restarts_o = 0, restarts = 0; int chosen, be_choice = 0, restarts_o = 0, restarts = 0;
struct vslp_state state; struct vslp_state state;
CHECK_OBJ_NOTNULL(vslpd, VSLPDIR_MAGIC); CHECK_OBJ_NOTNULL(vslpd, VSLPDIR_MAGIC);
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
AN(ctx->vsl); AN(ctx->vsl);
...@@ -423,7 +429,7 @@ VCL_BACKEND vslpdir_pick_be(struct vslpdir *vslpd, const struct vrt_ctx *ctx, ui ...@@ -423,7 +429,7 @@ VCL_BACKEND vslpdir_pick_be(struct vslpdir *vslpd, const struct vrt_ctx *ctx, ui
} else { } else {
be = NULL; be = NULL;
} }
while(restarts > 0) while(restarts > 0)
{ {
n_retry++; n_retry++;
...@@ -435,11 +441,13 @@ VCL_BACKEND vslpdir_pick_be(struct vslpdir *vslpd, const struct vrt_ctx *ctx, ui ...@@ -435,11 +441,13 @@ VCL_BACKEND vslpdir_pick_be(struct vslpdir *vslpd, const struct vrt_ctx *ctx, ui
if(chosen < 0) { if(chosen < 0) {
VSLb(ctx->vsl, SLT_Debug, VSLb(ctx->vsl, SLT_Debug,
"VSLP failed to find other healthy backend for key %8x in restarts: %2i/%2i - using previous", "VSLP failed to find other healthy backend "
"for key %8x in restarts: %2i/%2i - using previous",
hash, restarts, restarts_o); hash, restarts, restarts_o);
} else { } else {
VSLb(ctx->vsl, SLT_Debug, VSLb(ctx->vsl, SLT_Debug,
"VSLP picked backend %2i for key %8x in restarts: %2i/%2i", "VSLP picked backend %2i "
"for key %8x in restarts: %2i/%2i",
chosen, hash, restarts, restarts_o); chosen, hash, restarts, restarts_o);
be = vslpd->backend[chosen]; be = vslpd->backend[chosen];
AN(be); AN(be);
...@@ -469,10 +477,12 @@ VCL_BACKEND vslpdir_pick_be(struct vslpdir *vslpd, const struct vrt_ctx *ctx, ui ...@@ -469,10 +477,12 @@ VCL_BACKEND vslpdir_pick_be(struct vslpdir *vslpd, const struct vrt_ctx *ctx, ui
chosen = vslp_choose_next_healthy(&state, n_retry); chosen = vslp_choose_next_healthy(&state, n_retry);
if(chosen < 0) { if(chosen < 0) {
VSLb(ctx->vsl, SLT_Debug, VSLb(ctx->vsl, SLT_Debug,
"VSLP found no alternative backend in healthy"); "VSLP found no alternative backend "
"in healthy");
} else { } else {
VSLb(ctx->vsl, SLT_Debug, VSLb(ctx->vsl, SLT_Debug,
"VSLP picked alternative backend %2i for key %8x in healthy", "VSLP picked alternative backend %2i "
"for key %8x in healthy",
chosen, hash); chosen, hash);
be = vslpd->backend[chosen]; be = vslpd->backend[chosen];
} }
...@@ -487,7 +497,8 @@ VCL_BACKEND vslpdir_pick_be(struct vslpdir *vslpd, const struct vrt_ctx *ctx, ui ...@@ -487,7 +497,8 @@ VCL_BACKEND vslpdir_pick_be(struct vslpdir *vslpd, const struct vrt_ctx *ctx, ui
"VSLP found no alternative backend in unhealthy"); "VSLP found no alternative backend in unhealthy");
} else { } else {
VSLb(ctx->vsl, SLT_Debug, VSLb(ctx->vsl, SLT_Debug,
"VSLP picked alternative backend %2i for key %8x in unhealthy", "VSLP picked alternative backend %2i "
"for key %8x in unhealthy",
chosen, hash); chosen, hash);
be = vslpd->backend[chosen]; be = vslpd->backend[chosen];
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment