Skip to content

Commit

Permalink
Move decision on fetch_chunksize to the storage engine
Browse files Browse the repository at this point in the history
For chunked encoding, we do not know how big the object is ultimately
going to be, so VFP_GetStorage() called ObjGetSpace() with the
fetch_chunksize parameter in this case.

Yet which size is best might differ for different storage engines, and
having the information that the caller does not know the final size
might be relevant. Storage engines could guess that if a request came
in for fetch_chunksize that this _might_ be the "chunked" case, but
that heuristic would be wrong for Objects of just that size advertised
via Content-Length.

So this patch takes the guesswork out of the game by just passing the
magic 0 value down to the storage engine to mean "give me some good
chunk of bytes, I do not know how much I am going to need".
  • Loading branch information
nigoroll committed Feb 19, 2024
1 parent 8cbb4d1 commit d77da13
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
10 changes: 3 additions & 7 deletions bin/varnishd/cache/cache_fetch_proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,15 @@ VFP_Error(struct vfp_ctx *vc, const char *fmt, ...)
enum vfp_status
VFP_GetStorage(struct vfp_ctx *vc, ssize_t *sz, uint8_t **ptr)
{
ssize_t l;

CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC);
AN(sz);
assert(*sz >= 0);
AN(ptr);

l = fetchfrag;
if (l == 0)
l = *sz;
if (l == 0)
l = cache_param->fetch_chunksize;
*sz = l;
if (fetchfrag > 0)
*sz = fetchfrag;

if (!ObjGetSpace(vc->wrk, vc->oc, sz, ptr)) {
*sz = 0;
*ptr = NULL;
Expand Down
3 changes: 2 additions & 1 deletion bin/varnishd/cache/cache_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ ObjIterate(struct worker *wrk, struct objcore *oc,
* is no free space, some will be added first.
*
* The "sz" argument is an input hint of how much space is desired.
* 0 means "unknown", return some default size (maybe fetch_chunksize)
*/

int
Expand All @@ -201,7 +202,7 @@ ObjGetSpace(struct worker *wrk, struct objcore *oc, ssize_t *sz, uint8_t **ptr)
CHECK_OBJ_NOTNULL(oc->boc, BOC_MAGIC);
AN(sz);
AN(ptr);
assert(*sz > 0);
assert(*sz >= 0);

AN(om->objgetspace);
return (om->objgetspace(wrk, oc, sz, ptr));
Expand Down
2 changes: 1 addition & 1 deletion bin/varnishd/storage/storage_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ smd_lsp_getspace(struct worker *wrk, struct objcore *oc, ssize_t *sz,
uint8_t **ptr)
{
AN(sz);
if (*sz > 1)
if (*sz > 2)
(*sz)--;
return (SML_methods.objgetspace(wrk, oc, sz, ptr));
}
Expand Down
2 changes: 2 additions & 0 deletions bin/varnishd/storage/storage_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,8 @@ sml_getspace(struct worker *wrk, struct objcore *oc, ssize_t *sz,
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
AN(sz);
AN(ptr);
if (*sz == 0)
*sz = cache_param->fetch_chunksize;
assert(*sz > 0);

o = sml_getobj(wrk, oc);
Expand Down

0 comments on commit d77da13

Please sign in to comment.