[6.0] 774b262fe shard: more signedness stir
Reza Naghibi
reza at naghibi.com
Wed Aug 19 13:17:07 UTC 2020
commit 774b262fe213ac000e4b24d50d3c50debbf2808a
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Wed Jun 10 09:29:34 2020 +0200
shard: more signedness stir
Conflicts:
lib/libvmod_directors/shard_dir.c
lib/libvmod_directors/vmod_shard.c
diff --git a/lib/libvmod_directors/shard_cfg.c b/lib/libvmod_directors/shard_cfg.c
index e08fd8ca3..bb0a7aabb 100644
--- a/lib/libvmod_directors/shard_cfg.c
+++ b/lib/libvmod_directors/shard_cfg.c
@@ -241,7 +241,7 @@ static void
shardcfg_hashcircle(struct sharddir *shardd)
{
const struct shard_backend *backends, *b;
- int h;
+ unsigned h;
uint32_t i, j, n_points, r, rmax;
const char *ident;
const int len = 12; // log10(UINT32_MAX) + 2;
@@ -389,7 +389,7 @@ shardcfg_backend_lookup(const struct backend_reconfig *re,
static void
shardcfg_backend_expand(const struct backend_reconfig *re)
{
- int min = re->hint;
+ unsigned min = re->hint;
CHECK_OBJ_NOTNULL(re->shardd, SHARDDIR_MAGIC);
@@ -422,6 +422,7 @@ shardcfg_backend_add(struct backend_reconfig *re,
assert(re->shardd->n_backend < re->shardd->l_backend);
i = re->shardd->n_backend;
} else {
+ assert(re->hole_i != UINT_MAX);
do {
if (!bb[re->hole_i].backend)
break;
@@ -440,7 +441,7 @@ shardcfg_backend_add(struct backend_reconfig *re,
static void
shardcfg_backend_clear(struct sharddir *shardd)
{
- int i;
+ unsigned i;
for (i = 0; i < shardd->n_backend; i++)
shardcfg_backend_free(&shardd->backend[i]);
shardd->n_backend = 0;
@@ -525,7 +526,7 @@ shardcfg_apply_change(VRT_CTX, struct sharddir *shardd,
.shardd = shardd,
.hint = shardd->n_backend,
.hole_n = 0,
- .hole_i = INT_MAX
+ .hole_i = UINT_MAX
};
// XXX assert sharddir_locked(shardd)
@@ -651,7 +652,7 @@ shardcfg_reconfigure(VRT_CTX, struct vmod_priv *priv,
void
shardcfg_delete(const struct sharddir *shardd)
{
- int i;
+ unsigned i;
for (i = 0; i < shardd->n_backend; i++)
shardcfg_backend_free(&shardd->backend[i]);
@@ -682,7 +683,7 @@ shardcfg_set_rampup(struct sharddir *shardd, VCL_DURATION duration)
}
VCL_DURATION
-shardcfg_get_rampup(const struct sharddir *shardd, int host)
+shardcfg_get_rampup(const struct sharddir *shardd, unsigned host)
{
VCL_DURATION r;
diff --git a/lib/libvmod_directors/shard_dir.c b/lib/libvmod_directors/shard_dir.c
index 875616f68..f2c3db8dd 100644
--- a/lib/libvmod_directors/shard_dir.c
+++ b/lib/libvmod_directors/shard_dir.c
@@ -35,6 +35,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
+#include <limits.h>
#include "cache/cache.h"
#include "cache/cache_director.h"
@@ -47,7 +48,7 @@
#include "shard_dir.h"
struct shard_be_info {
- int hostid;
+ unsigned hostid;
unsigned healthy;
double changed; // when
};
@@ -63,7 +64,7 @@ struct shard_state {
uint32_t idx;
struct vbitmap *picklist;
- int pickcount;
+ unsigned pickcount;
struct shard_be_info previous;
struct shard_be_info last;
@@ -200,7 +201,7 @@ shard_next(struct shard_state *state, VCL_INT skip, VCL_BOOL healthy)
sbe = &state->last;
}
if (sbe == &state->last &&
- state->last.hostid != -1)
+ state->last.hostid != UINT_MAX)
memcpy(&state->previous, &state->last,
sizeof(state->previous));
@@ -293,9 +294,9 @@ init_state(struct shard_state *state,
state->idx = UINT32_MAX;
state->picklist = picklist;
- /* healhy and changed only defined for hostid != -1 */
- state->previous.hostid = -1;
- state->last.hostid = -1;
+ /* healhy and changed only defined for valid hostids */
+ state->previous.hostid = UINT_MAX;
+ state->last.hostid = UINT_MAX;
}
/* basically same as vdir_any_healthy
@@ -359,7 +360,7 @@ sharddir_pick_be_locked(VRT_CTX, const struct sharddir *shardd, uint32_t key,
if (alt > 0) {
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,
state->previous.hostid);
AN(be);
@@ -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 (state->previous.hostid != -1) {
+ if (state->previous.hostid != UINT_MAX) {
be = sharddir_backend(shardd, state->previous.hostid);
AN(be);
return (be);
@@ -390,8 +391,8 @@ sharddir_pick_be_locked(VRT_CTX, const struct sharddir *shardd, uint32_t key,
return (be);
assert(alt == 0);
- assert(state->previous.hostid >= 0);
- assert(state->last.hostid >= 0);
+ assert(state->previous.hostid != UINT_MAX);
+ assert(state->last.hostid != UINT_MAX);
assert(state->previous.hostid != state->last.hostid);
assert(be == sharddir_backend(shardd, state->previous.hostid));
diff --git a/lib/libvmod_directors/shard_dir.h b/lib/libvmod_directors/shard_dir.h
index fc59bc8fd..ac2621a85 100644
--- a/lib/libvmod_directors/shard_dir.h
+++ b/lib/libvmod_directors/shard_dir.h
@@ -90,9 +90,8 @@ struct sharddir {
};
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);
return (shardd->backend[id].backend);
}
@@ -130,4 +129,4 @@ VCL_BACKEND sharddir_pick_be(VRT_CTX, struct sharddir *, uint32_t, VCL_INT,
/* in shard_cfg.c */
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);
More information about the varnish-commit
mailing list