Commit 3bc8325e authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add scaffold code for backend polling.

It doesn't actually do anything yet.



git-svn-id: http://www.varnish-cache.org/svn/trunk@2937 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 970270a5
......@@ -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 \
......
......@@ -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);
......
......@@ -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);
......@@ -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);
......
/*-
* 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;
}
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment