Mailing List Archive

r3351 - in branches/nuke/varnish-cache: bin/varnishd bin/varnishtest/tests include lib/libvcl
Author: sky
Date: 2008-10-27 01:22:38 +0100 (Mon, 27 Oct 2008)
New Revision: 3351

Added:
branches/nuke/varnish-cache/bin/varnishtest/tests/c00019.vtc
Modified:
branches/nuke/varnish-cache/bin/varnishd/cache.h
branches/nuke/varnish-cache/bin/varnishd/cache_hash.c
branches/nuke/varnish-cache/bin/varnishd/cache_vrt.c
branches/nuke/varnish-cache/include/shmlog_tags.h
branches/nuke/varnish-cache/include/stat_field.h
branches/nuke/varnish-cache/include/vrt.h
branches/nuke/varnish-cache/lib/libvcl/vcc_action.c
branches/nuke/varnish-cache/lib/libvcl/vcc_fixed_token.c
Log:
This implements a nuke() option. It will mangle the hash string
of an object header, thus making it impossible to find.
Eventually it will expire or LRU will get the better of it.
It takes a variable arglist of strings, which it will use to
create a hash with.
nuke("/url","host"); generates
url#hash# which is the default hashstring




Modified: branches/nuke/varnish-cache/bin/varnishd/cache.h
===================================================================
--- branches/nuke/varnish-cache/bin/varnishd/cache.h 2008-10-26 19:04:51 UTC (rev 3350)
+++ branches/nuke/varnish-cache/bin/varnishd/cache.h 2008-10-27 00:22:38 UTC (rev 3351)
@@ -453,6 +453,7 @@
int HSH_Compare(const struct sess *sp, const struct objhead *o);
void HSH_Copy(const struct sess *sp, const struct objhead *o);
struct object *HSH_Lookup(struct sess *sp);
+int HSH_Nuke(struct sess *sp);
void HSH_Unbusy(const struct sess *sp);
void HSH_Ref(struct object *o);
void HSH_Deref(struct object *o);

Modified: branches/nuke/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- branches/nuke/varnish-cache/bin/varnishd/cache_hash.c 2008-10-26 19:04:51 UTC (rev 3350)
+++ branches/nuke/varnish-cache/bin/varnishd/cache_hash.c 2008-10-27 00:22:38 UTC (rev 3351)
@@ -184,6 +184,21 @@
assert(b <= obj->hash + obj->hashlen);
}

+int
+HSH_Nuke(struct sess *sp)
+{
+ struct objhead *oh = hash->lookup(sp, NULL);
+ if (oh) {
+ VSL_stats->n_nuke_hit++;
+ oh->hash[0] = "\n";
+ hash->deref(oh);
+ return 1;
+ } else {
+ VSL_stats->n_nuke_miss++;
+ return 0;
+ }
+}
+
struct object *
HSH_Lookup(struct sess *sp)
{
@@ -223,7 +238,7 @@
}
if (!o->cacheable)
continue;
- if (o->ttl == 0)
+ if (o->ttl == 0)
continue;
if (BAN_CheckObject(o, h->hd[HTTP_HDR_URL].b, oh->hash)) {
o->ttl = 0;

Modified: branches/nuke/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- branches/nuke/varnish-cache/bin/varnishd/cache_vrt.c 2008-10-26 19:04:51 UTC (rev 3350)
+++ branches/nuke/varnish-cache/bin/varnishd/cache_vrt.c 2008-10-27 00:22:38 UTC (rev 3351)
@@ -723,6 +723,54 @@
(void)BAN_Add(NULL, regexp, hash);
}

+
+/*--------------------------------------------------------------------*/
+
+int
+VRT_nuke(struct sess *sp, const char *str, ...)
+{
+ int retval;
+ va_list ap;
+ struct object *obj = sp->obj;
+ struct objhead *objhead = sp->objhead;
+ struct objhead *oh;
+ const char *vp;
+ char *p;
+ uintptr_t u;
+
+ sp->obj = NULL;
+ sp->objhead = NULL;
+
+ /* code lifted from cnt_lookup -- should probably be a common function */
+ /* Allocate the pointers we need, align properly. */
+ sp->lhashptr = 1; /* space for NUL */
+ sp->ihashptr = 0;
+ sp->nhashptr = sp->vcl->nhashcount * 2;
+ p = WS_Alloc(sp->http->ws,
+ sizeof(const char *) * (sp->nhashptr + 1));
+ XXXAN(p);
+ /* Align pointer properly (?) */
+ u = (uintptr_t)p;
+ u &= sizeof(const char *) - 1;
+ if (u)
+ p += sizeof(const char *) - u;
+ sp->hashptr = (void*)p;
+
+ VRT_l_req_hash(sp, str);
+
+ va_start(ap, str);
+ vp = va_arg(ap, const char *);
+ while (vp != vrt_magic_string_end) {
+ VRT_l_req_hash(sp, vp);
+ vp = va_arg(ap, const char *);
+ }
+
+ retval = HSH_Nuke(sp);
+ sp->obj = obj;
+ sp->objhead = objhead;
+ return retval;
+}
+
/*--------------------------------------------------------------------
* Simple stuff
*/

