r141 - in trunk/varnish-cache: bin/varnishd include lib/libvcl

phk at projects.linpro.no phk at projects.linpro.no
Tue Apr 18 10:23:44 CEST 2006


Author: phk
Date: 2006-04-18 10:23:44 +0200 (Tue, 18 Apr 2006)
New Revision: 141

Modified:
   trunk/varnish-cache/bin/varnishd/Makefile.am
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_main.c
   trunk/varnish-cache/bin/varnishd/cache_pool.c
   trunk/varnish-cache/bin/varnishd/cache_vcl.c
   trunk/varnish-cache/include/vcl_lang.h
   trunk/varnish-cache/lib/libvcl/vcl_fixed_token.c
Log:

Add busyflag and strorage link to objects.

Initialize default hasher and stevedore.

Give each workerthread an object pointer to be kept populated with
a template object for when lookups miss and need to insert one.

Add libmd to get MD5, (choice of hash-algorithm to be revisited later)

Implement lookup, begin on fetch.



Modified: trunk/varnish-cache/bin/varnishd/Makefile.am
===================================================================
--- trunk/varnish-cache/bin/varnishd/Makefile.am	2006-04-18 07:34:24 UTC (rev 140)
+++ trunk/varnish-cache/bin/varnishd/Makefile.am	2006-04-18 08:23:44 UTC (rev 141)
@@ -29,4 +29,5 @@
 	$(top_builddir)/lib/libvarnish/libvarnish.la \
 	$(top_builddir)/lib/libvcl/libvcl.la \
 	$(top_builddir)/contrib/libevent/libevent.la \
-	-lpthread
+	-lpthread \
+	-lmd

Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2006-04-18 07:34:24 UTC (rev 140)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2006-04-18 08:23:44 UTC (rev 141)
@@ -10,6 +10,7 @@
 	struct event_base	*eb;
 	struct event		e1, e2;
 	struct sbuf		*sb;
+	struct object		*nobj;
 };
 #else
 struct worker;
@@ -30,6 +31,8 @@
 
 extern struct hash_slinger hsl_slinger;
 
