shard: more signedness stir

parent 7fec5db7
...@@ -242,7 +242,7 @@ static void ...@@ -242,7 +242,7 @@ static void
shardcfg_hashcircle(struct sharddir *shardd) shardcfg_hashcircle(struct sharddir *shardd)
{ {
const struct shard_backend *backends, *b; const struct shard_backend *backends, *b;
int h; unsigned h;
uint32_t i, j, n_points, r, rmax; uint32_t i, j, n_points, r, rmax;
const char *ident; const char *ident;
const int len = 12; // log10(UINT32_MAX) + 2; const int len = 12; // log10(UINT32_MAX) + 2;
...@@ -394,7 +394,7 @@ shardcfg_backend_lookup(const struct backend_reconfig *re, ...@@ -394,7 +394,7 @@ shardcfg_backend_lookup(const struct backend_reconfig *re,
static void static void
shardcfg_backend_expand(const struct backend_reconfig *re) shardcfg_backend_expand(const struct backend_reconfig *re)
{ {
int min = re->hint; unsigned min = re->hint;
CHECK_OBJ_NOTNULL(re->shardd, SHARDDIR_MAGIC); CHECK_OBJ_NOTNULL(re->shardd, SHARDDIR_MAGIC);
...@@ -427,6 +427,7 @@ shardcfg_backend_add(struct backend_reconfig *re, ...@@ -427,6 +427,7 @@ shardcfg_backend_add(struct backend_reconfig *re,
assert(re->shardd->n_backend < re->shardd->l_backend); assert(re->shardd->n_backend < re->shardd->l_backend);
i = re->shardd->n_backend; i = re->shardd->n_backend;
} else { } else {
assert(re->hole_i != UINT_MAX);
do { do {
if (!bb[re->hole_i].backend) if (!bb[re->hole_i].backend)
break; break;
...@@ -445,7 +446,7 @@ shardcfg_backend_add(struct backend_reconfig *re, ...@@ -445,7 +446,7 @@ shardcfg_backend_add(struct backend_reconfig *re,
static void static void
shardcfg_backend_clear(struct sharddir *shardd) shardcfg_backend_clear(struct sharddir *shardd)
{ {
int i; unsigned i;
for (i = 0; i < shardd->n_backend; i++) for (i = 0; i < shardd->n_backend; i++)
shardcfg_backend_free(&shardd->backend[i]); shardcfg_backend_free(&shardd->backend[i]);
shardd->n_backend = 0; shardd->n_backend = 0;
...@@ -530,7 +531,7 @@ shardcfg_apply_change(VRT_CTX, struct sharddir *shardd, ...@@ -530,7 +531,7 @@ shardcfg_apply_change(VRT_CTX, struct sharddir *shardd,
.shardd = shardd, .shardd = shardd,
.hint = shardd->n_backend, .hint = shardd->n_backend,
.hole_n = 0, .hole_n = 0,
.hole_i = INT_MAX .hole_i = UINT_MAX
}; };
// XXX assert sharddir_locked(shardd) // XXX assert sharddir_locked(shardd)
...@@ -656,7 +657,7 @@ shardcfg_reconfigure(VRT_CTX, struct vmod_priv *priv, ...@@ -656,7 +657,7 @@ shardcfg_reconfigure(VRT_CTX, struct vmod_priv *priv,
void void
shardcfg_delete(const struct sharddir *shardd) shardcfg_delete(const struct sharddir *shardd)
{ {
int i; unsigned i;
for (i = 0; i < shardd->n_backend; i++) for (i = 0; i < shardd->n_backend; i++)
shardcfg_backend_free(&shardd->backend[i]); shardcfg_backend_free(&shardd->backend[i]);
...@@ -687,7 +688,7 @@ shardcfg_set_rampup(struct sharddir *shardd, VCL_DURATION duration) ...@@ -687,7 +688,7 @@ shardcfg_set_rampup(struct sharddir *shardd, VCL_DURATION duration)
} }
VCL_DURATION VCL_DURATION
shardcfg_get_rampup(const struct sharddir *shardd, int host) shardcfg_get_rampup(const struct sharddir *shardd, unsigned host)
{ {
VCL_DURATION r; VCL_DURATION r;
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#include <limits.h>
#include "cache/cache.h" #include "cache/cache.h"
...@@ -47,7 +48,7 @@ ...@@ -47,7 +48,7 @@
#include "shard_dir.h" #include "shard_dir.h"
struct shard_be_info { struct shard_be_info {
int hostid; unsigned hostid;
unsigned healthy; unsigned healthy;
double changed; // when double changed; // when
}; };
...@@ -63,7 +64,7 @@ struct shard_state { ...@@ -63,7 +64,7 @@ struct shard_state {
uint32_t idx; uint32_t idx;
struct vbitmap *picklist; struct vbitmap *picklist;
int pickcount; unsigned pickcount;
struct shard_be_info previous; struct shard_be_info previous;
struct shard_be_info last; struct shard_be_info last;
...@@ -159,7 +160,7 @@ shard_next(struct shard_state *state, VCL_INT skip, VCL_BOOL healthy) ...@@ -159,7 +160,7 @@ shard_next(struct shard_state *state, VCL_INT skip, VCL_BOOL healthy)
sbe = &state->last; sbe = &state->last;
} }
if (sbe == &state->last && if (sbe == &state->last &&
state->last.hostid != -1) state->last.hostid != UINT_MAX)
memcpy(&state->previous, &state->last, memcpy(&state->previous, &state->last,
sizeof(state->previous)); sizeof(state->previous));
...@@ -262,9 +263,9 @@ init_state(struct shard_state *state, ...@@ -262,9 +263,9 @@ init_state(struct shard_state *state,
state->idx = UINT32_MAX; state->idx = UINT32_MAX;
state->picklist = picklist; state->picklist = picklist;
/* healhy and changed only defined for hostid != -1 */ /* healhy and changed only defined for valid hostids */
state->previous.hostid = -1; state->previous.hostid = UINT_MAX;
state->last.hostid = -1; state->last.hostid = UINT_MAX;
} }
/* basically same as vdir_any_healthy /* basically same as vdir_any_healthy
...@@ -327,7 +328,7 @@ sharddir_pick_be_locked(VRT_CTX, const struct sharddir *shardd, uint32_t key, ...@@ -327,7 +328,7 @@ sharddir_pick_be_locked(VRT_CTX, const struct sharddir *shardd, uint32_t key,
if (alt > 0) { if (alt > 0) {
if (shard_next(state, alt - 1, if (shard_next(state, alt - 1,
healthy == VENUM(ALL) ? 1 : 0) == -1) { healthy == VENUM(ALL) ? 1 : 0) == -1) {
if (state->previous.hostid != -1) { if (state->previous.hostid != UINT_MAX) {
be = sharddir_backend(shardd, be = sharddir_backend(shardd,
state->previous.hostid); state->previous.hostid);
AN(be); AN(be);
...@@ -338,7 +339,7 @@ sharddir_pick_be_locked(VRT_CTX, const struct sharddir *shardd, uint32_t key, ...@@ -338,7 +339,7 @@ sharddir_pick_be_locked(VRT_CTX, const struct sharddir *shardd, uint32_t key,
} }
if (shard_next(state, 0, healthy == VENUM(IGNORE) ? 0 : 1) == -1) { if (shard_next(state, 0, healthy == VENUM(IGNORE) ? 0 : 1) == -1) {
if (state->previous.hostid != -1) { if (state->previous.hostid != UINT_MAX) {
be = sharddir_backend(shardd, state->previous.hostid); be = sharddir_backend(shardd, state->previous.hostid);
AN(be); AN(be);
return (be); return (be);
...@@ -358,8 +359,8 @@ sharddir_pick_be_locked(VRT_CTX, const struct sharddir *shardd, uint32_t key, ...@@ -358,8 +359,8 @@ sharddir_pick_be_locked(VRT_CTX, const struct sharddir *shardd, uint32_t key,
return (be); return (be);
assert(alt == 0); assert(alt == 0);
assert(state->previous.hostid >= 0); assert(state->previous.hostid != UINT_MAX);
assert(state->last.hostid >= 0); assert(state->last.hostid != UINT_MAX);
assert(state->previous.hostid != state->last.hostid); assert(state->previous.hostid != state->last.hostid);
assert(be == sharddir_backend(shardd, state->previous.hostid)); assert(be == sharddir_backend(shardd, state->previous.hostid));
......
...@@ -74,9 +74,8 @@ struct sharddir { ...@@ -74,9 +74,8 @@ struct sharddir {
}; };
static inline VCL_BACKEND static inline VCL_BACKEND
sharddir_backend(const struct sharddir *shardd, int id) sharddir_backend(const struct sharddir *shardd, unsigned id)
{ {
assert(id >= 0);
assert(id < shardd->n_backend); assert(id < shardd->n_backend);
return (shardd->backend[id].backend); return (shardd->backend[id].backend);
} }
...@@ -115,4 +114,4 @@ VCL_BACKEND sharddir_pick_be(VRT_CTX, struct sharddir *, uint32_t, VCL_INT, ...@@ -115,4 +114,4 @@ VCL_BACKEND sharddir_pick_be(VRT_CTX, struct sharddir *, uint32_t, VCL_INT,
/* in shard_cfg.c */ /* in shard_cfg.c */
void shardcfg_delete(const struct sharddir *shardd); void shardcfg_delete(const struct sharddir *shardd);
VCL_DURATION shardcfg_get_rampup(const struct sharddir *shardd, int host); VCL_DURATION shardcfg_get_rampup(const struct sharddir *shardd, unsigned host);
...@@ -707,9 +707,8 @@ vmod_shard_list(VRT_CTX, VCL_BACKEND dir, struct vsb *vsb, int pflag, int jflag) ...@@ -707,9 +707,8 @@ vmod_shard_list(VRT_CTX, VCL_BACKEND dir, struct vsb *vsb, int pflag, int jflag)
VCL_DURATION rampup_d, d; VCL_DURATION rampup_d, d;
VCL_BACKEND be; VCL_BACKEND be;
VCL_BOOL h; VCL_BOOL h;
unsigned nh = 0; unsigned i, nh = 0;
double rampup_p; double rampup_p;
int i;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(dir, DIRECTOR_MAGIC); CHECK_OBJ_NOTNULL(dir, DIRECTOR_MAGIC);
......
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