]> err.no Git - varnish/commitdiff
Add busyflag and strorage link to objects.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 18 Apr 2006 08:23:44 +0000 (08:23 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 18 Apr 2006 08:23:44 +0000 (08:23 +0000)
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.

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

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

index 29a35f4f571d12999f473420e4d80dcf1227405c..f8606e925676dade374621774fb7fe30d2901fa3 100644 (file)
@@ -29,4 +29,5 @@ varnishd_LDADD = \
        $(top_builddir)/lib/libvarnish/libvarnish.la \
        $(top_builddir)/lib/libvcl/libvcl.la \
        $(top_builddir)/contrib/libevent/libevent.la \
-       -lpthread
+       -lpthread \
+       -lmd
index f42ce40b4a66008183e962e71723b5465c35122f..1cd7753d46ef90a80b0533856f953615dcc5a260 100644 (file)
@@ -10,6 +10,7 @@ struct worker {
        struct event_base       *eb;
        struct event            e1, e2;
        struct sbuf             *sb;
+       struct object           *nobj;
 };
 #else
 struct worker;
@@ -30,6 +31,8 @@ struct hash_slinger {
 
 extern struct hash_slinger hsl_slinger;
 
+extern struct hash_slinger     *hash;
+
 /* Storage -----------------------------------------------------------*/
 
 struct storage {
@@ -52,6 +55,8 @@ struct stevedore {
 
 extern struct stevedore sma_stevedore;
 
+extern struct stevedore *stevedore;
+
 /* Prototypes etc ----------------------------------------------------*/
 
 
index b96806043225b1d44149af9ea2de75c5895be460..224cbf9c4b65259535354e915eb1e18221e6c2ba 100644 (file)
@@ -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 @@ child_main(void)
        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);
 
index 678b9f98098071208ce7203f774a197ca715aff3..23b3e60582d09238dff62007ed433cac03911375 100644 (file)
@@ -3,6 +3,7 @@
  */
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <assert.h>
 #include <pthread.h>
 #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 TAILQ_HEAD(, sess) shd = TAILQ_HEAD_INITIALIZER(shd);
 
 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 @@ CacheWorker(void *priv)
                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));
index bb8ca23532908aa884f031e66f4b059f6d883fb5..16cd0b9ec8c2ee635f2cb1d0366b52a24576bf10 100644 (file)
@@ -198,5 +198,11 @@ VCL_pass(VCL_FARGS)
 }
 
 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) { 
+}
index 9b919b16b94e95b0785362c0d4da89798fae69f5..8afd4be0449f6b6670615838204ce80f057ed805 100644 (file)
@@ -45,6 +45,10 @@ struct object {
        unsigned                refcnt;
        unsigned                valid;
        unsigned                cacheable;
+
+       unsigned                busy;
+
+       TAILQ_HEAD(, storage)   store;
 };
 
 struct sess {
@@ -63,9 +67,11 @@ struct sess {
 
        enum {
                HND_Unclass,
-               HND_Handle,
+               HND_Deliver,
                HND_Pass,
-               HND_Pipe
+               HND_Pipe,
+               HND_Lookup,
+               HND_Fetch
        }                       handling;
 
        char                    done;
index 792a7be67b19ba59fb4f21f7fd2c33dd8d3cc0df..1b5becca43d6484984dec82ec2033c23db0de8e1 100644 (file)
@@ -483,6 +483,10 @@ vcl_output_lang_h(FILE *f)
        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 @@ vcl_output_lang_h(FILE *f)
        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);