]> err.no Git - varnish/commitdiff
Add the ability to instantly ban/purge all cached objects matching
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Thu, 29 Jun 2006 17:09:24 +0000 (17:09 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Thu, 29 Jun 2006 17:09:24 +0000 (17:09 +0000)
a given regexp.

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

varnish-cache/bin/varnishd/Makefile.am
varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_ban.c [new file with mode: 0644]
varnish-cache/bin/varnishd/cache_hash.c
varnish-cache/bin/varnishd/cache_main.c

index 070ed754733a27be1117c3400015a09f84b6597c..60d663ea59023de93e67652006e812274b71e5f3 100644 (file)
@@ -7,6 +7,7 @@ bin_PROGRAMS = varnishd
 varnishd_SOURCES = \
        cache_acceptor.c \
        cache_backend.c \
+       cache_ban.c \
        cache_expire.c \
        cache_fetch.c \
        cache_hash.c \
index 797c3719c3861800a3a5e56c7d664a912e6530f0..54507eb37aab6ada3798b5ad74ebad4d122e458f 100644 (file)
@@ -9,6 +9,7 @@
 #define VCA_ADDRBUFSIZE                32      /* Sizeof ascii network address */
 
 struct event_base;
+struct cli;
 struct sbuf;
 struct sess;
 struct object;
@@ -69,6 +70,8 @@ struct object {
        struct objhead          *objhead;
        pthread_cond_t          cv;
 
+       unsigned                ban_seq;
+
        unsigned                valid;
        unsigned                cacheable;
 
@@ -149,6 +152,12 @@ int VBE_GetFd(struct backend *bp, void **ptr, unsigned xid);
 void VBE_ClosedFd(void *ptr);
 void VBE_RecycleFd(void *ptr);
 
+/* cache_ban.c */
+void BAN_Init(void);
+void cli_func_url_purge(struct cli *cli, char **av, void *priv);
+void BAN_NewObj(struct object *o);
+int BAN_CheckObject(struct object *o, const char *url);
+
 /* cache_expiry.c */
 void EXP_Insert(struct object *o);
 void EXP_Init(void);
diff --git a/varnish-cache/bin/varnishd/cache_ban.c b/varnish-cache/bin/varnishd/cache_ban.c
new file mode 100644 (file)
index 0000000..e162a67
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * $Id$
+ *
+ * Ban processing
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <regex.h>
+
+#include "shmlog.h"
+#include "cli_priv.h"
+#include "cache.h"
+
+struct ban {
+       TAILQ_ENTRY(ban)        list;
+       unsigned                gen;
+       regex_t                 regexp;
+       char                    *ban;
+};
+
+static TAILQ_HEAD(,ban) ban_head = TAILQ_HEAD_INITIALIZER(ban_head);
+static unsigned ban_next;
+static struct ban *ban_start;
+
+static void
+AddBan(const char *regexp)
+{
+       struct ban *b;
+       int i;
+
+       b = calloc(sizeof *b, 1);
+       assert(b != NULL);
+
+       i = regcomp(&b->regexp, regexp, REG_EXTENDED | REG_NOSUB);
+       if (i) {
+               char buf[512];
+       
+               regerror(i, &b->regexp, buf, sizeof buf);
+               VSL(SLT_Debug, 0, "REGEX: <%s>", buf);
+       }
+       b->gen = ++ban_next;
+       b->ban = strdup(regexp);
+       TAILQ_INSERT_HEAD(&ban_head, b, list);
+       ban_start = b;
+}
+
+void
+BAN_NewObj(struct object *o)
+{
+
+       o->ban_seq = ban_next;
+}
+
+int
+BAN_CheckObject(struct object *o, const char *url)
+{
+       struct ban *b, *b0;
+       int i;
+
+       b0 = ban_start;
+       for (b = b0;
+           b != NULL && b->gen > o->ban_seq;
+           b = TAILQ_NEXT(b, list)) {
+               i = regexec(&b->regexp, url, 0, NULL, 0);
+               if (!i)
+                       return (1);
+       } 
+       o->ban_seq = b0->gen;
+       return (0);
+}
+
+void
+cli_func_url_purge(struct cli *cli, char **av, void *priv)
+{
+
+       AddBan(av[2]);
+       cli_out(cli, "PURGE %s\n", av[2]);
+}
+
+void
+BAN_Init(void)
+{
+
+       AddBan("a");
+}
index 620dc661fa2da255bc04d60f2d9e4688905caec8..1ad722447659e964f1ea42891f9e9dd8b4618db9 100644 (file)
@@ -12,6 +12,7 @@
 #include <pthread.h>
 
 #include "libvarnish.h"
+#include "shmlog.h"
 #include "cache.h"
 
 static struct hash_slinger      *hash;
@@ -48,8 +49,13 @@ HSH_Lookup(struct worker *w, struct http *h)
                o->refcnt++;
                if (o->busy)
                        AZ(pthread_cond_wait(&o->cv, &oh->mtx));
-               /* XXX: do Vary: comparison */
-               if (1)
+               /* XXX: check TTL */
+               if (o->ttl == 0) {
+                       VSL(SLT_Debug, 0, "Object %p had 0 ttl", o);
+               } else if (BAN_CheckObject(o, b)) {
+                       o->ttl = 0;
+                       VSL(SLT_Debug, 0, "Object %p was banned", o);
+               } else 
                        break;
                o->refcnt--;
        }
@@ -67,6 +73,7 @@ HSH_Lookup(struct worker *w, struct http *h)
        TAILQ_INSERT_TAIL(&oh->objects, o, list);
        /* NB: do not deref objhead the new object inherits our reference */
        AZ(pthread_mutex_unlock(&oh->mtx));
+       BAN_NewObj(o);
        return (o);
 }
 
index ada0e1032ea0e9b7fb8c31404e914aa6dada02c0..236fe7d7715c54789d9cc2b9e266cd3f9dd39425 100644 (file)
@@ -83,6 +83,7 @@ cli_func_ping(struct cli *cli, char **av, void *priv)
 
 static struct cli_proto cli_proto[] = {
        { CLI_URL_QUERY,        cli_func_url_query },
+       { CLI_URL_PURGE,        cli_func_url_purge },
        { CLI_CONFIG_LOAD,      cli_func_config_load },
        { CLI_CONFIG_LIST,      cli_func_config_list },
        { CLI_CONFIG_UNLOAD,    cli_func_config_unload },
@@ -115,6 +116,7 @@ child_main(void)
        VCA_Init();
        EXP_Init();
        HSH_Init();
+       BAN_Init();
 
        eb = event_init();
        assert(eb != NULL);