[master] 2f05442 Let remove_backend tell if the current dir changed
Guillaume Quintard
guillaume at varnish-software.com
Wed Feb 1 11:09:05 CET 2017
commit 2f0544222347302607348a8a59fb39f592f74885
Author: Guillaume Quintard <guillaume at varnish-software.com>
Date: Fri Jan 27 14:38:05 2017 +0100
Let remove_backend tell if the current dir changed
diff --git a/lib/libvmod_directors/fall_back.c b/lib/libvmod_directors/fall_back.c
index c45e539..7a44938 100644
--- a/lib/libvmod_directors/fall_back.c
+++ b/lib/libvmod_directors/fall_back.c
@@ -123,7 +123,7 @@ vmod_fallback_remove_backend(VRT_CTX,
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(fb, VMOD_DIRECTORS_FALLBACK_MAGIC);
- vdir_remove_backend(fb->vd, be);
+ vdir_remove_backend(fb->vd, be, NULL);
}
VCL_BACKEND __match_proto__()
diff --git a/lib/libvmod_directors/hash.c b/lib/libvmod_directors/hash.c
index b117d56..71a4366 100644
--- a/lib/libvmod_directors/hash.c
+++ b/lib/libvmod_directors/hash.c
@@ -91,7 +91,7 @@ vmod_hash_remove_backend(VRT_CTX,
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(rr, VMOD_DIRECTORS_HASH_MAGIC);
- vdir_remove_backend(rr->vd, be);
+ vdir_remove_backend(rr->vd, be, NULL);
}
VCL_BACKEND __match_proto__()
diff --git a/lib/libvmod_directors/random.c b/lib/libvmod_directors/random.c
index 314c9eb..10e6f53 100644
--- a/lib/libvmod_directors/random.c
+++ b/lib/libvmod_directors/random.c
@@ -118,7 +118,7 @@ VCL_VOID vmod_random_remove_backend(VRT_CTX,
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(rr, VMOD_DIRECTORS_RANDOM_MAGIC);
- vdir_remove_backend(rr->vd, be);
+ vdir_remove_backend(rr->vd, be, NULL);
}
VCL_BACKEND __match_proto__()
diff --git a/lib/libvmod_directors/round_robin.c b/lib/libvmod_directors/round_robin.c
index ef63bca..59f7332 100644
--- a/lib/libvmod_directors/round_robin.c
+++ b/lib/libvmod_directors/round_robin.c
@@ -127,7 +127,7 @@ vmod_round_robin_remove_backend(VRT_CTX,
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(rr, VMOD_DIRECTORS_ROUND_ROBIN_MAGIC);
- vdir_remove_backend(rr->vd, be);
+ vdir_remove_backend(rr->vd, be, NULL);
}
VCL_BACKEND __match_proto__()
diff --git a/lib/libvmod_directors/vdir.c b/lib/libvmod_directors/vdir.c
index c94b2ed..28f28f9 100644
--- a/lib/libvmod_directors/vdir.c
+++ b/lib/libvmod_directors/vdir.c
@@ -134,7 +134,7 @@ vdir_add_backend(struct vdir *vd, VCL_BACKEND be, double weight)
}
void
-vdir_remove_backend(struct vdir *vd, VCL_BACKEND be)
+vdir_remove_backend(struct vdir *vd, VCL_BACKEND be, unsigned *cur)
{
unsigned u, n;
@@ -155,6 +155,15 @@ vdir_remove_backend(struct vdir *vd, VCL_BACKEND be)
memmove(&vd->backend[u], &vd->backend[u+1], n * sizeof(vd->backend[0]));
memmove(&vd->weight[u], &vd->weight[u+1], n * sizeof(vd->weight[0]));
vd->n_backend--;
+
+ if (cur) {
+ assert(*cur >= 0);
+ assert(*cur <= vd->n_backend);
+ if (u < *cur)
+ (*cur)--;
+ else if (*cur == vd->n_backend)
+ *cur = 0;
+ }
vdir_unlock(vd);
}
diff --git a/lib/libvmod_directors/vdir.h b/lib/libvmod_directors/vdir.h
index eb4c6a8..0bdfb04 100644
--- a/lib/libvmod_directors/vdir.h
+++ b/lib/libvmod_directors/vdir.h
@@ -48,7 +48,7 @@ void vdir_rdlock(struct vdir *vd);
void vdir_wrlock(struct vdir *vd);
void vdir_unlock(struct vdir *vd);
unsigned vdir_add_backend(struct vdir *, VCL_BACKEND be, double weight);
-void vdir_remove_backend(struct vdir *, VCL_BACKEND be);
+void vdir_remove_backend(struct vdir *, VCL_BACKEND be, unsigned *cur);
unsigned vdir_any_healthy(struct vdir *, const struct busyobj *,
double *changed);
VCL_BACKEND vdir_pick_be(struct vdir *, double w, const struct busyobj *);
More information about the varnish-commit
mailing list