[6.0] 13a03e3a1 Allow shard.reconfigure() to work on empty directors
Reza Naghibi
reza at naghibi.com
Tue Apr 20 18:32:06 UTC 2021
commit 13a03e3a105d4b71efee4b0e50e647a4e6d79980
Author: Reza Naghibi <reza at naghibi.com>
Date: Thu Apr 15 10:58:00 2021 -0400
Allow shard.reconfigure() to work on empty directors
Also move the lock up to cover more operations.
diff --git a/bin/varnishtest/tests/d06001.vtc b/bin/varnishtest/tests/d06001.vtc
new file mode 100644
index 000000000..592f3da93
--- /dev/null
+++ b/bin/varnishtest/tests/d06001.vtc
@@ -0,0 +1,30 @@
+varnishtest "Empty shard reconfig"
+
+server s1 {
+ rxreq
+ txresp
+} -start
+
+varnish v1 -vcl+backend {
+ import directors;
+
+ sub vcl_init {
+ new shard1 = directors.shard();
+ new shard2 = directors.shard();
+
+ shard1.reconfigure();
+
+ shard2.add_backend(s1);
+ shard2.reconfigure();
+ }
+
+ sub vcl_recv {
+ set req.backend_hint = shard2.backend();
+ }
+} -start
+
+client c1 {
+ txreq
+ rxresp
+ expect resp.status == 200
+} -run
diff --git a/lib/libvmod_directors/shard_cfg.c b/lib/libvmod_directors/shard_cfg.c
index 577e51aba..1c4c797e0 100644
--- a/lib/libvmod_directors/shard_cfg.c
+++ b/lib/libvmod_directors/shard_cfg.c
@@ -616,14 +616,19 @@ shardcfg_reconfigure(VRT_CTX, struct vmod_priv *priv,
return (0);
}
+ sharddir_wrlock(shardd);
+
change = shard_change_get(ctx, priv, shardd);
- if (change == NULL)
+ if (change == NULL) {
+ sharddir_unlock(shardd);
return (0);
+ }
- if (VSTAILQ_FIRST(&change->tasks) == NULL)
+ if (VSTAILQ_FIRST(&change->tasks) == NULL) {
+ shard_change_finish(change);
+ sharddir_unlock(shardd);
return (1);
-
- sharddir_wrlock(shardd);
+ }
shardcfg_apply_change(ctx, shardd, change, replicas);
shard_change_finish(change);
More information about the varnish-commit
mailing list