[Varnish] #265: Implement nuke option to invalidate all variants of an object

Varnish varnish-bugs at projects.linpro.no
Wed Jul 2 14:21:27 CEST 2008


#265: Implement nuke option to invalidate all variants of an object
-------------------------+--------------------------------------------------
 Reporter:  sky          |        Owner:  phk  
     Type:  enhancement  |       Status:  new  
 Priority:  normal       |    Milestone:       
Component:  varnishd     |      Version:  trunk
 Severity:  normal       |   Resolution:       
 Keywords:               |  
-------------------------+--------------------------------------------------
Comment (by sky):

 Ok, new version of the patch.

 This supports a nuke("string") operation so it doesn't rely on vary-ants
 of an object existing. Logs and update stats. Should be completely
 harmless to people who don't use it :)

 Might want to add a return value so one can tell it was successful, also,
 wondering if there is a flag set, so when an object is about to expire, we
 know it has been nuked and thus we shouldn't bother to wake VCL up, since
 it is already gone.

 {{{
 Index: bin/varnishd/cache_vrt.c
 ===================================================================
 --- bin/varnishd/cache_vrt.c    (revision 2877)
 +++ bin/varnishd/cache_vrt.c    (working copy)
 @@ -620,6 +620,78 @@
         (void)BAN_Add(NULL, regexp, hash);
  }

 +/*--------------------------------------------------------------------*/
 +
 +void
 +VRT_nuke(struct sess *sp, const char *hash)
 +{
 +       /* XXX Would be nice with a return value? */
 +
 +
 +
 +       /* Save state and restore later */
 +       unsigned tmp_lhashptr = sp->lhashptr;
 +       unsigned tmp_ihashptr = sp->ihashptr;
 +       const char **tmp_p    = sp->hashptr;
 +
 +       {
 +               /* XXX Copy and paste from cache-hash */
 +               char *p;
 +               uintptr_t u;
 +               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;
 +
 +       }
 +
 +       const char *curpos;
 +       const char *startpos;
 +       startpos = hash;
 +       int partlen = 0;
 +
 +       for(curpos = hash; *curpos; curpos++) {
 +               if (*curpos == '\0')
 +                       break;
 +               if (*curpos == '#') {
 +                       sp->hashptr[sp->ihashptr] = startpos;
 +                       sp->hashptr[sp->ihashptr+1] = startpos + partlen;
 +                       sp->ihashptr +=2;
 +                       sp->lhashptr += partlen + 1;
 +                       partlen = 0;
 +                       startpos = curpos + 1;
 +                       continue;
 +               }
 +               partlen++;
 +       }
 +
 +       struct objhead *oh = heritage.hash->lookup(sp, NULL);
 +       if(oh) {
 +               WSP(sp, SLT_Nuke_success, "%s", oh->hash);
 +               VSL_stats->nuke_success++;
 +               LOCK(&oh->mtx);
 +               oh->hash[0] = '\n';
 +               UNLOCK(&oh->mtx);
 +               heritage.hash->deref(oh);
 +       } else {
 +               VSL_stats->nuke_fail++;
 +               WSP(sp, SLT_Nuke_fail, "%s", hash);
 +       }
 +
 +       sp->lhashptr = tmp_lhashptr;
 +       sp->ihashptr = tmp_ihashptr;
 +       sp->hashptr  = tmp_p;
 +}
 +
 +
  /*--------------------------------------------------------------------
   * Simple stuff
   */
 Index: lib/libvcl/vcc_action.c
 ===================================================================
 --- lib/libvcl/vcc_action.c     (revision 2877)
 +++ lib/libvcl/vcc_action.c     (working copy)
 @@ -353,6 +353,29 @@

  /*--------------------------------------------------------------------*/

 +static void
 +parse_nuke(struct tokenlist *tl)
 +{
 +       vcc_NextToken(tl);
 +
 +       Fb(tl, 1, "VRT_nuke(sp,");
 +
 +       Expect(tl, '(');
 +       vcc_NextToken(tl);
 +
 +       if (!vcc_StringVal(tl)) {
 +               vcc_ExpectedStringval(tl);
 +               return;
 +       }
 +
 +       Expect(tl, ')');
 +       vcc_NextToken(tl);
 +       Fb(tl, 0, ");\n");
 +
 +}
 +
 +/*--------------------------------------------------------------------*/
 +
  typedef void action_f(struct tokenlist *tl);

  static struct action_table {
 @@ -372,6 +395,7 @@
         { "purge_url",  parse_purge_url },
         { "purge_hash", parse_purge_hash },
         { "esi",        parse_esi },
 +       { "nuke",       parse_nuke },

         { NULL,         NULL }
  };
 Index: include/stat_field.h
 ===================================================================
 --- include/stat_field.h        (revision 2877)
 +++ include/stat_field.h        (working copy)
 @@ -105,3 +105,6 @@
  MAC_STAT(sma_bfree,            uint64_t, 'i', "SMA bytes free")

  MAC_STAT(backend_req,          uint64_t, 'a', "Backend requests made")
 +
 +MAC_STAT(nuke_success,         uint64_t, 'a', "Nukes succeeded")
 +MAC_STAT(nuke_fail,            uint64_t, 'a', "Nukes failed")
 Index: include/shmlog_tags.h
 ===================================================================
 --- include/shmlog_tags.h       (revision 2877)
 +++ include/shmlog_tags.h       (working copy)
 @@ -99,3 +99,7 @@
  SLTM(ESI_xmlerror)

  SLTM(Hash)
 +
 +SLTM(Nuke_success)
 +SLTM(Nuke_fail)
 +

 }}}

-- 
Ticket URL: <http://varnish.projects.linpro.no/ticket/265#comment:2>
Varnish <http://varnish.projects.linpro.no/>
The Varnish HTTP Accelerator


More information about the varnish-bugs mailing list