From dfa4cf3512a5f00e6ef68255db55f46c7be8835a Mon Sep 17 00:00:00 2001 From: phk Date: Tue, 5 Feb 2008 09:57:46 +0000 Subject: [PATCH] Rename VBE_NewBackend() to VBE_AddBackend() and make it responsible for the identity check for reusing backends between VCL. Disable the round-robin code for now, I'm trying to get the random code working first. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2429 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 5 +- varnish-cache/bin/varnishd/cache_backend.c | 63 ++++++++++++------- .../bin/varnishd/cache_backend_round_robin.c | 3 + .../bin/varnishd/cache_backend_simple.c | 19 +----- 4 files changed, 51 insertions(+), 39 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index b58a5d28..24cf10ea 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -408,6 +408,7 @@ struct backend { pthread_mutex_t mtx; struct backend_method *method; + const char *ident; void *priv; int health; @@ -442,7 +443,7 @@ void VBE_free_bereq(struct bereq *bereq); extern struct backendlist backendlist; void VBE_DropRef(struct backend *); void VBE_DropRefLocked(struct backend *); -struct backend *VBE_NewBackend(struct backend_method *method); +struct backend *VBE_AddBackend(struct backend_method *method, const char *ident); struct vbe_conn *VBE_NewConn(void); void VBE_ReleaseConn(struct vbe_conn *); void VBE_UpdateHealth(const struct sess *sp, const struct vbe_conn *, int); @@ -471,7 +472,7 @@ void CNT_Init(void); /* cache_cli.c [CLI] */ void CLI_Init(void); extern pthread_t cli_thread; -#define ASSERT_CLI() do {assert(phtread_self() == cli_thread);} while (0) +#define ASSERT_CLI() do {assert(pthread_self() == cli_thread);} while (0) /* cache_expiry.c */ void EXP_Insert(struct object *o); diff --git a/varnish-cache/bin/varnishd/cache_backend.c b/varnish-cache/bin/varnishd/cache_backend.c index cc2f6cbe..92fdacb5 100644 --- a/varnish-cache/bin/varnishd/cache_backend.c +++ b/varnish-cache/bin/varnishd/cache_backend.c @@ -211,27 +211,6 @@ VBE_ReleaseConn(struct vbe_conn *vc) UNLOCK(&VBE_mtx); } -/*--------------------------------------------------------------------*/ - -struct backend * -VBE_NewBackend(struct backend_method *method) -{ - struct backend *b; - - b = calloc(sizeof *b, 1); - XXXAN(b); - b->magic = BACKEND_MAGIC; - b->method = method; - - MTX_INIT(&b->mtx); - b->refcount = 1; - - b->last_check = TIM_mono(); - b->minute_limit = 1; - - VTAILQ_INSERT_TAIL(&backendlist, b, list); - return (b); -} /*--------------------------------------------------------------------*/ @@ -344,6 +323,46 @@ VBE_AddBackendMethod(const struct backend_method *bem) bem->init(); } +/*-------------------------------------------------------------------- + * Add a backend/director instance when loading a VCL. + * If an existing backend is matched, grab a refcount and return NULL. + * Else create a new backend structure and return that with reference + * initialized to one. + */ + +struct backend * +VBE_AddBackend(struct backend_method *method, const char *ident) +{ + struct backend *b; + + ASSERT_CLI(); + VTAILQ_FOREACH(b, &backendlist, list) { + CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); + if (b->method != method) + continue; + if (strcmp(b->ident, ident)) + continue; + b->refcount++; + return (NULL); + } + + b = calloc(sizeof *b, 1); + XXXAN(b); + b->magic = BACKEND_MAGIC; + b->method = method; + b->ident = strdup(ident); + XXXAN(b->ident); + + MTX_INIT(&b->mtx); + b->refcount = 1; + + b->last_check = TIM_mono(); + b->minute_limit = 1; + + VTAILQ_INSERT_TAIL(&backendlist, b, list); + return (b); +} + /*--------------------------------------------------------------------*/ void @@ -353,5 +372,7 @@ VBE_Init(void) MTX_INIT(&VBE_mtx); VBE_AddBackendMethod(&backend_method_simple); VBE_AddBackendMethod(&backend_method_random); +#if 0 VBE_AddBackendMethod(&backend_method_round_robin); +#endif } diff --git a/varnish-cache/bin/varnishd/cache_backend_round_robin.c b/varnish-cache/bin/varnishd/cache_backend_round_robin.c index 462a920e..c701e8cf 100644 --- a/varnish-cache/bin/varnishd/cache_backend_round_robin.c +++ b/varnish-cache/bin/varnishd/cache_backend_round_robin.c @@ -30,6 +30,8 @@ * */ +#if 0 + #include #include @@ -487,3 +489,4 @@ VRT_init_round_robin_backend(struct backend **bp, const struct vrt_round_robin_b *bp = b; } +#endif diff --git a/varnish-cache/bin/varnishd/cache_backend_simple.c b/varnish-cache/bin/varnishd/cache_backend_simple.c index 5d0eecfe..a9be5def 100644 --- a/varnish-cache/bin/varnishd/cache_backend_simple.c +++ b/varnish-cache/bin/varnishd/cache_backend_simple.c @@ -364,22 +364,9 @@ VRT_init_simple_backend(struct backend **bp, const struct vrt_simple_backend *t) struct bes *bes; const char *p; - /* - * Scan existing backends to see if we can recycle one of them. - */ - VTAILQ_FOREACH(b, &backendlist, list) { - CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); - if (b->method != &backend_method_simple) - continue; - CAST_OBJ_NOTNULL(bes, b->priv, BES_MAGIC); - if (strcmp(bes->ident, t->ident)) - continue; - b->refcount++; - *bp = b; - return; - } - - b = VBE_NewBackend(&backend_method_simple); + b = VBE_AddBackend(&backend_method_simple, t->ident); + if (b == NULL) + return; /* ref to existing backend */ bes = calloc(sizeof *bes, 1); XXXAN(bes); -- 2.39.5