[master] 351e100 Add BOOL std.healthy(BACKEND) which can check if any backend is healthy, rather than have hardcoded variables for req.backend and bereq.backend's health.
Poul-Henning Kamp
phk at varnish-cache.org
Fri Nov 22 15:21:12 CET 2013
commit 351e100e084fae8dd0db2c46badc9be38c48bd1b
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Fri Nov 22 14:20:09 2013 +0000
Add BOOL std.healthy(BACKEND) which can check if any backend is
healthy, rather than have hardcoded variables for
req.backend and bereq.backend's health.
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 250cb85..5a80ff0 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -328,22 +328,6 @@ REQ_VAR_R(backend, director, struct director *)
REQ_VAR_L(ttl, d_ttl, double, if (!(arg>0.0)) arg = 0;)
REQ_VAR_R(ttl, d_ttl, double)
-unsigned
-VRT_r_req_backend_healthy(const struct vrt_ctx *ctx)
-{
-
- CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
- CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
- /*
- * XXX: Not optimal, but we do not have a backend in vcl_deliver
- * XXX: and we have to return something.
- */
- if (ctx->req->director == NULL)
- return (0);
- CHECK_OBJ_NOTNULL(ctx->req->director, DIRECTOR_MAGIC);
- return (VDI_Healthy(ctx->req->director));
-}
-
/*--------------------------------------------------------------------*/
void
@@ -366,16 +350,6 @@ VRT_r_bereq_backend(const struct vrt_ctx *ctx)
return (ctx->bo->director);
}
-unsigned
-VRT_r_bereq_backend_healthy(const struct vrt_ctx *ctx)
-{
-
- CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
- CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
- CHECK_OBJ_NOTNULL(ctx->bo->director, DIRECTOR_MAGIC);
- return (VDI_Healthy(ctx->bo->director));
-}
-
/*--------------------------------------------------------------------*/
void
diff --git a/bin/varnishtest/tests/r01228.vcl b/bin/varnishtest/tests/r01228.vcl
index 55d5689..1cb7e01 100644
--- a/bin/varnishtest/tests/r01228.vcl
+++ b/bin/varnishtest/tests/r01228.vcl
@@ -6,8 +6,11 @@ server s1 {
} -start
varnish v1 -vcl+backend {
+
+ import ${vmod_std};
+
sub vcl_deliver {
- set resp.http.x-foo = req.backend.healthy;
+ set resp.http.x-foo = std.healthy(req.backend);
}
} -start
diff --git a/bin/varnishtest/tests/v00014.vtc b/bin/varnishtest/tests/v00014.vtc
index 5477a98..67d3431 100644
--- a/bin/varnishtest/tests/v00014.vtc
+++ b/bin/varnishtest/tests/v00014.vtc
@@ -8,6 +8,8 @@ server s1 {
varnish v1 -vcl {
+ import ${vmod_std};
+
probe foo {
.url = "/";
.timeout = 1s;
@@ -25,7 +27,7 @@ varnish v1 -vcl {
}
sub vcl_recv {
- if (req.backend.healthy) {
+ if (std.healthy(req.backend)) {
return(error(200,"Backend healthy"));
} else {
return(error(500,"Backend sick"));
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index 9a00c37..a41c246 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -229,13 +229,6 @@ The client's IP address.
The backend to use to service the request.
"""
),
- ('req.backend.healthy',
- 'BOOL',
- ( 'client',),
- ( ), """
- XXX: remove: foo.healthy()
- """
- ),
('req.hash_ignore_busy',
'BOOL',
( 'recv',),
@@ -266,13 +259,6 @@ The client's IP address.
( 'pipe', 'backend', ), """
"""
),
- ('bereq.backend.healthy',
- 'BOOL',
- ( 'pipe', 'backend', ),
- ( ), """
- XXX: remove: foo.healthy()
- """
- ),
('bereq.method',
'STRING',
( 'pipe', 'backend', ),
diff --git a/lib/libvmod_std/vmod.vcc b/lib/libvmod_std/vmod.vcc
index 1f4e33e..f07b8c2 100644
--- a/lib/libvmod_std/vmod.vcc
+++ b/lib/libvmod_std/vmod.vcc
@@ -37,3 +37,4 @@ Function DURATION duration(STRING, DURATION)
Function INT integer(STRING, INT)
Function VOID collect(HEADER)
Function IP ip(STRING, IP)
+Function BOOL healthy(BACKEND)
diff --git a/lib/libvmod_std/vmod_std.c b/lib/libvmod_std/vmod_std.c
index c865494..9d20b95 100644
--- a/lib/libvmod_std/vmod_std.c
+++ b/lib/libvmod_std/vmod_std.c
@@ -42,6 +42,7 @@
#include "vtcp.h"
#include "cache/cache.h"
+#include "cache/cache_backend.h"
#include "vcc_if.h"
@@ -183,3 +184,13 @@ vmod_collect(const struct vrt_ctx *ctx, VCL_HEADER hdr)
http_CollectHdr(ctx->http_resp, hdr->what);
}
}
+
+VCL_BOOL __match_proto__(td_std_healthy)
+vmod_healthy(const struct vrt_ctx *ctx, VCL_BACKEND be)
+{
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+ if (be == NULL)
+ return (0);
+ CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC);
+ return (VDI_Healthy(be));
+}
More information about the varnish-commit
mailing list