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.
*
* Authors: Nils Goroll <nils.goroll@uplex.de>
......@@ -67,22 +67,23 @@ vslp_get_prefered_idx(const struct vslpdir *vslpd, const uint32_t key)
const int n = vslpd->n_backend * vslpd->replicas;
int idx = -1, high = n, low = 0, i;
do {
i = (high + low) >> 1;
if (vslpd->hashcircle[i].point == key)
idx = i;
else if (i == n - 1)
idx = n - 1;
else if (vslpd->hashcircle[i].point < key && vslpd->hashcircle[i+1].point >= key)
idx = i + 1;
else if (vslpd->hashcircle[i].point > key)
if (i == 0)
idx = 0;
else
high = i;
else
low = i;
} while (idx == -1);
do {
i = (high + low) >> 1;
if (vslpd->hashcircle[i].point == key)
idx = i;
else if (i == n - 1)
idx = n - 1;
else if (vslpd->hashcircle[i].point < key &&
vslpd->hashcircle[i+1].point >= key)
idx = i + 1;
else if (vslpd->hashcircle[i].point > key)
if (i == 0)
idx = 0;
else
high = i;
else
low = i;
} while (idx == -1);
return idx;
}
......@@ -102,7 +103,8 @@ vslp_be_healthy(struct vslp_state *state, int chosen)
now = time(NULL);
if(state->vslpd->bstate[chosen].recover_time == 0)
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].recover_time = 0;
......@@ -147,11 +149,12 @@ vslp_choose_next(struct vslp_state *state, uint32_t n_retry)
i = state->idx + n_retry;
if(i >= (state->vslpd->n_backend * state->vslpd->replicas))
i = i - (state->vslpd->n_backend * state->vslpd->replicas);
chosen = state->vslpd->hashcircle[i].host;
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;
} while (state->picklist & (1 << chosen));
state->picklist |= 1 << chosen;
......@@ -253,7 +256,7 @@ vslpdir_set_rampup_ratio(struct vslpdir *vslpd, VCL_REAL ratio)
assert(ratio >= 0.0 && ratio < 1.0);
CHECK_OBJ_NOTNULL(vslpd, VSLPDIR_MAGIC);
vslpdir_lock(vslpd);
vslpd->altsrv_p = ratio;
vslpd->altsrv_p = ratio;
vslpdir_unlock(vslpd);
}
......@@ -266,7 +269,7 @@ vslpdir_set_rampup_time(struct vslpdir *vslpd, VCL_DURATION duration)
time_t t = (time_t) floor(duration);
vslpdir_lock(vslpd);
vslpd->rampup_time = t;
vslpd->rampup_time = t;
vslpdir_unlock(vslpd);
}
......@@ -299,29 +302,31 @@ vslpdir_init_hashcircle(struct vslpdir *vslpd, VCL_INT replicas)
WRONG("VSLP director doesn't have any backends");
}
vslpd->replicas = replicas;
for (i = 0; i < vslpd->n_backend; i++) {
for (j = 0; j < replicas; j++) {
int len = strlen(vslpd->backend[i]->vcl_name)
+ (j == 0 ? 0 : log10(j)) + 2;
char s[len];
sprintf(s, "%s%d", vslpd->backend[i]->vcl_name, j);
vslpd->hashcircle[i * replicas + j].point =
vslp_hash_sha256(s);
vslpd->hashcircle[i * replicas + j].host = i;
}
vslpd->bstate[i].canon_point = vslpd->hashcircle[i * replicas].point;
}
qsort( (void *) vslpd->hashcircle, vslpd->n_backend * replicas,
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++) {
int len = strlen(vslpd->backend[i]->vcl_name)
+ (j == 0 ? 0 : log10(j)) + 2;
char s[len];
sprintf(s, "%s%d", vslpd->backend[i]->vcl_name, j);
vslpd->hashcircle[i * replicas + j].point =
vslp_hash_sha256(s);
vslpd->hashcircle[i * replicas + j].host = i;
}
vslpd->bstate[i].canon_point =
vslpd->hashcircle[i * replicas].point;
}
qsort( (void *) vslpd->hashcircle, vslpd->n_backend * replicas,
sizeof (struct vslp_hostnode), (compar) hostnode_compare);
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,
vslpd->hashcircle[i * replicas + j].point,
vslpd->hashcircle[i * replicas + j].host);
......@@ -360,12 +365,12 @@ unsigned
vslpdir_any_healthy(struct vslpdir *vslpd)
{
unsigned retval = 0;
VCL_BACKEND be;
unsigned u;
VCL_BACKEND be;
unsigned u;
CHECK_OBJ_NOTNULL(vslpd, VSLPDIR_MAGIC);
vslpdir_lock(vslpd);
for (u = 0; u < vslpd->n_backend; u++) {
CHECK_OBJ_NOTNULL(vslpd, VSLPDIR_MAGIC);
vslpdir_lock(vslpd);
for (u = 0; u < vslpd->n_backend; u++) {
be = vslpd->backend[u];
CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC);
if (be->healthy(be, NULL, NULL)) {
......@@ -373,19 +378,20 @@ vslpdir_any_healthy(struct vslpdir *vslpd)
break;
}
}
vslpdir_unlock(vslpd);
vslpdir_unlock(vslpd);
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_BACKEND be;
int chosen, be_choice = 0, restarts_o = 0, restarts = 0;
struct vslp_state state;
CHECK_OBJ_NOTNULL(vslpd, VSLPDIR_MAGIC);
CHECK_OBJ_NOTNULL(vslpd, VSLPDIR_MAGIC);
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
AN(ctx->vsl);
......@@ -423,7 +429,7 @@ VCL_BACKEND vslpdir_pick_be(struct vslpdir *vslpd, const struct vrt_ctx *ctx, ui
} else {
be = NULL;
}
while(restarts > 0)
{
n_retry++;
......@@ -435,11 +441,13 @@ VCL_BACKEND vslpdir_pick_be(struct vslpdir *vslpd, const struct vrt_ctx *ctx, ui
if(chosen < 0) {
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);
} else {
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);
be = vslpd->backend[chosen];
AN(be);
......@@ -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);
if(chosen < 0) {
VSLb(ctx->vsl, SLT_Debug,
"VSLP found no alternative backend in healthy");
"VSLP found no alternative backend "
"in healthy");
} else {
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);
be = vslpd->backend[chosen];
}
......@@ -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");
} else {
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);
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