add request context helper #751
No reviewers
Labels
No labels
action
check-aws
action
discussion-needed
action
for-external-contributors
action
for-newcomers
action
more-info-needed
action
need-funding
action
triage-required
kind
correctness
kind
ideas
kind
improvement
kind
performance
kind
testing
kind
usability
kind
wrong-behavior
prio
critical
prio
low
scope
admin-api
scope
background-healing
scope
build
scope
documentation
scope
k8s
scope
layout
scope
metadata
scope
ops
scope
rpc
scope
s3-api
scope
security
scope
telemetry
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: Deuxfleurs/garage#751
Loading…
Reference in a new issue
No description provided.
Delete branch "yuka/garage:req-ctx"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
As suggested by LX, add a request context helper which contains a bunch of variables which are passed to almost all API request handlers.
Additionally, limit bucket.state.as_option.unwrap() occurrences to only directly after the get_existing_bucket. Since the api_server already does get_existing_bucket, it knows for sure that the bucket exists in a non-deleted state, so it can unwrap the bucket state/params and pass them through the request context, making the unwrap() in the request handler unnecessary.
3b00c43e15
to4a354a5735
4a354a5735
todaee9b75c4
daee9b75c4
to7b516ef3c4
Does this patch apply easily to the main (v0.9) branch ? Because if it does it would be nice to have it there, to minimize divergence between the two.
7b516ef3c4
toc1b6fd48bc
Rebased and changed the target branch to main
I wonder if the hyper Request should also be made a part of the request context
I think we should avoid adding the Request in there for now, I'm afraid it might add more noise and not really help refactor anything.
The objetive of this diff is to make the BucketParams available everywhere in the functions that handle API paths, because this will be necessary to have per-bucket consistency levels, and later on, different storage pools. In its current form, I find this patch not very satisfying because it seems to add more lines/noise than it actually avoids, but later on we can expect that it will be usefull.
There are maybe two things I would like to ask you to do before merging:
Uniformize the convention for receiving a ReqCtx in all of the handler conventions. I've seen three patterns throughout the code: destructure the ReqCtx in the list of arguments (e.g.
handle_create_multipart_upload
), destructure the ReqCtx at the beginning of the function (e.g.handle_put_part
), and have a separate funciton that destructures the ReqCtx and calls the original function (e.g.handle_head
). My recommendation would be to use the second pattern (destructure ReqCtx using a let binding at the beginning of the handler function) for all requests.I don't like that we are writing this kind of things in all of the functions that modify the bucket parameters:
I think we should add a helper to the Bucket struct in bucket_table.rs so that we can just write
Bucket::present(bucket_id, bucket_params)
.Thanks :)
(see comment above)
Oops, this is what I did in the beginning, but then changed to the second pattern in case the whole context needs to be passed to a helper function.
This is what I do now in all cases where it is possible.
This has a specific reason: The web_server.rs calls handle_head without providing an access/api key. So the handle_head_without_ctx is also used directly from elsewhere.
This was also my intent with the exception seen above.
c1b6fd48bc
to639f4d4b0f
639f4d4b0f
tofb55682c66
✅ Implemented the suggestions as far as possible
Thanks, I synced the next-0.10 branch to include these changes