r2429 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Tue Feb 5 10:57:47 CET 2008
Author: phk
Date: 2008-02-05 10:57:46 +0100 (Tue, 05 Feb 2008)
New Revision: 2429
Modified:
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_backend.c
trunk/varnish-cache/bin/varnishd/cache_backend_round_robin.c
trunk/varnish-cache/bin/varnishd/cache_backend_simple.c
Log:
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.
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2008-02-05 09:46:30 UTC (rev 2428)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2008-02-05 09:57:46 UTC (rev 2429)
@@ -408,6 +408,7 @@
pthread_mutex_t mtx;
struct backend_method *method;
+ const char *ident;
void *priv;
int health;
@@ -442,7 +443,7 @@
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 @@
/* 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);
Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.c 2008-02-05 09:46:30 UTC (rev 2428)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2008-02-05 09:57:46 UTC (rev 2429)
@@ -211,28 +211,7 @@
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);
-}
-
/*--------------------------------------------------------------------*/
void
@@ -344,6 +323,46 @@
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 @@
MTX_INIT(&VBE_mtx);
VBE_AddBackendMethod(&backend_method_simple);
VBE_AddBackendMethod(&backend_method_random);
+#if 0
VBE_AddBackendMethod(&backend_method_round_robin);
+#endif
}
Modified: trunk/varnish-cache/bin/varnishd/cache_backend_round_robin.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend_round_robin.c 2008-02-05 09:46:30 UTC (rev 2428)
+++ trunk/varnish-cache/bin/varnishd/cache_backend_round_robin.c 2008-02-05 09:57:46 UTC (rev 2429)
@@ -30,6 +30,8 @@
*
*/
+#if 0
+
#include <sys/types.h>
#include <sys/socket.h>
@@ -487,3 +489,4 @@
*bp = b;
}
+#endif
Modified: trunk/varnish-cache/bin/varnishd/cache_backend_simple.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend_simple.c 2008-02-05 09:46:30 UTC (rev 2428)
+++ trunk/varnish-cache/bin/varnishd/cache_backend_simple.c 2008-02-05 09:57:46 UTC (rev 2429)
@@ -364,23 +364,10 @@
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_AddBackend(&backend_method_simple, t->ident);
+ if (b == NULL)
+ return; /* ref to existing backend */
- b = VBE_NewBackend(&backend_method_simple);
-
bes = calloc(sizeof *bes, 1);
XXXAN(bes);
bes->magic = BES_MAGIC;
More information about the varnish-commit
mailing list