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: svn+ssh://projects.linpro.no/svn/varnish/trunk@3526
d4fa192b-c00b-0410-8231-
f00ffab90ce4
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";
#include "vsha256.h"
static const struct hash_slinger *hash;
+unsigned save_hash;
double
HSH_Grace(double g)
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
+ if (!save_hash)
+ return;
oh->hash = malloc(sp->lhashptr);
XXXAN(oh->hash);
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;
if (u)
p += sizeof(const char *) - u;
sp->hashptr = (void*)p;
- SHA256_Init(sp->wrk->sha256ctx);
}
void
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
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 *
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);
}
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.
HSH_Init(void)
{
+ save_hash = params->save_hash;
hash = heritage.hash;
if (hash->start != NULL)
hash->start();
#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 */
/* 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;
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;
}
"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",
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"
client c1 -run
-varnish v1 -cli "purge.hash foo"
+varnish v1 -cliok "purge.hash foo"
client c1 {
txreq -url "/foo"
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"