[master] ce59124 shard: replace magic defaults with optional arguments

Nils Goroll nils.goroll at uplex.de
Fri Mar 9 16:18:07 UTC 2018


commit ce59124fc596f1281d814aff9aca1572ed038bbf
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Fri Mar 9 17:07:59 2018 +0100

    shard: replace magic defaults with optional arguments

diff --git a/lib/libvmod_directors/shard_cfg.c b/lib/libvmod_directors/shard_cfg.c
index ccd64c2..4674a40 100644
--- a/lib/libvmod_directors/shard_cfg.c
+++ b/lib/libvmod_directors/shard_cfg.c
@@ -656,8 +656,7 @@ shardcfg_get_rampup(const struct sharddir *shardd, int host)
 	// assert sharddir_rdlock_held(shardd);
 	assert (host < shardd->n_backend);
 
-	// magic value for default
-	if (shardd->backend[host].rampup == 973279260)
+	if (isnan(shardd->backend[host].rampup))
 		r = shardd->rampup_duration;
 	else
 		r = shardd->backend[host].rampup;
diff --git a/lib/libvmod_directors/vmod.vcc b/lib/libvmod_directors/vmod.vcc
index d240119..586c9db 100644
--- a/lib/libvmod_directors/vmod.vcc
+++ b/lib/libvmod_directors/vmod.vcc
@@ -368,7 +368,7 @@ The association can be changed per backend request using the `param`
 argument of `func_shard.backend`_.
 
 $Method BOOL .add_backend(PRIV_TASK, BACKEND backend,
-	STRING ident=0, DURATION rampup=973279260)
+	[STRING ident], [DURATION rampup])
 
 Add a backend `backend` to the director.
 
@@ -380,13 +380,13 @@ backend name.
 `ident` allows to add multiple instances of the same backend.
 
 `rampup`: Optionally specify a specific rampup time for this
-backend. The magic default value of `973279260s` instructs the shard
-director to use the default rampup time (see :ref:`func_shard.set_rampup`).
+backend. Otherwise, the per-director rampup time is used (see
+:ref:`func_shard.set_rampup`).
 
 NOTE: Backend changes need to be finalized with `shard.reconfigure()`
 and are only supported on one shard director at a time.
 
-$Method BOOL .remove_backend(PRIV_TASK, BACKEND backend=0, STRING ident=0)
+$Method BOOL .remove_backend(PRIV_TASK, [BACKEND backend=0], [STRING ident=0])
 
 Remove backend(s) from the director. Either `backend` or `ident` must
 be specified. `ident` removes a specific instance. If `backend` is
diff --git a/lib/libvmod_directors/vmod_shard.c b/lib/libvmod_directors/vmod_shard.c
index 1a0504b..21a73eb 100644
--- a/lib/libvmod_directors/vmod_shard.c
+++ b/lib/libvmod_directors/vmod_shard.c
@@ -297,26 +297,29 @@ vmod_shard_associate(VRT_CTX,
 
 VCL_BOOL v_matchproto_(td_directors_shard_add_backend)
 vmod_shard_add_backend(VRT_CTX, struct vmod_directors_shard *vshard,
-    struct vmod_priv *priv,
-    VCL_BACKEND be, VCL_STRING ident, VCL_DURATION rampup)
+    struct vmod_shard_add_backend_arg *args)
 {
 	CHECK_OBJ_NOTNULL(vshard, VMOD_SHARD_SHARD_MAGIC);
 
-	if (be == NULL) {
+	if (args->backend == NULL) {
 		shard_err0(ctx, vshard->shardd,
 		    ".backend_add() NULL backend given");
-		return 0;
+		return (0);
 	}
 
-	return shardcfg_add_backend(ctx, priv, vshard->shardd,
-	    be, ident, rampup);
+	return shardcfg_add_backend(ctx, args->arg1,
+	    vshard->shardd, args->backend,
+	    args->valid_ident ? args->ident : NULL,
+	    args->valid_rampup ? args->rampup : nan(""));
 }
 
 VCL_BOOL v_matchproto_(td_directors_shard_remove_backend)
 vmod_shard_remove_backend(VRT_CTX, struct vmod_directors_shard *vshard,
-    struct vmod_priv *priv,
-    VCL_BACKEND be, VCL_STRING ident)
+    struct vmod_shard_remove_backend_arg *args)
 {
+	VCL_BACKEND be = args->valid_backend ? args->backend : NULL;
+	VCL_STRING ident = args->ident ? args->ident : NULL;
+
 	CHECK_OBJ_NOTNULL(vshard, VMOD_SHARD_SHARD_MAGIC);
 
 	if (be == NULL && ident == NULL) {
@@ -326,7 +329,7 @@ vmod_shard_remove_backend(VRT_CTX, struct vmod_directors_shard *vshard,
 		return 0;
 	}
 
-	return shardcfg_remove_backend(ctx, priv, vshard->shardd,
+	return shardcfg_remove_backend(ctx, args->arg1, vshard->shardd,
 	    be, ident);
 }
 


More information about the varnish-commit mailing list