Refactor getsvc #277

Merged
fyrchik merged 7 commits from dstepanov-yadro/frostfs-node:object-3606 into master 2023-04-28 14:03:13 +00:00

The main goal: to make the GET service easier.
The first option is to divide the get service into three services: get, get range, head. But this approach will lead to code duplication. As a result, there will be three complex services.
So I refactored the GET service:

  • extracted dependencies
  • resolved cyclic dependencies between structs
  • renamed types
    Also moved errors to separate files.
The main goal: to make the GET service easier. The first option is to divide the get service into three services: get, get range, head. But this approach will lead to code duplication. As a result, there will be three complex services. So I refactored the GET service: - extracted dependencies - resolved cyclic dependencies between structs - renamed types Also moved errors to separate files.
dstepanov-yadro force-pushed object-3606 from fcf8cf19a3 to 3d58994f8a 2023-04-24 09:13:55 +00:00 Compare
dstepanov-yadro changed title from WIP: Refactor getsvc to Refactor getsvc 2023-04-24 11:26:53 +00:00
dstepanov-yadro requested review from storage-core-committers 2023-04-24 11:26:58 +00:00
dstepanov-yadro requested review from storage-core-developers 2023-04-24 11:26:59 +00:00
dstepanov-yadro force-pushed object-3606 from 19bb559f4f to 88469f9859 2023-04-24 11:30:50 +00:00 Compare
fyrchik reviewed 2023-04-24 15:06:01 +00:00
@ -67,2 +20,2 @@
}
func New(
ks keyStorage,

Why this change? We use functional options in services and you can do everything with both?

Why this change? We use functional options in services and you can do everything with both?
Poster
Collaborator

For example, it was not obvious to me which of the dependencies and options were required and which were not.

So New requires mandatory deps, With... - optional.

For example, it was not obvious to me which of the dependencies and options were required and which were not. So `New` requires mandatory deps, `With...` - optional.
Poster
Collaborator

Fixed back to Option for logger.

Use this pattern for optional arguments in constructors ...

From https://github.com/uber-go/guide/blob/master/style.md#functional-options

Fixed back to Option for logger. > Use this pattern for optional arguments in constructors ... From https://github.com/uber-go/guide/blob/master/style.md#functional-options

Yes, but 5 positional arguments don't look nice either.

Not that I am against the change, but I if we were to commit to a new scheme, I would like to do this atomically across the whole repo. We can create an issue for the discussion.

Yes, but 5 positional arguments don't look nice either. Not that I am against the change, but I if we were to commit to a new scheme, I would like to do this atomically across the whole repo. We can create an issue for the discussion.
Collaborator

I would prefer the positional arguments if they are required. They can be packed into a Options struct if needed.
It seems relatively easy to build incorrect objects in other places as well, because of this.

I would prefer the positional arguments if they are required. They can be packed into a `Options` struct if needed. It seems relatively easy to build incorrect objects in other places as well, because of this.

I like struct, but it seems we do not enforce anything with it either.
However it may be easier to see what arguments are required.

I like struct, but it seems we do not enforce anything with it either. However it may be easier to see what arguments are required.
We can try adopting this linter https://github.com/GaijinEntertainment/go-exhaustruct
Collaborator

Ofc it's not enforced, especially when having pointer fields. But I guess it's a combination of it being conventional and easier to look at the struct and its doc when calling New, rather than at the multiple option builders which might be spread around.

Ofc it's not enforced, especially when having pointer fields. But I guess it's a combination of it being conventional and easier to look at the struct and its doc when calling `New`, rather than at the multiple option builders which might be spread around.
Collaborator

we do not enforce anything with it either.

how about a struct that shows a caller that it contains only the required params + validaion inside New (pointers to be sure it is not a default value)? i do not like 5 positional args too

> we do not enforce anything with it either. how about a struct that shows a caller that it contains only the required params + validaion inside `New` (pointers to be sure it is not a default value)? i do not like 5 positional args too
Poster
Collaborator

we do not enforce anything with it either.

how about a struct that shows a caller that it contains only the required params + validaion inside New (pointers to be sure it is not a default value)? i do not like 5 positional args too

What's the difference? Instead of 5 arguments, there will be a structure with 5 fields that will most likely be filled in when calling the New method.

For example:

But positional arguments have an advantage: if a new dependency is added to the New method, then with a very high probability the program will not assemble until this dependency is added everywhere.

> > we do not enforce anything with it either. > > how about a struct that shows a caller that it contains only the required params + validaion inside `New` (pointers to be sure it is not a default value)? i do not like 5 positional args too What's the difference? Instead of 5 arguments, there will be a structure with 5 fields that will most likely be filled in when calling the `New` method. For example: - `New` declaration: https://git.frostfs.info/TrueCloudLab/frostfs-node/src/branch/master/pkg/innerring/processors/frostfs/processor.go#L88 - `New` call: https://git.frostfs.info/TrueCloudLab/frostfs-node/src/branch/master/pkg/innerring/initialization.go#L412 But positional arguments have an advantage: if a new dependency is added to the `New` method, then with a very high probability the program will not assemble until this dependency is added everywhere.
Collaborator

What's the difference? Instead of 5 arguments, there will be a structure with 5 fields that will most likely be filled in when calling the New method.

For me, it looks unreadable, especially when we provide a bunch of nil vars or empty strings.

> What's the difference? Instead of 5 arguments, there will be a structure with 5 fields that will most likely be filled in when calling the `New` method. For me, it looks unreadable, especially when we provide a bunch of nil vars or empty strings.
Poster
Collaborator

For me, it looks unreadable, especially when we provide a bunch of nil vars or empty strings.

It's about required arguments only. If you can pass nil or empty string as an argument value, i think that this argument is not required.

For not required arguments use Option.

> For me, it looks unreadable, especially when we provide a bunch of nil vars or empty strings. It's about required arguments only. If you can pass nil or empty string as an argument value, i think that this argument is not required. For not required arguments use Option.
dstepanov-yadro force-pushed object-3606 from 88469f9859 to b9d557fbff 2023-04-25 07:58:53 +00:00 Compare
carpawell reviewed 2023-04-26 16:28:14 +00:00
@ -109,3 +109,1 @@
w := NewSimpleObjectWriter()
prm.SetHeaderWriter(w)
err := exec.svc.Head(ctx, prm)
err := r.getDetached(ctx, p)
Collaborator

what does it mean? 1m was not enough for me to understand "detached" here

what does it mean? 1m was not enough for me to understand "detached" here
Poster
Collaborator

renamed

renamed
dstepanov-yadro force-pushed object-3606 from b9d557fbff to 0f73c7bb1b 2023-04-28 08:24:07 +00:00 Compare
dstepanov-yadro force-pushed object-3606 from 0f73c7bb1b to 8de72f144d 2023-04-28 08:37:32 +00:00 Compare
fyrchik approved these changes 2023-04-28 10:05:10 +00:00
fyrchik merged commit 22d47376a6 into master 2023-04-28 14:03:13 +00:00
Sign in to join this conversation.
No reviewers
TrueCloudLab/storage-core-developers
No Milestone
No Assignees
5 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: TrueCloudLab/frostfs-node#277
There is no content yet.