Changeset 4100

Show
Ignore:
Timestamp:
06/09/09 12:41:38 (15 months ago)
Author:
phk
Message:

Remove the vcl_timeout{} VCL callback.

We had big plans for this originally, but none of them have materialized
because there are better ways to do those things.

For instance: why invent a lot of code to do prefetch, when wget(1) can
do the job already ?

Getting rid of vcl_timeout{} (and vcl_discard{}, see yesterdays commit)
simplifies the expiry codes locking and statekeeping significantly.

Location:
trunk/varnish-cache
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • trunk/varnish-cache/bin/varnishd/cache_expire.c

    r4099 r4100  
    3232 * and two ways to kill objects: TTL-timeouts and LRU cleanups. 
    3333 * 
    34  * To avoid holding the mutex while we ponder the fate of objects, we 
    35  * have the following prototol: 
    36  * 
    37  * Any object on the LRU is also on the binheap (normal case) 
    38  * 
    39  * An object is taken off only the binheap but left on the LRU during timer 
    40  * processing because we have no easy way to put it back the right place 
    41  * in the LRU list. 
    42  * 
    43  * An object is taken off both LRU and binheap for LRU processing, (which 
    44  * implies that it must be on both, from where it follows that the timer 
    45  * is not chewing on it) because we expect the majority of objects to be 
    46  * discarded by LRU and save a lock cycle that way, and because we can 
    47  * properly replace it's position in the binheap. 
     34 * Any object on the LRU is also on the binheap and vice versa. 
     35 * 
     36 * We hold one object reference for both data structures. 
     37 * 
    4838 */ 
    4939 
     
    113103 
    114104        CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); 
     105        AN(o->objhead); 
    115106        AN(ObjIsBusy(o)); 
    116107        assert(o->cacheable); 
     
    152143        if (oc == NULL) 
    153144                return (retval); 
     145        AN(o->objhead); 
    154146        CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); 
    155147        if (Lck_Trylock(&exp_mtx)) 
     
    242234                CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); 
    243235                CHECK_OBJ_NOTNULL(o->objhead, OBJHEAD_MAGIC); 
     236                assert(oc->flags & OC_F_ONLRU); 
    244237                assert(oc->timer_idx != BINHEAP_NOIDX); 
    245238                binheap_delete(exp_heap, oc->timer_idx); 
    246239                assert(oc->timer_idx == BINHEAP_NOIDX); 
     240                VTAILQ_REMOVE(&lru, o->objcore, lru_list); 
     241                oc->flags &= ~OC_F_ONLRU; 
    247242 
    248243                {       /* Sanity checking */ 
     
    254249                } 
    255250 
    256                 assert(oc->flags & OC_F_ONLRU); 
    257                 Lck_Unlock(&exp_mtx); 
    258  
    259                 WSL(sp->wrk, SLT_ExpPick, 0, "%u TTL", o->xid); 
    260  
    261                 sp->obj = o; 
    262                 VCL_timeout_method(sp); 
    263                 sp->obj = NULL; 
    264  
    265                 assert(sp->handling == VCL_RET_DISCARD); 
    266                 WSL(sp->wrk, SLT_ExpKill, 0, 
    267                     "%u %d", o->xid, (int)(o->ttl - t)); 
    268                 Lck_Lock(&exp_mtx); 
    269                 assert(oc->timer_idx == BINHEAP_NOIDX); 
    270                 assert(oc->flags & OC_F_ONLRU); 
    271                 VTAILQ_REMOVE(&lru, o->objcore, lru_list); 
    272                 oc->flags &= ~OC_F_ONLRU; 
    273251                VSL_stats->n_expired++; 
    274252                Lck_Unlock(&exp_mtx); 
     253                WSL(sp->wrk, SLT_ExpKill, 0, "%u %d", 
     254                    o->xid, (int)(o->ttl - t)); 
    275255                HSH_Deref(sp->wrk, &o); 
    276256        } 
     
    278258 
    279259/*-------------------------------------------------------------------- 
    280  * Attempt to make space by nuking, with VCLs permission, the oldest 
    281  * object on the LRU list which isn't in use. 
     260 * Attempt to make space by nuking, the oldest object on the LRU list 
     261 * which isn't in use. 
    282262 * Returns: 1: did, 0: didn't, -1: can't 
    283263 */ 
     
    292272         * Find the first currently unused object on the LRU. 
    293273         * 
    294          * Ideally we would have the refcnt in the objcore so we the object does 
     274         * Ideally we would have the refcnt in the objcore so we object does 
    295275         * not need to get paged in for this check, but it does not pay off 
    296276         * the complexity:  The chances of an object being in front of the LRU, 
     
    298278         * object with no active references will be prodded further anyway. 
    299279         * 
    300          * NB: Checking refcount here is no guarantee that it does not gain 
    301          * another ref while we ponder its destiny without the lock held. 
    302280         */ 
    303281        Lck_Lock(&exp_mtx); 
  • trunk/varnish-cache/bin/varnishd/default.vcl

    r4099 r4100  
    111111} 
    112112 
    113 sub vcl_timeout { 
    114     /* XXX: Do not redefine vcl_timeout{}, it is not yet supported */ 
    115     return (discard); 
    116 } 
    117  
    118113sub vcl_error { 
    119114    set obj.http.Content-Type = "text/html; charset=utf-8"; 
  • trunk/varnish-cache/include/vcl.h

    r4099 r4100  
    2323#define VCL_MET_FETCH           (1 << 6) 
    2424#define VCL_MET_DELIVER         (1 << 7) 
    25 #define VCL_MET_TIMEOUT         (1 << 8) 
    26 #define VCL_MET_ERROR           (1 << 9) 
     25#define VCL_MET_ERROR           (1 << 8) 
    2726 
    28 #define VCL_MET_MAX             10 
     27#define VCL_MET_MAX             9 
    2928 
    3029/* VCL Returns */ 
     
    7069        vcl_func_f      *fetch_func; 
    7170        vcl_func_f      *deliver_func; 
    72         vcl_func_f      *timeout_func; 
    7371        vcl_func_f      *error_func; 
    7472}; 
  • trunk/varnish-cache/include/vcl_returns.h

    r4099 r4100  
    6161    | (1 << VCL_RET_DELIVER) 
    6262)) 
    63 VCL_MET_MAC(timeout,TIMEOUT, 
    64      ((1 << VCL_RET_FETCH) 
    65     | (1 << VCL_RET_DISCARD) 
    66 )) 
    6763VCL_MET_MAC(error,ERROR, 
    6864     ((1 << VCL_RET_RESTART) 
  • trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c

    r4099 r4100  
    11/* 
    2  * $Id: vcc_gen_fixed_token.tcl 3948 2009-03-18 11:25:43Z kristian $ 
     2 * $Id: vcc_gen_fixed_token.tcl 4099 2009-06-08 21:40:48Z phk $ 
    33 * 
    44 * NB:  This file is machine generated, DO NOT EDIT! 
     
    160160        /* ../../include/vcl.h */ 
    161161 
    162         vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 3948 2009-03-18 11"); 
    163         vsb_cat(sb, ":25:43Z kristian $\n *\n * NB:  This file is machine g"); 
    164         vsb_cat(sb, "enerated, DO NOT EDIT!\n *\n * Edit and run vcc_gen_fi"); 
    165         vsb_cat(sb, "xed_token.tcl instead\n */\n\nstruct sess;\n"); 
     162        vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 4099 2009-06-08 21"); 
     163        vsb_cat(sb, ":40:48Z phk $\n *\n * NB:  This file is machine genera"); 
     164        vsb_cat(sb, "ted, DO NOT EDIT!\n *\n * Edit and run vcc_gen_fixed_t"); 
     165        vsb_cat(sb, "oken.tcl instead\n */\n\nstruct sess;\n"); 
    166166        vsb_cat(sb, "struct cli;\n\ntypedef void vcl_init_f(struct cli *);\n"); 
    167167        vsb_cat(sb, "typedef void vcl_fini_f(struct cli *);\n"); 
     
    175175        vsb_cat(sb, "#define VCL_MET_FETCH\t\t(1 << 6)\n"); 
    176176        vsb_cat(sb, "#define VCL_MET_DELIVER\t\t(1 << 7)\n"); 
    177         vsb_cat(sb, "#define VCL_MET_TIMEOUT\t\t(1 << 8)\n"); 
    178         vsb_cat(sb, "#define VCL_MET_ERROR\t\t(1 << 9)\n"); 
    179         vsb_cat(sb, "\n#define VCL_MET_MAX\t\t10\n\n"); 
    180         vsb_cat(sb, "/* VCL Returns */\n#define VCL_RET_ERROR\t\t0\n"); 
    181         vsb_cat(sb, "#define VCL_RET_LOOKUP\t\t1\n#define VCL_RET_HASH\t\t2"); 
    182         vsb_cat(sb, "\n#define VCL_RET_PIPE\t\t3\n#define VCL_RET_PASS\t\t4"); 
    183         vsb_cat(sb, "\n#define VCL_RET_FETCH\t\t5\n#define VCL_RET_DELIVER\t"); 
    184         vsb_cat(sb, "\t6\n#define VCL_RET_DISCARD\t\t7\n"); 
    185         vsb_cat(sb, "#define VCL_RET_KEEP\t\t8\n#define VCL_RET_RESTART\t\t"); 
    186         vsb_cat(sb, "9\n\n#define VCL_RET_MAX\t\t10\n"); 
    187         vsb_cat(sb, "\nstruct VCL_conf {\n\tunsigned\tmagic;\n"); 
     177        vsb_cat(sb, "#define VCL_MET_ERROR\t\t(1 << 8)\n"); 
     178        vsb_cat(sb, "\n#define VCL_MET_MAX\t\t9\n\n/* VCL Returns */\n"); 
     179        vsb_cat(sb, "#define VCL_RET_ERROR\t\t0\n#define VCL_RET_LOOKUP\t\t"); 
     180        vsb_cat(sb, "1\n#define VCL_RET_HASH\t\t2\n#define VCL_RET_PIPE\t\t"); 
     181        vsb_cat(sb, "3\n#define VCL_RET_PASS\t\t4\n#define VCL_RET_FETCH\t\t"); 
     182        vsb_cat(sb, "5\n#define VCL_RET_DELIVER\t\t6\n"); 
     183        vsb_cat(sb, "#define VCL_RET_DISCARD\t\t7\n#define VCL_RET_KEEP\t\t"); 
     184        vsb_cat(sb, "8\n#define VCL_RET_RESTART\t\t9\n"); 
     185        vsb_cat(sb, "\n#define VCL_RET_MAX\t\t10\n\n"); 
     186        vsb_cat(sb, "struct VCL_conf {\n\tunsigned\tmagic;\n"); 
    188187        vsb_cat(sb, "#define VCL_CONF_MAGIC\t0x7406c509\t/* from /dev/rando"); 
    189188        vsb_cat(sb, "m */\n\n\tstruct director\t**director;\n"); 
     
    198197        vsb_cat(sb, "\tvcl_func_f\t*miss_func;\n\tvcl_func_f\t*hit_func;\n"); 
    199198        vsb_cat(sb, "\tvcl_func_f\t*fetch_func;\n\tvcl_func_f\t*deliver_fun"); 
    200         vsb_cat(sb, "c;\n\tvcl_func_f\t*timeout_func;\n"); 
    201         vsb_cat(sb, "\tvcl_func_f\t*error_func;\n};\n"); 
     199        vsb_cat(sb, "c;\n\tvcl_func_f\t*error_func;\n"); 
     200        vsb_cat(sb, "};\n"); 
    202201 
    203202        /* ../../include/vrt.h */ 
  • trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl

    r4099 r4100  
    4343        {fetch          {error restart pass deliver}} 
    4444        {deliver        {restart deliver}} 
    45         {timeout        {fetch discard}} 
    4645        {error          {restart deliver}} 
    4746} 
  • trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl

    r4099 r4100  
    234234    { obj.ttl 
    235235        RW TIME 
    236         {                         hit               timeout error} 
     236        {                         hit               error} 
    237237        "const struct sess *" 
    238238    } 
    239239    { obj.grace 
    240240        RW TIME 
    241         {                         hit               timeout error} 
     241        {                         hit               error} 
    242242        "const struct sess *" 
    243243    } 
    244244    { obj.lastuse 
    245245        RO TIME 
    246         {                         hit       deliver timeout error} 
     246        {                         hit       deliver error} 
    247247        "const struct sess *" 
    248248    } 
     
    281281    { now 
    282282            RO TIME 
    283             {recv pipe pass hash miss hit fetch deliver timeout} 
     283            {recv pipe pass hash miss hit fetch deliver } 
    284284            "const struct sess *" 
    285285    } 
    286286    { req.backend.healthy       RO BOOL 
    287             {recv pipe pass hash miss hit fetch deliver timeout} 
     287            {recv pipe pass hash miss hit fetch deliver } 
    288288            "const struct sess *" 
    289289    } 
  • trunk/varnish-cache/lib/libvcl/vcc_obj.c

    r4099 r4100  
    11/* 
    2  * $Id: vcc_gen_obj.tcl 4066 2009-05-10 21:21:36Z sky $ 
     2 * $Id: vcc_gen_obj.tcl 4099 2009-06-08 21:40:48Z phk $ 
    33 * 
    44 * NB:  This file is machine generated, DO NOT EDIT! 
     
    216216            "VRT_r_obj_ttl(sp)",            "VRT_l_obj_ttl(sp, ", 
    217217            V_RW,           0, 
    218             VCL_MET_HIT | VCL_MET_TIMEOUT | VCL_MET_ERROR 
     218            VCL_MET_HIT | VCL_MET_ERROR 
    219219        }, 
    220220        { "obj.grace", TIME, 9, 
    221221            "VRT_r_obj_grace(sp)",          "VRT_l_obj_grace(sp, ", 
    222222            V_RW,           0, 
    223             VCL_MET_HIT | VCL_MET_TIMEOUT | VCL_MET_ERROR 
     223            VCL_MET_HIT | VCL_MET_ERROR 
    224224        }, 
    225225        { "obj.lastuse", TIME, 11, 
    226226            "VRT_r_obj_lastuse(sp)",        NULL, 
    227227            V_RO,           0, 
    228             VCL_MET_HIT | VCL_MET_DELIVER | VCL_MET_TIMEOUT | VCL_MET_ERROR 
     228            VCL_MET_HIT | VCL_MET_DELIVER | VCL_MET_ERROR 
    229229        }, 
    230230        { "obj.hash", STRING, 8, 
     
    258258            VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH 
    259259             | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER 
    260              | VCL_MET_TIMEOUT 
    261260        }, 
    262261        { "req.backend.healthy", BOOL, 19, 
     
    265264            VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH 
    266265             | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER 
    267              | VCL_MET_TIMEOUT 
    268266        }, 
    269267        { NULL } 
  • trunk/varnish-cache/man/vcl.7so

    r4025 r4100  
    445445Deliver the object to the client. 
    446446.El 
    447 .\" vcl_timeout 
    448 .It Cm vcl_timeout 
    449 Called by the reaper thread shortly before a cached document reaches 
    450 its expiry time. 
    451 .Pp 
    452 The 
    453 .Cm vcl_timeout 
    454 subroutine may terminate with one of the following keywords: 
    455 .Bl -tag -width indent 
    456 .It Cm fetch 
    457 Request a fresh copy of the object from the backend. 
    458 .It Cm discard 
    459 Discard the object. 
    460 .El 
    461 .\" vcl_discard 
    462 .It Cm vcl_discard 
    463 Called by the reaper thread when a cached document is about to be 
    464 discarded, either because it has expired or because space is running 
    465 low. 
    466 .Pp 
    467 The 
    468 .Cm vcl_discard 
    469 subroutine may terminate with one of the following keywords: 
    470 .Bl -tag -width indent 
    471 .It Cm discard 
    472 Discard the object. 
    473 .It Cm keep 
    474 Keep the object in cache. 
    475 .El 
    476447.El 
    477448.Pp