Added: branches/nuke/varnish-cache/bin/varnishtest/tests/c00019.vtc
===================================================================
--- branches/nuke/varnish-cache/bin/varnishtest/tests/c00019.vtc (rev 0)
+++ branches/nuke/varnish-cache/bin/varnishtest/tests/c00019.vtc 2008-10-27 00:22:38 UTC (rev 3351)
@@ -0,0 +1,32 @@
+# $Id: c00006.vtc 2906 2008-07-08 10:29:07Z phk $
+
+test "Test explicit nuking a url from out of vcl_fetch"
+
+server s1 {
+ rxreq
+ expect req.url == "/foo"
+ txresp -body "1111\n"
+ rxreq
+ expect req.url == "/foo"
+ txresp -body "11111\n"
+} -start
+
+varnish v1 -vcl+backend { sub vcl_fetch { nuke("/foo","127.0.0.1"); } } -start
+
+client c1 {
+ txreq -url "/foo"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.content-length == 5
+}
+
+client c1 -run
+
+client c1 {
+ txreq -url "/foo"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.content-length == 6
+}
+
+client c1 -run

Modified: branches/nuke/varnish-cache/include/shmlog_tags.h
===================================================================
--- branches/nuke/varnish-cache/include/shmlog_tags.h 2008-10-26 19:04:51 UTC (rev 3350)
+++ branches/nuke/varnish-cache/include/shmlog_tags.h 2008-10-27 00:22:38 UTC (rev 3351)
@@ -92,6 +92,7 @@
SLTM(ExpBan)
SLTM(ExpPick)
SLTM(ExpKill)
+SLTM(ExpNuked)
SLTM(WorkThread)
SLTM(Terminate)


Modified: branches/nuke/varnish-cache/include/stat_field.h
===================================================================
--- branches/nuke/varnish-cache/include/stat_field.h 2008-10-26 19:04:51 UTC (rev 3350)
+++ branches/nuke/varnish-cache/include/stat_field.h 2008-10-27 00:22:38 UTC (rev 3351)
@@ -124,3 +124,6 @@
MAC_STAT(n_purge_retire, uint64_t, 'a', "N old purges deleted")
MAC_STAT(n_purge_obj_test, uint64_t, 'a', "N objects tested")
MAC_STAT(n_purge_re_test, uint64_t, 'a', "N regexps tested against")
+
+MAC_STAT(n_nuke_hit, uint64_t, 'a', "N object headers marked as nuked")
+MAC_STAT(n_nuke_miss, uint64_t, 'a', "N object headers not in cache")

Modified: branches/nuke/varnish-cache/include/vrt.h
===================================================================
--- branches/nuke/varnish-cache/include/vrt.h 2008-10-26 19:04:51 UTC (rev 3350)
+++ branches/nuke/varnish-cache/include/vrt.h 2008-10-27 00:22:38 UTC (rev 3351)
@@ -141,6 +141,7 @@

void VRT_panic(struct sess *sp, const char *, ...);
void VRT_purge(const char *, int hash);
+int VRT_nuke(struct sess *sp,const char *, ...);

void VRT_count(const struct sess *, unsigned);
int VRT_rewrite(const char *, const char *);

Modified: branches/nuke/varnish-cache/lib/libvcl/vcc_action.c
===================================================================
--- branches/nuke/varnish-cache/lib/libvcl/vcc_action.c 2008-10-26 19:04:51 UTC (rev 3350)
+++ branches/nuke/varnish-cache/lib/libvcl/vcc_action.c 2008-10-27 00:22:38 UTC (rev 3351)
@@ -379,6 +379,39 @@
}

static void
+parse_nuke(struct tokenlist *tl)
+{
+
+ vcc_NextToken(tl);
+
+ Fb(tl, 1, "VRT_nuke(sp, ");
+
+ vcc_NextToken(tl);
+
+ if (!vcc_StringVal(tl)) {
+ vcc_ExpectedStringval(tl);
+ return;
+ }
+
+
+ while (tl->t->tok == ',') {
+ vcc_NextToken(tl);
+ Fb(tl, 0, ", ");
+ if (!vcc_StringVal(tl)) {
+ vcc_ExpectedStringval(tl);
+ return;
+ }
+ }
+
+ Expect(tl, ')');
+ vcc_NextToken(tl);
+ Fb(tl, 0, ", vrt_magic_string_end);\n");
+}
+
+
+
+
+static void
parse_esi(struct tokenlist *tl)
{

@@ -440,6 +473,7 @@
/* Keep list sorted from here */
{ "call", parse_call },
{ "esi", parse_esi },
+ { "nuke", parse_nuke },
{ "panic", parse_panic },
{ "purge_hash", parse_purge_hash },
{ "purge_url", parse_purge_url },

Modified: branches/nuke/varnish-cache/lib/libvcl/vcc_fixed_token.c
===================================================================
--- branches/nuke/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-10-26 19:04:51 UTC (rev 3350)
+++ branches/nuke/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-10-27 00:22:38 UTC (rev 3351)
@@ -421,6 +421,7 @@
vsb_cat(sb, "\n");
vsb_cat(sb, "void VRT_panic(struct sess *sp, const char *, ...);\n");
vsb_cat(sb, "void VRT_purge(const char *, int hash);\n");
+ vsb_cat(sb, "int VRT_nuke(struct sess *sp,const char *, ...);\n");
vsb_cat(sb, "\n");
vsb_cat(sb, "void VRT_count(const struct sess *, unsigned);\n");
vsb_cat(sb, "int VRT_rewrite(const char *, const char *);\n");