Commit 774b262f authored by Nils Goroll's avatar Nils Goroll Committed by Reza Naghibi

shard: more signedness stir

 Conflicts:
	lib/libvmod_directors/shard_dir.c
	lib/libvmod_directors/vmod_shard.c
parent 3e8316c2
...@@ -241,7 +241,7 @@ static void ...@@ -241,7 +241,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;
...@@ -389,7 +389,7 @@ shardcfg_backend_lookup(const struct backend_reconfig *re, ...@@ -389,7 +389,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);
...@@ -422,6 +422,7 @@ shardcfg_backend_add(struct backend_reconfig *re, ...@@ -422,6 +422,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;
...@@ -440,7 +441,7 @@ shardcfg_backend_add(struct backend_reconfig *re, ...@@ -440,7 +441,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;
...@@ -525,7 +526,7 @@ shardcfg_apply_change(VRT_CTX, struct sharddir *shardd, ...@@ -525,7 +526,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)
...@@ -651,7 +652,7 @@ shardcfg_reconfigure(VRT_CTX, struct vmod_priv *priv, ...@@ -651,7 +652,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]);
...@@ -682,7 +683,7 @@ shardcfg_set_rampup(struct sharddir *shardd, VCL_DURATION duration) ...@@ -682,7 +683,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;
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,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"
#include "cache/cache_director.h" #include "cache/cache_director.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;
...@@ -200,7 +201,7 @@ shard_next(struct shard_state *state, VCL_INT skip, VCL_BOOL healthy) ...@@ -200,7 +201,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));
...@@ -293,9 +294,9 @@ init_state(struct shard_state *state, ...@@ -293,9 +294,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
...@@ -359,7 +360,7 @@ sharddir_pick_be_locked(VRT_CTX, const struct sharddir *shardd, uint32_t key, ...@@ -359,7 +360,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, healthy == ALL ? 1 : 0) == -1) { if (shard_next(state, alt - 1, healthy == 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);
...@@ -370,7 +371,7 @@ sharddir_pick_be_locked(VRT_CTX, const struct sharddir *shardd, uint32_t key, ...@@ -370,7 +371,7 @@ sharddir_pick_be_locked(VRT_CTX, const struct sharddir *shardd, uint32_t key,
} }
if (shard_next(state, 0, healthy == IGNORE ? 0 : 1) == -1) { if (shard_next(state, 0, healthy == 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);
...@@ -390,8 +391,8 @@ sharddir_pick_be_locked(VRT_CTX, const struct sharddir *shardd, uint32_t key, ...@@ -390,8 +391,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));
......
...@@ -90,9 +90,8 @@ struct sharddir { ...@@ -90,9 +90,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);
} }
...@@ -130,4 +129,4 @@ VCL_BACKEND sharddir_pick_be(VRT_CTX, struct sharddir *, uint32_t, VCL_INT, ...@@ -130,4 +129,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);
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