Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
401d1dd9
Commit
401d1dd9
authored
Apr 26, 2018
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make everybody use VRT_Healthy() and simplify backends as result.
parent
c25ed7e1
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
62 additions
and
60 deletions
+62
-60
cache_backend.c
bin/varnishd/cache/cache_backend.c
+1
-13
cache_director.c
bin/varnishd/cache/cache_director.c
+37
-36
cache_director.h
bin/varnishd/cache/cache_director.h
+0
-1
c00048.vtc
bin/varnishtest/tests/c00048.vtc
+7
-1
d00005.vtc
bin/varnishtest/tests/d00005.vtc
+6
-0
vrt.h
include/vrt.h
+3
-1
fall_back.c
lib/libvmod_directors/fall_back.c
+1
-1
round_robin.c
lib/libvmod_directors/round_robin.c
+1
-1
shard_dir.c
lib/libvmod_directors/shard_dir.c
+2
-2
vdir.c
lib/libvmod_directors/vdir.c
+3
-3
vmod_std.c
lib/libvmod_std/vmod_std.c
+1
-1
No files found.
bin/varnishd/cache/cache_backend.c
View file @
401d1dd9
...
...
@@ -88,7 +88,7 @@ vbe_dir_getfd(struct worker *wrk, struct backend *bp, struct busyobj *bo,
CHECK_OBJ_NOTNULL
(
bp
,
BACKEND_MAGIC
);
AN
(
bp
->
vsc
);
if
(
!
VDI_Healthy
(
bp
->
director
,
NULL
)
)
{
if
(
!
bp
->
director
->
health
)
{
VSLb
(
bo
->
vsl
,
SLT_FetchError
,
"backend %s: unhealthy"
,
bp
->
director
->
cli_name
);
// XXX: per backend stats ?
...
...
@@ -153,17 +153,6 @@ vbe_dir_getfd(struct worker *wrk, struct backend *bp, struct busyobj *bo,
return
(
pfd
);
}
static
VCL_BOOL
v_matchproto_
(
vdi_healthy_f
)
vbe_dir_healthy
(
VRT_CTX
,
VCL_BACKEND
d
,
VCL_TIME
*
changed
)
{
struct
backend
*
be
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
d
,
DIRECTOR_MAGIC
);
CAST_OBJ_NOTNULL
(
be
,
d
->
priv
,
BACKEND_MAGIC
);
return
(
VDI_Healthy
(
be
->
director
,
changed
));
}
static
void
v_matchproto_
(
vdi_finish_f
)
vbe_dir_finish
(
const
struct
director
*
d
,
struct
worker
*
wrk
,
struct
busyobj
*
bo
)
...
...
@@ -439,7 +428,6 @@ static const struct director_methods vbe_methods[1] = {{
.
magic
=
DIRECTOR_METHODS_MAGIC
,
.
type
=
"backend"
,
.
http1pipe
=
vbe_dir_http1pipe
,
.
healthy
=
vbe_dir_healthy
,
.
gethdrs
=
vbe_dir_gethdrs
,
.
getip
=
vbe_dir_getip
,
.
finish
=
vbe_dir_finish
,
...
...
bin/varnishd/cache/cache_director.c
View file @
401d1dd9
...
...
@@ -219,19 +219,32 @@ VDI_Http1Pipe(struct req *req, struct busyobj *bo)
* If director has no healthy method, we just assume it is healthy.
*/
int
VRT_Healthy
(
VRT_CTX
,
VCL_BACKEND
d
)
/*--------------------------------------------------------------------
* Test if backend is healthy and report when that last changed
*/
VCL_BOOL
VRT_Healthy
(
VRT_CTX
,
VCL_BACKEND
d
,
VCL_TIME
*
changed
)
{
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
if
(
d
==
NULL
)
return
(
0
);
CHECK_OBJ_NOTNULL
(
d
,
DIRECTOR_MAGIC
);
if
(
!
VDI_Healthy
(
d
,
NULL
))
return
(
0
);
if
(
d
->
methods
->
healthy
==
NULL
)
return
(
1
);
return
(
d
->
methods
->
healthy
(
ctx
,
d
,
NULL
));
if
(
d
->
admin_health
->
health
>=
0
)
{
if
(
changed
!=
NULL
)
*
changed
=
d
->
health_changed
;
return
(
d
->
admin_health
->
health
);
}
if
(
d
->
methods
->
healthy
==
NULL
)
{
if
(
changed
!=
NULL
)
*
changed
=
d
->
health_changed
;
return
(
d
->
health
);
}
return
(
d
->
methods
->
healthy
(
ctx
,
d
,
changed
));
}
/* Send Event ----------------------------------------------------------
...
...
@@ -270,24 +283,6 @@ VDI_Panic(const struct director *d, struct vsb *vsb, const char *nm)
VSB_printf
(
vsb
,
"},
\n
"
);
}
/*--------------------------------------------------------------------
* Test if backend is healthy and report when it last changed
*/
unsigned
VDI_Healthy
(
const
struct
director
*
d
,
double
*
changed
)
{
CHECK_OBJ_NOTNULL
(
d
,
DIRECTOR_MAGIC
);
AN
(
d
->
admin_health
);
if
(
changed
!=
NULL
)
*
changed
=
d
->
health_changed
;
if
(
d
->
admin_health
->
health
<
0
)
return
(
d
->
health
);
return
(
d
->
admin_health
->
health
);
}
/*---------------------------------------------------------------------*/
...
...
@@ -358,43 +353,49 @@ cli_backend_list(struct cli *cli, const char * const *av, void *priv)
/*---------------------------------------------------------------------*/
struct
set_health
{
unsigned
magic
;
#define SET_HEALTH_MAGIC 0x0c46b9fb
const
struct
vdi_ahealth
*
ah
;
};
static
int
v_matchproto_
(
vcl_be_func
)
do_set_health
(
struct
cli
*
cli
,
struct
director
*
d
,
void
*
priv
)
{
unsigned
prev
;
struct
set_health
*
sh
;
(
void
)
cli
;
AN
(
priv
);
CHECK_OBJ_NOTNULL
(
d
,
DIRECTOR_MAGIC
);
CAST_OBJ_NOTNULL
(
sh
,
priv
,
SET_HEALTH_MAGIC
);
if
(
d
->
admin_health
==
VDI_AH_DELETED
)
return
(
0
);
prev
=
VDI_Healthy
(
d
,
NULL
);
d
->
admin_health
=
*
(
const
struct
vdi_ahealth
**
)
priv
;
(
void
)
VDI_Ahealth
(
d
);
// Acts like type-check
if
(
prev
!=
VDI_Healthy
(
d
,
NULL
))
if
(
d
->
admin_health
!=
sh
->
ah
)
{
d
->
health_changed
=
VTIM_real
();
d
->
admin_health
=
sh
->
ah
;
d
->
health
=
sh
->
ah
->
health
?
1
:
0
;
}
return
(
0
);
}
static
void
v_matchproto_
()
cli_backend_set_health
(
struct
cli
*
cli
,
const
char
*
const
*
av
,
void
*
priv
)
{
const
struct
vdi_ahealth
*
ah
;
int
n
;
struct
set_health
sh
[
1
];
(
void
)
av
;
(
void
)
priv
;
ASSERT_CLI
();
AN
(
av
[
2
]);
AN
(
av
[
3
]);
ah
=
vdi_str2ahealth
(
av
[
3
]);
if
(
ah
==
NULL
||
ah
==
VDI_AH_DELETED
)
{
INIT_OBJ
(
sh
,
SET_HEALTH_MAGIC
);
sh
->
ah
=
vdi_str2ahealth
(
av
[
3
]);
if
(
sh
->
ah
==
NULL
||
sh
->
ah
==
VDI_AH_DELETED
)
{
VCLI_Out
(
cli
,
"Invalid state %s"
,
av
[
3
]);
VCLI_SetResult
(
cli
,
CLIS_PARAM
);
return
;
}
n
=
VCL_IterDirector
(
cli
,
av
[
2
],
do_set_health
,
&
a
h
);
n
=
VCL_IterDirector
(
cli
,
av
[
2
],
do_set_health
,
s
h
);
if
(
n
==
0
)
{
VCLI_Out
(
cli
,
"No Backends matches"
);
VCLI_SetResult
(
cli
,
CLIS_PARAM
);
...
...
bin/varnishd/cache/cache_director.h
View file @
401d1dd9
...
...
@@ -99,7 +99,6 @@ struct director {
double
health_changed
;
};
unsigned
VDI_Healthy
(
const
struct
director
*
,
double
*
);
/* cache_vcl.c */
int
VRT_AddDirector
(
VRT_CTX
,
struct
director
*
,
const
char
*
);
...
...
bin/varnishtest/tests/c00048.vtc
View file @
401d1dd9
...
...
@@ -23,7 +23,7 @@ varnish v1 -vcl {
} -start
delay 1
varnish v1 -vsl_catchup
varnish v1 -cliok "vcl.list"
varnish v1 -cliok "backend.list -p"
...
...
@@ -36,6 +36,8 @@ client c1 {
expect resp.status == 200
} -run
varnish v1 -vsl_catchup
varnish v1 -cliok "backend.list"
varnish v1 -cliok "backend.set_health s1 sick"
varnish v1 -cliok "backend.list"
...
...
@@ -46,6 +48,8 @@ client c1 {
expect resp.status == 503
} -run
varnish v1 -vsl_catchup
varnish v1 -cliok "backend.list"
varnish v1 -cliok "backend.set_health s1 healthy"
varnish v1 -cliok "backend.list"
...
...
@@ -56,6 +60,8 @@ client c1 {
expect resp.status == 200
} -run
varnish v1 -vsl_catchup
varnish v1 -clierr 106 "backend.set_health s1 foo"
varnish v1 -clierr 106 "backend.set_health s2 foo"
varnish v1 -clierr 106 "backend.set_health s2 auto"
...
...
bin/varnishtest/tests/d00005.vtc
View file @
401d1dd9
...
...
@@ -61,7 +61,10 @@ client c1 {
expect resp.body == "22"
} -run
varnish v1 -vsl_catchup
varnish v1 -cliok "backend.set_health s1 sick"
varnish v1 -cliok "backend.list"
client c1 {
txreq
...
...
@@ -72,7 +75,10 @@ client c1 {
expect resp.body == "22"
} -run
varnish v1 -vsl_catchup
varnish v1 -cliok "backend.set_health s2 sick"
varnish v1 -cliok "backend.list"
client c1 {
txreq
...
...
include/vrt.h
View file @
401d1dd9
...
...
@@ -52,6 +52,8 @@
* binary/load-time compatible, increment MAJOR version
*
*
* TRUNK (2018-09-15)
* VRT_Healthy() changed prototype
* 7.0 (2018-03-15)
* lots of stuff moved from cache.h to cache_varnishd.h
* (ie: from "$Abi vrt" to "$Abi strict")
...
...
@@ -416,7 +418,7 @@ struct vsmw_cluster *VRT_VSM_Cluster_New(VRT_CTX, size_t);
void
VRT_VSM_Cluster_Destroy
(
VRT_CTX
,
struct
vsmw_cluster
**
);
/* cache_director.c */
int
VRT_Healthy
(
VRT_CTX
,
VCL_BACKEND
);
VCL_BOOL
VRT_Healthy
(
VRT_CTX
,
VCL_BACKEND
,
VCL_TIME
*
);
/* Suckaddr related */
int
VRT_VSA_GetPtr
(
const
struct
suckaddr
*
sua
,
const
unsigned
char
**
dst
);
...
...
lib/libvmod_directors/fall_back.c
View file @
401d1dd9
...
...
@@ -74,7 +74,7 @@ vmod_fallback_resolve(VRT_CTX, VCL_BACKEND dir)
for
(
u
=
0
;
u
<
fb
->
vd
->
n_backend
;
u
++
)
{
be
=
fb
->
vd
->
backend
[
fb
->
cur
];
CHECK_OBJ_NOTNULL
(
be
,
DIRECTOR_MAGIC
);
if
(
be
->
methods
->
h
ealthy
(
ctx
,
be
,
NULL
))
if
(
VRT_H
ealthy
(
ctx
,
be
,
NULL
))
break
;
if
(
++
fb
->
cur
==
fb
->
vd
->
n_backend
)
fb
->
cur
=
0
;
...
...
lib/libvmod_directors/round_robin.c
View file @
401d1dd9
...
...
@@ -73,7 +73,7 @@ vmod_rr_resolve(VRT_CTX, VCL_BACKEND dir)
rr
->
nxt
=
nxt
+
1
;
be
=
rr
->
vd
->
backend
[
nxt
];
CHECK_OBJ_NOTNULL
(
be
,
DIRECTOR_MAGIC
);
if
(
be
->
methods
->
h
ealthy
(
ctx
,
be
,
NULL
))
if
(
VRT_H
ealthy
(
ctx
,
be
,
NULL
))
break
;
}
vdir_unlock
(
rr
->
vd
);
...
...
lib/libvmod_directors/shard_dir.c
View file @
401d1dd9
...
...
@@ -189,7 +189,7 @@ shard_next(struct shard_state *state, VCL_INT skip, VCL_BOOL healthy)
sbe
=
NULL
;
be
=
state
->
shardd
->
backend
[
c
].
backend
;
AN
(
be
);
if
(
be
->
methods
->
h
ealthy
(
state
->
ctx
,
be
,
&
changed
))
{
if
(
VRT_H
ealthy
(
state
->
ctx
,
be
,
&
changed
))
{
if
(
skip
--
==
0
)
{
chosen
=
c
;
sbe
=
&
state
->
last
;
...
...
@@ -324,7 +324,7 @@ sharddir_any_healthy(VRT_CTX, struct sharddir *shardd, VCL_TIME *changed)
for
(
u
=
0
;
u
<
shardd
->
n_backend
;
u
++
)
{
be
=
shardd
->
backend
[
u
].
backend
;
CHECK_OBJ_NOTNULL
(
be
,
DIRECTOR_MAGIC
);
retval
=
be
->
methods
->
h
ealthy
(
ctx
,
be
,
&
c
);
retval
=
VRT_H
ealthy
(
ctx
,
be
,
&
c
);
if
(
changed
!=
NULL
&&
c
>
*
changed
)
*
changed
=
c
;
if
(
retval
)
...
...
lib/libvmod_directors/vdir.c
View file @
401d1dd9
...
...
@@ -70,7 +70,7 @@ vdir_new(VRT_CTX, struct vdir **vdp, const char *vcl_name,
vd
->
dir
->
methods
=
m
;
REPLACE
(
vd
->
dir
->
vcl_name
,
vcl_name
);
vd
->
dir
->
priv
=
priv
;
vd
->
dir
->
admin_health
=
VDI_AH_
HEALTHY
;
vd
->
dir
->
admin_health
=
VDI_AH_
PROBE
;
vd
->
vbm
=
vbit_new
(
8
);
AN
(
vd
->
vbm
);
}
...
...
@@ -188,7 +188,7 @@ vdir_any_healthy(VRT_CTX, struct vdir *vd, VCL_TIME *changed)
for
(
u
=
0
;
u
<
vd
->
n_backend
;
u
++
)
{
be
=
vd
->
backend
[
u
];
CHECK_OBJ_NOTNULL
(
be
,
DIRECTOR_MAGIC
);
retval
=
be
->
methods
->
h
ealthy
(
ctx
,
be
,
&
c
);
retval
=
VRT_H
ealthy
(
ctx
,
be
,
&
c
);
if
(
changed
!=
NULL
&&
c
>
*
changed
)
*
changed
=
c
;
if
(
retval
)
...
...
@@ -230,7 +230,7 @@ vdir_pick_be(VRT_CTX, struct vdir *vd, double w)
CHECK_OBJ_NOTNULL
(
vd
,
VDIR_MAGIC
);
vdir_wrlock
(
vd
);
for
(
u
=
0
;
u
<
vd
->
n_backend
;
u
++
)
{
if
(
vd
->
backend
[
u
]
->
methods
->
h
ealthy
(
ctx
,
vd
->
backend
[
u
],
NULL
))
{
if
(
VRT_H
ealthy
(
ctx
,
vd
->
backend
[
u
],
NULL
))
{
vbit_clr
(
vd
->
vbm
,
u
);
tw
+=
vd
->
weight
[
u
];
}
else
...
...
lib/libvmod_std/vmod_std.c
View file @
401d1dd9
...
...
@@ -209,7 +209,7 @@ vmod_healthy(VRT_CTX, VCL_BACKEND be)
{
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_ORNULL
(
be
,
DIRECTOR_MAGIC
);
return
(
VRT_Healthy
(
ctx
,
be
));
return
(
VRT_Healthy
(
ctx
,
be
,
NULL
));
}
VCL_INT
v_matchproto_
(
td_std_port
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment