]> err.no Git - varnish/commitdiff
Add scaffold code for backend polling.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 11 Jul 2008 20:41:39 +0000 (20:41 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 11 Jul 2008 20:41:39 +0000 (20:41 +0000)
It doesn't actually do anything yet.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2937 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/Makefile.am
varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_backend.h
varnish-cache/bin/varnishd/cache_backend_cfg.c
varnish-cache/bin/varnishd/cache_backend_poll.c [new file with mode: 0644]
varnish-cache/bin/varnishd/cache_cli.c

index 1e5c5053327541349ceca2c72b00c32815ba8ae3..7f5ea9c1a55bf97c2553533224744269336a1720 100644 (file)
@@ -13,6 +13,7 @@ varnishd_SOURCES = \
        cache_acceptor_kqueue.c \
        cache_backend.c \
        cache_backend_cfg.c \
+       cache_backend_poll.c \
        cache_ban.c \
        cache_center.c \
        cache_cli.c \
index 518d2dde521edc385cac5f4f932422d523cc7701..77d89d153c71e49aa2232b083b093ff756ccabb5 100644 (file)
@@ -420,6 +420,7 @@ struct bereq * VBE_new_bereq(void);
 void VBE_free_bereq(struct bereq *bereq);
 void VBE_UpdateHealth(const struct sess *sp, const struct vbe_conn *, int);
 void VBE_AddHostHeader(const struct sess *sp);
+void VBE_Poll(void);
 
 /* cache_backend_cfg.c */
 void VBE_Init(void);
index 54836ed615ac8cd7e61405806f586e219851a1d4..3bb00a062559e569285f2268a01fc69b6b7e864f 100644 (file)
@@ -68,6 +68,9 @@
  *
  */
 
+struct vbp_target;
+struct vrt_backend_probe;
+
 /* Backend indstance */
 struct backend {
        unsigned                magic;
@@ -91,12 +94,17 @@ struct backend {
 
        VTAILQ_HEAD(, vbe_conn) connlist;
 
+       struct vbp_target       *probe;
        int                     health;
 };
 
+/* cache_backend.c */
+void VBE_ReleaseConn(struct vbe_conn *vc);
+
 /* cache_backend_cfg.c */
 extern MTX VBE_mtx;
 void VBE_DropRefLocked(struct backend *b);
 
-/* cache_backend.c */
-void VBE_ReleaseConn(struct vbe_conn *vc);
+/* cache_backend_poll.c */
+void VBP_Start(struct backend *b, struct vrt_backend_probe const *p);
+void VBP_Stop(struct backend *b);
index 00dae87f88690284e0c4f7a7aed6554dd41a4355..0a24bb648d367f4641f79a5da5143cd9171ccca0 100644 (file)
@@ -70,6 +70,37 @@ VBE_SelectBackend(struct sess *sp)
        sp->backend = bp;
 }
 
+/*--------------------------------------------------------------------
+ */
+
+static void
+VBE_Nuke(struct backend *b)
+{
+       VTAILQ_REMOVE(&backends, b, list);
+       free(b->ident);
+       free(b->hosthdr);
+       free(b->ipv4);
+       free(b->ipv6);
+       b->magic = 0;
+       free(b);
+       VSL_stats->n_backend--;
+}
+
+/*--------------------------------------------------------------------
+ */
+
+void
+VBE_Poll(void)
+{
+       struct backend *b, *b2;
+
+       ASSERT_CLI();
+       VTAILQ_FOREACH_SAFE(b, &backends, list, b2) {
+               if (b->refcount == 0 && b->probe == NULL)
+                       VBE_Nuke(b);
+       }
+}
+
 /*--------------------------------------------------------------------
  * Drop a reference to a backend.
  * The last reference must come from the watcher in the CLI thread,
@@ -91,20 +122,16 @@ VBE_DropRefLocked(struct backend *b)
                return;
 
        ASSERT_CLI();
-       VTAILQ_REMOVE(&backends, b, list);
        VTAILQ_FOREACH_SAFE(vbe, &b->connlist, list, vbe2) {
                VTAILQ_REMOVE(&b->connlist, vbe, list);
                if (vbe->fd >= 0)
                        AZ(close(vbe->fd));
                VBE_ReleaseConn(vbe);
        }
-       free(b->ident);
-       free(b->hosthdr);
-       free(b->ipv4);
-       free(b->ipv6);
-       b->magic = 0;
-       free(b);
-       VSL_stats->n_backend--;
+       if (b->probe != NULL)
+               VBP_Stop(b);
+       else
+               VBE_Nuke(b);
 }
 
 void
@@ -206,6 +233,7 @@ VBE_AddBackend(struct cli *cli, const struct vrt_backend *vb)
 
        assert(b->ipv4 != NULL || b->ipv6 != NULL);
 
+       VBP_Start(b, &vb->probe);
        VTAILQ_INSERT_TAIL(&backends, b, list);
        VSL_stats->n_backend++;
        return (b);
diff --git a/varnish-cache/bin/varnishd/cache_backend_poll.c b/varnish-cache/bin/varnishd/cache_backend_poll.c
new file mode 100644 (file)
index 0000000..83f8cf9
--- /dev/null
@@ -0,0 +1,114 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2008 Linpro AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: cache_backend_cfg.c 2905 2008-07-08 10:09:03Z phk $
+ *
+ * Poll backends for collection of health statistics
+ *
+ * We co-opt threads from the worker pool for probing the backends,
+ * but we want to avoid a potentially messy cleanup operation when we
+ * retire the backend, so the thread owns the health information, which
+ * the backend references, rather than the other way around.
+ *
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <poll.h>
+
+#include <sys/socket.h>
+
+#include "shmlog.h"
+#include "cache.h"
+#include "mgt_event.h"
+#include "vrt.h"
+#include "cache_backend.h"
+
+struct vbp_target {
+       unsigned                        magic;
+#define VBP_TARGET_MAGIC               0x6b7cb656
+
+       struct backend                  *backend;
+       struct workreq                  wrq;
+       int                             stop;
+};
+
+static void
+vbp_wrk_poll_backend(struct worker *w, void *priv)
+{
+       struct vbp_target *vt;
+
+       (void)w;
+       CAST_OBJ_NOTNULL(vt, priv, VBP_TARGET_MAGIC);
+       THR_Name("backend poll");
+
+       while (!vt->stop) {
+               printf("Poke backend %s\n", vt->backend->vcl_name);
+               sleep(1);
+       }
+       vt->backend->probe = NULL;
+       FREE_OBJ(vt);
+       THR_Name("cache-worker");
+}
+
+void
+VBP_Start(struct backend *b, struct vrt_backend_probe const *p)
+{
+       struct vbp_target *vt;
+
+       ASSERT_CLI();
+
+       /* Is probing even configured ? */
+       if (p->request == NULL)
+               return;
+
+       ALLOC_OBJ(vt, VBP_TARGET_MAGIC);
+       AN(vt);
+       vt->backend = b;
+       b->probe = vt;
+
+       vt->wrq.func = vbp_wrk_poll_backend;
+       vt->wrq.priv = vt;
+       if (WRK_Queue(&vt->wrq) == 0)
+               return;
+       assert(0 == __LINE__);
+       b->probe = NULL;
+       FREE_OBJ(vt);
+}
+
+void
+VBP_Stop(struct backend *b)
+{
+       if (b->probe == NULL)
+               return;
+       b->probe->stop = 1;
+}
index 302fa7bda4e29e54e03217d43b17b84c9d1dead3..f437edb73a01d7b24c67ae82aa4fcfcf965181ed 100644 (file)
@@ -103,6 +103,7 @@ cli_vlu(void *priv, const char *p)
        cli = priv;
        VSL(SLT_CLI, 0, "Rd %s", p);
        VCL_Poll();
+       VBE_Poll();
        vsb_clear(cli->sb);
        LOCK(&cli_mtx);
        cli_dispatch(cli, ccf_master_cli, p);