Commit 8cfb4e9e authored by Tollef Fog Heen's avatar Tollef Fog Heen

Merge r3526: Add a new paramter "purge_hash" which defaults to "off".

Only save the hash-string in the session workspace and objects when
this paramter is set to "on".

For sites with many small objects, this will save significant VM.

When this paramter is set to "off", the "purge.hash" facility will
not work, but this should not be a problem, because the new purging
facility allow much more expressive purging, the typical case
being:

        purge req.http.host ~ www.foo.com && req.url ~ "article2383"



git-svn-id: http://www.varnish-cache.org/svn/branches/2.0@3714 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent d970c768
......@@ -607,6 +607,14 @@ ccf_purge_hash(struct cli *cli, const char * const *av, void *priv)
const char *aav[6];
(void)priv;
if (!save_hash) {
cli_out(cli,
"purge.hash not possible.\n"
"Set the \"purge_hash\" parameter to on\n"
"and restart the varnish worker process to enable.\n");
cli_result(cli, CLIS_CANT);
return;
}
aav[0] = NULL;
aav[1] = "purge";
aav[2] = "obj.hash";
......
......@@ -69,6 +69,7 @@
#include "vsha256.h"
static const struct hash_slinger *hash;
unsigned save_hash;
double
HSH_Grace(double g)
......@@ -151,6 +152,8 @@ HSH_Copy(const struct sess *sp, struct objhead *oh)
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
if (!save_hash)
return;
oh->hash = malloc(sp->lhashptr);
XXXAN(oh->hash);
......@@ -172,6 +175,10 @@ HSH_Prepare(struct sess *sp, unsigned nhashcount)
char *p;
unsigned u;
SHA256_Init(sp->wrk->sha256ctx);
if (!save_hash)
return;
/* Allocate the pointers we need, align properly. */
sp->lhashptr = 1; /* space for NUL */
sp->ihashptr = 0;
......@@ -184,7 +191,6 @@ HSH_Prepare(struct sess *sp, unsigned nhashcount)
if (u)
p += sizeof(const char *) - u;
sp->hashptr = (void*)p;
SHA256_Init(sp->wrk->sha256ctx);
}
void
......@@ -196,6 +202,15 @@ HSH_AddString(struct sess *sp, const char *str)
str = "";
l = strlen(str);
SHA256_Update(sp->wrk->sha256ctx, str, l);
SHA256_Update(sp->wrk->sha256ctx, "#", 1);
if (params->log_hash)
WSP(sp, SLT_Hash, "%s", str);
if (!save_hash)
return;
/*
* XXX: handle this by bouncing sp->vcl->nhashcount when it fails
* XXX: and dispose of this request either by reallocating the
......@@ -207,8 +222,6 @@ HSH_AddString(struct sess *sp, const char *str)
sp->hashptr[sp->ihashptr + 1] = str + l;
sp->ihashptr += 2;
sp->lhashptr += l + 1;
SHA256_Update(sp->wrk->sha256ctx, str, l);
SHA256_Update(sp->wrk->sha256ctx, "#", 1);
}
struct object *
......@@ -284,8 +297,6 @@ HSH_Lookup(struct sess *sp)
if (o->hits < INT_MAX)
o->hits++;
Lck_Unlock(&oh->mtx);
if (params->log_hash)
WSP(sp, SLT_Hash, "%s", oh->hash);
(void)hash->deref(oh);
return (o);
}
......@@ -315,8 +326,6 @@ HSH_Lookup(struct sess *sp)
grace_o->refcnt++;
}
Lck_Unlock(&oh->mtx);
if (params->log_hash)
WSP(sp, SLT_Hash, "%s", oh->hash);
/*
* XXX: This may be too early, relative to pass objects.
* XXX: possibly move to when we commit to have it in the cache.
......@@ -467,6 +476,7 @@ void
HSH_Init(void)
{
save_hash = params->save_hash;
hash = heritage.hash;
if (hash->start != NULL)
hash->start();
......
......@@ -105,4 +105,6 @@ struct objhead {
#define hoh_head u.n.u_n_hoh_head
#define hoh_digest u.n.u_n_hoh_digest
};
extern unsigned save_hash;
#endif /* VARNISH_CACHE_CHILD */
......@@ -177,6 +177,9 @@ struct params {
/* Log hash string to shm */
unsigned log_hash;
/* Log hash string to shm */
unsigned save_hash;
/* Log local socket address to shm */
unsigned log_local_addr;
......
......@@ -100,7 +100,8 @@ tweak_generic_timeout_double(struct cli *cli, volatile double *dst, const char *
if (arg != NULL) {
u = strtod(arg, NULL);
if (u < 0) {
cli_out(cli, "Timeout must be greater or equal to zero\n");
cli_out(cli,
"Timeout must be greater or equal to zero\n");
cli_result(cli, CLIS_PARAM);
return;
}
......@@ -714,6 +715,12 @@ static const struct parspec input_parspec[] = {
"Log the hash string to shared memory log.\n",
0,
"off", "bool" },
{ "purge_hash", tweak_bool, &master.save_hash, 0, 0,
"Enable purge.hash command.\n"
"NB: this increases storage requirement per object "
"by the length of the hash string.\n",
MUST_RESTART,
"off", "bool" },
{ "log_local_address", tweak_bool, &master.log_local_addr, 0, 0,
"Log the local address on the TCP connection in the "
"SessionOpen shared memory record.\n",
......
......@@ -11,7 +11,11 @@ server s1 {
txresp -body "11111\n"
} -start
varnish v1 -vcl+backend { } -start
varnish v1 -arg "-ppurge_hash=off" -vcl+backend { } -start
varnish v1 -clierr 300 "purge.hash foo"
varnish v1 -stop
varnish v1 -cliok "param.set purge_hash on"
varnish v1 -start
client c1 {
txreq -url "/foo"
......@@ -22,7 +26,7 @@ client c1 {
client c1 -run
varnish v1 -cli "purge.hash foo"
varnish v1 -cliok "purge.hash foo"
client c1 {
txreq -url "/foo"
......
......@@ -13,7 +13,7 @@ server s1 {
txresp -hdr "foo: 3" -body "foo3"
} -start
varnish v1 -vcl+backend {} -start
varnish v1 -arg "-p purge_hash=on" -vcl+backend {} -start
varnish v1 -cliok "purge.url FOO"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment