Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
unique-xids
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
unique-xids
Commits
9aab053b
Commit
9aab053b
authored
Mar 06, 2013
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a proof-of-concept round-robin director as a VMOD object
parent
8d9597e1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
157 additions
and
0 deletions
+157
-0
m00009.vtc
bin/varnishtest/tests/m00009.vtc
+69
-0
vmod.vcc
lib/libvmod_debug/vmod.vcc
+5
-0
vmod_debug_obj.c
lib/libvmod_debug/vmod_debug_obj.c
+83
-0
No files found.
bin/varnishtest/tests/m00009.vtc
0 → 100644
View file @
9aab053b
varnishtest "Test vmod.debug round robin director"
server s1 {
rxreq
txresp -body "1"
} -start
server s2 {
rxreq
txresp -body "22"
} -start
server s3 {
rxreq
txresp -body "333"
} -start
server s4 {
rxreq
txresp -body "4444"
} -start
varnish v1 -vcl+backend {
import debug from "${topbuild}/lib/libvmod_debug/.libs/libvmod_debug.so" ;
sub vcl_init {
new rr = debug.rr();
rr.add_backend(s1);
rr.add_backend(s2);
rr.add_backend(s3);
rr.add_backend(s4);
}
sub vcl_recv {
set req.backend = rr.select();
}
} -start
client c1 {
timeout 3
txreq -url "/foo1"
rxresp
expect resp.bodylen == 1
txreq -url "/foo2"
rxresp
expect resp.bodylen == 2
txreq -url "/foo3"
rxresp
expect resp.bodylen == 3
txreq -url "/foo4"
rxresp
expect resp.bodylen == 4
} -run
server s1 -start
server s2 -start
client c2 {
timeout 3
txreq -url "/foo11"
rxresp
expect resp.bodylen == 1
txreq -url "/foo22"
rxresp
expect resp.bodylen == 2
} -run
lib/libvmod_debug/vmod.vcc
View file @
9aab053b
...
...
@@ -35,3 +35,8 @@ Object obj(STRING) {
Method STRING .foo(STRING why)
Method TIME .date()
}
Object rr() {
Method VOID .add_backend(BACKEND)
Method BACKEND .select()
}
lib/libvmod_debug/vmod_debug_obj.c
View file @
9aab053b
...
...
@@ -86,3 +86,86 @@ vmod_obj_date(struct req *req, struct vmod_debug_obj *o)
assert
(
o
->
foobar
==
42
);
return
(
21
.
4
);
}
/*----------------------------------------------------------------------*/
struct
vmod_debug_rr_entry
{
unsigned
magic
;
#define VMOD_DEBUG_RR_ENTRY_MAGIC 0xa80970cf
VTAILQ_ENTRY
(
vmod_debug_rr_entry
)
list
;
VCL_BACKEND
be
;
};
struct
vmod_debug_rr
{
unsigned
magic
;
#define VMOD_DEBUG_RR_MAGIC 0x99f4b726
VTAILQ_HEAD
(,
vmod_debug_rr_entry
)
listhead
;
pthread_mutex_t
mtx
;
};
VCL_VOID
vmod_rr__init
(
struct
req
*
req
,
struct
vmod_debug_rr
**
rrp
)
{
struct
vmod_debug_rr
*
rr
;
(
void
)
req
;
AN
(
rrp
);
AZ
(
*
rrp
);
ALLOC_OBJ
(
rr
,
VMOD_DEBUG_RR_MAGIC
);
AN
(
rr
);
*
rrp
=
rr
;
AZ
(
pthread_mutex_init
(
&
rr
->
mtx
,
NULL
));
VTAILQ_INIT
(
&
rr
->
listhead
);
}
VCL_VOID
vmod_rr__fini
(
struct
req
*
req
,
struct
vmod_debug_rr
**
rrp
)
{
struct
vmod_debug_rr
*
rr
;
struct
vmod_debug_rr_entry
*
ep
;
(
void
)
req
;
rr
=
*
rrp
;
*
rrp
=
NULL
;
CHECK_OBJ_NOTNULL
(
rr
,
VMOD_DEBUG_RR_MAGIC
);
AZ
(
pthread_mutex_destroy
(
&
rr
->
mtx
));
while
(
!
VTAILQ_EMPTY
(
&
rr
->
listhead
))
{
ep
=
VTAILQ_FIRST
(
&
rr
->
listhead
);
VTAILQ_REMOVE
(
&
rr
->
listhead
,
ep
,
list
);
FREE_OBJ
(
ep
);
}
FREE_OBJ
(
*
rrp
);
}
VCL_VOID
vmod_rr_add_backend
(
struct
req
*
req
,
struct
vmod_debug_rr
*
rr
,
VCL_BACKEND
be
)
{
struct
vmod_debug_rr_entry
*
ep
;
(
void
)
req
;
ALLOC_OBJ
(
ep
,
VMOD_DEBUG_RR_ENTRY_MAGIC
);
AN
(
ep
);
ep
->
be
=
be
;
AZ
(
pthread_mutex_lock
(
&
rr
->
mtx
));
VTAILQ_INSERT_TAIL
(
&
rr
->
listhead
,
ep
,
list
);
AZ
(
pthread_mutex_unlock
(
&
rr
->
mtx
));
}
VCL_BACKEND
vmod_rr_select
(
struct
req
*
req
,
struct
vmod_debug_rr
*
rr
)
{
struct
vmod_debug_rr_entry
*
ep
;
(
void
)
req
;
CHECK_OBJ_NOTNULL
(
rr
,
VMOD_DEBUG_RR_MAGIC
);
AZ
(
pthread_mutex_lock
(
&
rr
->
mtx
));
ep
=
VTAILQ_FIRST
(
&
rr
->
listhead
);
VTAILQ_REMOVE
(
&
rr
->
listhead
,
ep
,
list
);
VTAILQ_INSERT_TAIL
(
&
rr
->
listhead
,
ep
,
list
);
AZ
(
pthread_mutex_unlock
(
&
rr
->
mtx
));
return
(
ep
->
be
);
}
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