+extern struct hash_slinger	*hash;
+
 /* Storage -----------------------------------------------------------*/
 
 struct storage {
@@ -52,6 +55,8 @@
 
 extern struct stevedore sma_stevedore;
 
+extern struct stevedore *stevedore;
+
 /* Prototypes etc ----------------------------------------------------*/
 
 

Modified: trunk/varnish-cache/bin/varnishd/cache_main.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_main.c	2006-04-18 07:34:24 UTC (rev 140)
+++ trunk/varnish-cache/bin/varnishd/cache_main.c	2006-04-18 08:23:44 UTC (rev 141)
@@ -25,6 +25,9 @@
 static struct event ev_keepalive;
 static pthread_t vca_thread;
 
+struct hash_slinger	*hash;
+struct stevedore	*stevedore;
+
 pthread_mutex_t	sessmtx;
 
 /*--------------------------------------------------------------------*/
@@ -114,6 +117,12 @@
 	eb = event_init();
 	assert(eb != NULL);
 
+	hash = &hsl_slinger;
+	hash->init();
+
+	stevedore = &sma_stevedore;
+	stevedore->init();
+
 	CVCL_Load(heritage.vcl_file, "boot");
 	cli = cli_setup(eb, heritage.fds[2], heritage.fds[1], 0, cli_proto);
 

Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-04-18 07:34:24 UTC (rev 140)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-04-18 08:23:44 UTC (rev 141)
@@ -3,6 +3,7 @@
  */
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <assert.h>
 #include <pthread.h>
@@ -10,8 +11,10 @@
 #include <sys/time.h>
 #include <sbuf.h>
 #include <event.h>
+#include <md5.h>
 
 #include "libvarnish.h"
+#include "shmlog.h"
 #include "vcl_lang.h"
 #include "cache.h"
 
@@ -19,11 +22,55 @@
 
 static pthread_cond_t	shdcnd;
 
+static int
+LookupSession(struct worker *w, struct sess *sp)
+{
+	struct object *o;
+	unsigned char key[16];
+	MD5_CTX ctx;
+
+	if (w->nobj == NULL) {
+		w->nobj = calloc(sizeof *w->nobj, 1);	
+		assert(w->nobj != NULL);
+		w->nobj->busy = 1;
+		TAILQ_INIT(&w->nobj->store);
+	}
+
+	MD5Init(&ctx);
+	MD5Update(&ctx, sp->http.url, strlen(sp->http.url));
+	MD5Final(key, &ctx);
+	o = hash->lookup(key, w->nobj);
+	if (o == w->nobj)
+		w->nobj = NULL;
+	/*
+	 * XXX: if obj is busy, park session on it
+	 */
+
+	sp->obj = o;
+	sp->handling = HND_Unclass;
+	sp->vcl->lookup_func(sp);
+	if (sp->handling == HND_Unclass) {
+		if (o->valid && o->cacheable)
+			sp->handling = HND_Deliver;
+		else
+			sp->handling = HND_Pass;
+	}
+	return (0);
+}
+
+static int
+FetchSession(struct worker *w, struct sess *sp)
+{
+
+	assert(w == NULL);
+}
+
 static void *
 CacheWorker(void *priv)
 {
 	struct sess *sp;
 	struct worker w;
+	int done;
 
 	memset(&w, 0, sizeof w);
 	w.eb = event_init();
@@ -47,19 +94,36 @@
 		HttpdAnalyze(sp, 1);
 
 		sp->backend = sp->vcl->default_backend;
-		/* Call the VCL program */
+
+		/*
+		 * Call the VCL recv function.
+		 * Default action is to lookup
+		 */
+		sp->handling = HND_Lookup;
+		
 		sp->vcl->recv_func(sp);
 
-		printf("Handling: %d\n", sp->handling);
-		switch(sp->handling) {
-		case HND_Unclass:
-		case HND_Handle:
-		case HND_Pipe:
-			PipeSession(&w, sp);
-			break;
-		case HND_Pass:
-			PassSession(&w, sp);
-			break;
+		for (done = 0; !done; ) {
+			printf("Handling: %d\n", sp->handling);
+			switch(sp->handling) {
+			case HND_Lookup:
+				done = LookupSession(&w, sp);
+				break;
+			case HND_Fetch:
+				done = FetchSession(&w, sp);
+				break;
+			case HND_Pipe:
+				PipeSession(&w, sp);
+				done = 1;
+				break;
+			case HND_Pass:
+				PassSession(&w, sp);
+				done = 1;
+				break;
+			case HND_Unclass:
+			case HND_Deliver:
+				assert(sp->handling == HND_Unclass);
+			}
 		}
 
 		AZ(pthread_mutex_lock(&sessmtx));

Modified: trunk/varnish-cache/bin/varnishd/cache_vcl.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vcl.c	2006-04-18 07:34:24 UTC (rev 140)
+++ trunk/varnish-cache/bin/varnishd/cache_vcl.c	2006-04-18 08:23:44 UTC (rev 141)
@@ -198,5 +198,11 @@
 }
 
 void VCL_insert(VCL_FARGS) { }
-void VCL_fetch(VCL_FARGS) { }
-void VCL_error(VCL_FARGS, unsigned err, const char *str) { }
+
+void VCL_fetch(VCL_FARGS) { 
+	sess->handling = HND_Fetch;
+	sess->done++;
+}
+
+void VCL_error(VCL_FARGS, unsigned err, const char *str) { 
+}

Modified: trunk/varnish-cache/include/vcl_lang.h
===================================================================
--- trunk/varnish-cache/include/vcl_lang.h	2006-04-18 07:34:24 UTC (rev 140)
+++ trunk/varnish-cache/include/vcl_lang.h	2006-04-18 08:23:44 UTC (rev 141)
@@ -45,6 +45,10 @@
 	unsigned 		refcnt;
 	unsigned		valid;
 	unsigned		cacheable;
+
+	unsigned		busy;
+
+	TAILQ_HEAD(, storage)	store;
 };
 
 struct sess {
@@ -63,9 +67,11 @@
 
 	enum {
 		HND_Unclass,
-		HND_Handle,
+		HND_Deliver,
 		HND_Pass,
-		HND_Pipe
+		HND_Pipe,
+		HND_Lookup,
+		HND_Fetch
 	}			handling;
 
 	char			done;

Modified: trunk/varnish-cache/lib/libvcl/vcl_fixed_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcl_fixed_token.c	2006-04-18 07:34:24 UTC (rev 140)
+++ trunk/varnish-cache/lib/libvcl/vcl_fixed_token.c	2006-04-18 08:23:44 UTC (rev 141)
@@ -483,6 +483,10 @@
 	fputs("	unsigned 		refcnt;\n", f);
 	fputs("	unsigned		valid;\n", f);
 	fputs("	unsigned		cacheable;\n", f);
+	fputs("\n", f);
+	fputs("	unsigned		busy;\n", f);
+	fputs("\n", f);
+	fputs("	TAILQ_HEAD(, storage)	store;\n", f);
 	fputs("};\n", f);
 	fputs("\n", f);
 	fputs("struct sess {\n", f);
@@ -501,9 +505,11 @@
 	fputs("\n", f);
 	fputs("	enum {\n", f);
 	fputs("		HND_Unclass,\n", f);
-	fputs("		HND_Handle,\n", f);
+	fputs("		HND_Deliver,\n", f);
 	fputs("		HND_Pass,\n", f);
-	fputs("		HND_Pipe\n", f);
+	fputs("		HND_Pipe,\n", f);
+	fputs("		HND_Lookup,\n", f);
+	fputs("		HND_Fetch\n", f);
 	fputs("	}			handling;\n", f);
 	fputs("\n", f);
 	fputs("	char			done;\n", f);




More information about the varnish-commit mailing list