Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-weightadjust
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
libvmod-weightadjust
Commits
cc0b38df
Commit
cc0b38df
authored
Mar 26, 2019
by
Nils Goroll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adjust to 6.1
parent
f0389d8a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
74 additions
and
56 deletions
+74
-56
README.rst
README.rst
+1
-1
configure.ac
configure.ac
+1
-1
random.c
src/random.c
+33
-17
vdir.c
src/vdir.c
+28
-25
vdir.h
src/vdir.h
+7
-8
vmod_weightadjust.c
src/vmod_weightadjust.c
+4
-4
No files found.
README.rst
View file @
cc0b38df
...
...
@@ -2,7 +2,7 @@
vmod-weightadjust
============
This version is for varnish 6.
0
This version is for varnish 6.
1
SYNOPSIS
========
...
...
configure.ac
View file @
cc0b38df
...
...
@@ -28,7 +28,7 @@ AC_ARG_WITH([rst2man],
m4_ifndef([VARNISH_PREREQ], AC_MSG_ERROR([Need varnish.m4 -- see README.rst]))
VARNISH_PREREQ([6.
0
])
VARNISH_PREREQ([6.
1
])
VARNISH_VMODS([weightadjust])
VMOD_TESTS="$(cd $srcdir/src && echo tests/*.vtc)"
...
...
src/random.c
View file @
cc0b38df
...
...
@@ -46,34 +46,52 @@
#define vmod_random__init _vmod_random__init
#define vmod_random__fini _vmod_random__fini
static
unsigned
vmod_random_healthy
(
const
struct
director
*
dir
,
const
struct
busyobj
*
bo
,
double
*
changed
)
static
VCL_BOOL
vmod_random_healthy
(
VRT_CTX
,
VCL_BACKEND
dir
,
VCL_TIME
*
changed
)
{
struct
vmod_directors_random
*
rr
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
dir
,
DIRECTOR_MAGIC
);
CAST_OBJ_NOTNULL
(
rr
,
dir
->
priv
,
VMOD_DIRECTORS_RANDOM_MAGIC
);
return
(
vdir_any_healthy
(
rr
->
vd
,
bo
,
changed
));
return
(
vdir_any_healthy
(
ctx
,
rr
->
vd
,
changed
));
}
static
const
struct
director
*
vmod_random_resolve
(
const
struct
director
*
dir
,
struct
worker
*
wrk
,
struct
busyobj
*
bo
)
static
VCL_BACKEND
vmod_random_resolve
(
VRT_CTX
,
VCL_BACKEND
dir
)
{
struct
vmod_directors_random
*
rr
;
VCL_BACKEND
be
;
double
r
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
dir
,
DIRECTOR_MAGIC
);
CHECK_OBJ_NOTNULL
(
wrk
,
WORKER_MAGIC
);
CHECK_OBJ_NOTNULL
(
bo
,
BUSYOBJ_MAGIC
);
CAST_OBJ_NOTNULL
(
rr
,
dir
->
priv
,
VMOD_DIRECTORS_RANDOM_MAGIC
);
r
=
scalbn
(
VRND_RandomTestable
(),
-
31
);
assert
(
r
>=
0
&&
r
<
1
.
0
);
be
=
vdir_pick_be
(
rr
->
vd
,
r
,
bo
);
be
=
vdir_pick_be
(
ctx
,
rr
->
vd
,
r
);
return
(
be
);
}
static
void
v_matchproto_
(
vdi_destroy_f
)
vmod_random_destroy
(
VCL_BACKEND
dir
)
{
struct
vmod_directors_random
*
rr
;
CAST_OBJ_NOTNULL
(
rr
,
dir
->
priv
,
VMOD_DIRECTORS_RANDOM_MAGIC
);
vdir_delete
(
&
rr
->
vd
);
FREE_OBJ
(
rr
);
}
static
const
struct
vdi_methods
vmod_random_methods
[
1
]
=
{{
.
magic
=
VDI_METHODS_MAGIC
,
.
type
=
"random"
,
.
healthy
=
vmod_random_healthy
,
.
resolve
=
vmod_random_resolve
,
.
destroy
=
vmod_random_destroy
}};
VCL_VOID
vmod_random__init
(
VRT_CTX
,
struct
vmod_directors_random
**
rrp
,
const
char
*
vcl_name
)
...
...
@@ -86,8 +104,7 @@ vmod_random__init(VRT_CTX, struct vmod_directors_random **rrp,
ALLOC_OBJ
(
rr
,
VMOD_DIRECTORS_RANDOM_MAGIC
);
AN
(
rr
);
*
rrp
=
rr
;
vdir_new
(
&
rr
->
vd
,
"random"
,
vcl_name
,
vmod_random_healthy
,
vmod_random_resolve
,
rr
);
vdir_new
(
ctx
,
&
rr
->
vd
,
vcl_name
,
vmod_random_methods
,
rr
);
}
VCL_VOID
...
...
@@ -100,8 +117,7 @@ vmod_random__fini(struct vmod_directors_random **rrp)
return
;
TAKE_OBJ_NOTNULL
(
rr
,
rrp
,
VMOD_DIRECTORS_RANDOM_MAGIC
);
vdir_delete
(
&
rr
->
vd
);
FREE_OBJ
(
rr
);
VRT_DelDirector
(
&
rr
->
vd
->
dir
);
}
#ifdef UNUSED
...
...
@@ -112,15 +128,15 @@ vmod_random_add_backend(VRT_CTX,
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
rr
,
VMOD_DIRECTORS_RANDOM_MAGIC
);
(
void
)
vdir_add_backend
(
rr
->
vd
,
be
,
w
);
vdir_add_backend
(
ctx
,
rr
->
vd
,
be
,
w
);
}
VCL_VOID
vmod_random_remove_backend
(
VRT_CTX
,
struct
vmod_directors_random
*
rr
,
VCL_BACKEND
be
)
struct
vmod_directors_random
*
rr
,
VCL_BACKEND
be
)
v_matchproto_
()
{
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
rr
,
VMOD_DIRECTORS_RANDOM_MAGIC
);
vdir_remove_backend
(
rr
->
vd
,
be
,
NULL
);
vdir_remove_backend
(
ctx
,
rr
->
vd
,
be
,
NULL
);
}
#endif
...
...
src/vdir.c
View file @
cc0b38df
...
...
@@ -31,7 +31,6 @@
#include <stdlib.h>
#include "cache/cache.h"
#include "cache/cache_director.h"
#include "vbm.h"
...
...
@@ -50,12 +49,13 @@ vdir_expand(struct vdir *vd, unsigned n)
}
void
vdir_new
(
struct
vdir
**
vdp
,
const
char
*
name
,
const
char
*
vcl_name
,
vdi_healthy_f
*
healthy
,
vdi_resolve_f
*
resolve
,
void
*
priv
)
vdir_new
(
VRT_CTX
,
struct
vdir
**
vdp
,
const
char
*
vcl_name
,
const
struct
vdi_methods
*
m
,
void
*
priv
)
{
struct
vdir
*
vd
;
AN
(
name
);
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
m
,
VDI_METHODS_MAGIC
);
AN
(
vcl_name
);
AN
(
vdp
);
AZ
(
*
vdp
);
...
...
@@ -63,14 +63,7 @@ vdir_new(struct vdir **vdp, const char *name, const char *vcl_name,
AN
(
vd
);
*
vdp
=
vd
;
AZ
(
pthread_rwlock_init
(
&
vd
->
mtx
,
NULL
));
ALLOC_OBJ
(
vd
->
dir
,
DIRECTOR_MAGIC
);
AN
(
vd
->
dir
);
vd
->
dir
->
name
=
name
;
REPLACE
(
vd
->
dir
->
vcl_name
,
vcl_name
);
vd
->
dir
->
priv
=
priv
;
vd
->
dir
->
healthy
=
healthy
;
vd
->
dir
->
resolve
=
resolve
;
vd
->
dir
=
VRT_AddDirector
(
ctx
,
m
,
priv
,
"%s"
,
vcl_name
);
vd
->
vbm
=
vbit_new
(
8
);
AN
(
vd
->
vbm
);
}
...
...
@@ -82,11 +75,10 @@ vdir_delete(struct vdir **vdp)
TAKE_OBJ_NOTNULL
(
vd
,
vdp
,
VDIR_MAGIC
);
AZ
(
vd
->
dir
);
free
(
vd
->
backend
);
free
(
vd
->
weight
);
AZ
(
pthread_rwlock_destroy
(
&
vd
->
mtx
));
free
(
vd
->
dir
->
vcl_name
);
FREE_OBJ
(
vd
->
dir
);
vbit_destroy
(
vd
->
vbm
);
FREE_OBJ
(
vd
);
}
...
...
@@ -113,12 +105,18 @@ vdir_unlock(struct vdir *vd)
}
unsigne
d
vdir_add_backend
(
struct
vdir
*
vd
,
VCL_BACKEND
be
,
double
weight
)
voi
d
vdir_add_backend
(
VRT_CTX
,
struct
vdir
*
vd
,
VCL_BACKEND
be
,
double
weight
)
{
unsigned
u
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
vd
,
VDIR_MAGIC
);
if
(
be
==
NULL
)
{
VRT_fail
(
ctx
,
"%s: NULL backend cannot be added"
,
VRT_BACKEND_string
(
vd
->
dir
));
return
;
}
AN
(
be
);
vdir_wrlock
(
vd
);
if
(
vd
->
n_backend
>=
vd
->
l_backend
)
...
...
@@ -129,17 +127,20 @@ vdir_add_backend(struct vdir *vd, VCL_BACKEND be, double weight)
vd
->
weight
[
u
]
=
weight
;
vd
->
total_weight
+=
weight
;
vdir_unlock
(
vd
);
return
(
u
);
}
void
vdir_remove_backend
(
struct
vdir
*
vd
,
VCL_BACKEND
be
,
unsigned
*
cur
)
vdir_remove_backend
(
VRT_CTX
,
struct
vdir
*
vd
,
VCL_BACKEND
be
,
unsigned
*
cur
)
{
unsigned
u
,
n
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
vd
,
VDIR_MAGIC
);
if
(
be
==
NULL
)
if
(
be
==
NULL
)
{
VRT_fail
(
ctx
,
"%s: NULL backend cannot be removed"
,
VRT_BACKEND_string
(
vd
->
dir
));
return
;
}
CHECK_OBJ
(
be
,
DIRECTOR_MAGIC
);
vdir_wrlock
(
vd
);
for
(
u
=
0
;
u
<
vd
->
n_backend
;
u
++
)
...
...
@@ -165,23 +166,23 @@ vdir_remove_backend(struct vdir *vd, VCL_BACKEND be, unsigned *cur)
vdir_unlock
(
vd
);
}
unsigned
vdir_any_healthy
(
struct
vdir
*
vd
,
const
struct
busyobj
*
bo
,
double
*
changed
)
VCL_BOOL
vdir_any_healthy
(
VRT_CTX
,
struct
vdir
*
vd
,
VCL_TIME
*
changed
)
{
unsigned
retval
=
0
;
VCL_BACKEND
be
;
unsigned
u
;
double
c
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
vd
,
VDIR_MAGIC
);
CHECK_OBJ_ORNULL
(
bo
,
BUSYOBJ_MAGIC
);
vdir_rdlock
(
vd
);
if
(
changed
!=
NULL
)
*
changed
=
0
;
for
(
u
=
0
;
u
<
vd
->
n_backend
;
u
++
)
{
be
=
vd
->
backend
[
u
];
CHECK_OBJ_NOTNULL
(
be
,
DIRECTOR_MAGIC
);
retval
=
be
->
healthy
(
be
,
bo
,
&
c
);
retval
=
VRT_Healthy
(
ctx
,
be
,
&
c
);
if
(
changed
!=
NULL
&&
c
>
*
changed
)
*
changed
=
c
;
if
(
retval
)
...
...
@@ -213,15 +214,17 @@ vdir_pick_by_weight(const struct vdir *vd, double w,
}
VCL_BACKEND
vdir_pick_be
(
struct
vdir
*
vd
,
double
w
,
const
struct
busyobj
*
bo
)
vdir_pick_be
(
VRT_CTX
,
struct
vdir
*
vd
,
double
w
)
{
unsigned
u
;
double
tw
=
0
.
0
;
VCL_BACKEND
be
=
NULL
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
vd
,
VDIR_MAGIC
);
vdir_wrlock
(
vd
);
for
(
u
=
0
;
u
<
vd
->
n_backend
;
u
++
)
{
if
(
vd
->
backend
[
u
]
->
healthy
(
vd
->
backend
[
u
],
bo
,
NULL
))
{
if
(
VRT_Healthy
(
ctx
,
vd
->
backend
[
u
]
,
NULL
))
{
vbit_clr
(
vd
->
vbm
,
u
);
tw
+=
vd
->
weight
[
u
];
}
else
...
...
src/vdir.h
View file @
cc0b38df
...
...
@@ -37,18 +37,17 @@ struct vdir {
VCL_BACKEND
*
backend
;
double
*
weight
;
double
total_weight
;
struct
director
*
dir
;
VCL_BACKEND
dir
;
struct
vbitmap
*
vbm
;
};
void
vdir_new
(
struct
vdir
**
vdp
,
const
char
*
name
,
const
char
*
vcl_name
,
vdi_healthy_f
*
healthy
,
vdi_resolve_f
*
resolve
,
void
*
priv
);
void
vdir_new
(
VRT_CTX
,
struct
vdir
**
vdp
,
const
char
*
vcl_name
,
const
struct
vdi_methods
*
,
void
*
priv
);
void
vdir_delete
(
struct
vdir
**
vdp
);
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
,
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
*
);
void
vdir_add_backend
(
VRT_CTX
,
struct
vdir
*
,
VCL_BACKEND
,
double
weight
);
void
vdir_remove_backend
(
VRT_CTX
,
struct
vdir
*
,
VCL_BACKEND
,
unsigned
*
cur
);
VCL_BOOL
vdir_any_healthy
(
VRT_CTX
,
struct
vdir
*
,
VCL_TIME
*
);
VCL_BACKEND
vdir_pick_be
(
VRT_CTX
,
struct
vdir
*
,
double
w
);
src/vmod_weightadjust.c
View file @
cc0b38df
...
...
@@ -153,7 +153,7 @@ wadj_cfg_re(VRT_CTX, struct vmod_weightadjust_random *rr, VCL_BACKEND be,
if
(
vre
==
NULL
)
{
VERR
(
ctx
,
"%s.%s regex errror (%s) for %s pos %d"
,
rr
->
vd
->
dir
->
vcl_name
,
be
->
name
,
err
,
rr
->
vd
->
dir
->
vcl_name
,
be
->
vcl_
name
,
err
,
weight_update
,
erroff
);
}
...
...
@@ -271,7 +271,7 @@ vmod_random_add_backend(VRT_CTX, struct vmod_weightadjust_random *rr,
msg
(
ctx
,
0
,
"vmod weightadjust director %s "
"add_backend(%s) without weight update falls back "
"to standard behaviour"
,
rr
->
vd
->
dir
->
vcl_name
,
vcl_be
->
name
);
rr
->
vd
->
dir
->
vcl_name
,
vcl_be
->
vcl_
name
);
goto
no_weightadjust
;
}
...
...
@@ -321,7 +321,7 @@ vmod_random_add_backend(VRT_CTX, struct vmod_weightadjust_random *rr,
AZ
(
pthread_mutex_unlock
(
&
wa_vcl
->
mtx
));
no_weightadjust:
vdir_add_backend
(
rr
->
vd
,
vcl_be
,
w
);
vdir_add_backend
(
ctx
,
rr
->
vd
,
vcl_be
,
w
);
return
;
err:
...
...
@@ -374,5 +374,5 @@ vmod_random_remove_backend(VRT_CTX,
vdir_unlock
(
rr
->
vd
);
no_weightadjust:
vdir_remove_backend
(
rr
->
vd
,
vcl_be
,
NULL
);
vdir_remove_backend
(
ctx
,
rr
->
vd
,
vcl_be
,
NULL
);
}
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