Unify parameters in object services #495

Merged
fyrchik merged 10 commits from dstepanov-yadro/frostfs-node:refactor/getsvc_unify_params into master 2023-07-12 07:42:12 +00:00

Now required dependencies are passed as args, other as options.

Closes #294

Now required dependencies are passed as args, other as options. Closes #294
dstepanov-yadro force-pushed refactor/getsvc_unify_params from df939a090d to 842de037cc 2023-07-06 10:05:54 +00:00 Compare
dstepanov-yadro force-pushed refactor/getsvc_unify_params from 842de037cc to 528bcc8f42 2023-07-06 11:34:40 +00:00 Compare
dstepanov-yadro force-pushed refactor/getsvc_unify_params from 528bcc8f42 to 1c79835600 2023-07-06 11:39:22 +00:00 Compare
dstepanov-yadro force-pushed refactor/getsvc_unify_params from 1c79835600 to 08c4e219f0 2023-07-06 11:59:10 +00:00 Compare
dstepanov-yadro changed title from WIP: Unify parameters in object services to Unify parameters in object services 2023-07-06 12:28:00 +00:00
dstepanov-yadro requested review from storage-core-committers 2023-07-06 12:28:05 +00:00
dstepanov-yadro requested review from storage-core-developers 2023-07-06 12:28:05 +00:00
ale64bit approved these changes 2023-07-10 08:27:41 +00:00
@ -38,3 +37,1 @@
func (c *CheckerPrm) SetValidator(v *eaclSDK.Validator) *CheckerPrm {
c.validator = v
return c
type localStorage struct {
Member

why the struct even? just alias it?

why the `struct` even? just alias it?
Author
Member

From here: #495/files

From here: https://git.frostfs.info/TrueCloudLab/frostfs-node/pulls/495/files#diff-65b4b70b0453f2a0abd08c354212feeb6a6680d4
ale64bit marked this conversation as resolved
@ -46,1 +41,3 @@
}
func (s *localStorage) Head(ctx context.Context, addr oid.Address) (*objectSDK.Object, error) {
if s.ls == nil {
return nil, io.ErrUnexpectedEOF
Member

this might hide a more serious error, no? (i.e. a missing/nil argument somewhere)

this might hide a more serious error, no? (i.e. a missing/nil argument somewhere)
Author
Member

again from here: #495/files#diff-65b4b70b0453f2a0abd08c354212feeb6a6680d4

again from here: #495/files#diff-65b4b70b0453f2a0abd08c354212feeb6a6680d4
ale64bit marked this conversation as resolved
@ -75,0 +72,4 @@
opts ...Option) *Service {
c := &cfg{
log: &logger.Logger{Logger: zap.L()},
header: (*headSvcWrapper)(gs),
Member

do we plan to get rid of these casts that scare adults and children alike in another task/PR?

do we plan to get rid of these casts that scare adults and children alike in another task/PR?
Author
Member

fixed

fixed
ale64bit marked this conversation as resolved
aarifullin reviewed 2023-07-10 08:28:12 +00:00
@ -84,0 +80,4 @@
cs container.Source,
opts ...Option) Service {
cfg := &cfg{
log: &logger.Logger{Logger: zap.L()},
Member

I think that New should have log log.Logger parameter that can be used for cfg instance creation. This will support dependency inversion.
From the other side - this barely can be helpful because we do not use mocks

I think that `New` should have `log log.Logger` parameter that can be used for `cfg` instance creation. This will support dependency inversion. From the other side - this barely can be helpful because we do not use mocks
Author
Member

logger can be passed with options, because logger is not mandatory and default logger will be used if it is not proovided

`logger` can be passed with options, because logger is not mandatory and default logger will be used if it is not proovided
aarifullin reviewed 2023-07-10 08:39:56 +00:00
@ -63,0 +62,4 @@
nk netmap.AnnouncedKeys,
nst netmap.State,
opts ...Option) *Service {
c := &cfg{
Member

Here are inevitably many mandatory parameters. Don't you consider to unite some parameters in one struct?

Just for example

type cfgSource struct {
    cs container.Source
    ns netmap.Source
    ms MaxSizeSource
}
Here are inevitably many mandatory parameters. Don't you consider to unite some parameters in one struct? Just for example ```golang type cfgSource struct { cs container.Source ns netmap.Source ms MaxSizeSource } ```
Author
Member

Let's assume that you decided to add a new dependency. If you use a structure with fields, as you suggested, then you can easily forget to initialize one of the fields, and discover it only during execution.

type NewParams struct {
	Dep1Value   Dep1Type
    Dep2Value   Dep2Type
    NewDepValue NewDepType
}


func New(p *NewParams) *Service {
	s := &Service {
    	dep1: p.Dep1Value,
        dep2: p.Dep2Value,
        dep3: p.NewDepValue
    }
}

func createService() *Service {
	return New(&NewParams{
    			Dep1Value: getDep1(),
                Dep2Value: getDep2(),
                // oops, NewDepValue missed
                })
}

In the case of passing by argument, the source code simply will not be assembled until you pass a new dependency.

Let's assume that you decided to add a new dependency. If you use a structure with fields, as you suggested, then you can easily forget to initialize one of the fields, and discover it only during execution. ``` type NewParams struct { Dep1Value Dep1Type Dep2Value Dep2Type NewDepValue NewDepType } func New(p *NewParams) *Service { s := &Service { dep1: p.Dep1Value, dep2: p.Dep2Value, dep3: p.NewDepValue } } func createService() *Service { return New(&NewParams{ Dep1Value: getDep1(), Dep2Value: getDep2(), // oops, NewDepValue missed }) } ``` In the case of passing by argument, the source code simply will not be assembled until you pass a new dependency.
Owner

Another possibility is having a linter which can check whether all struct fields are filled? Like this:

type Prm struct {
	A // param:obligatory
    B // param:obligatory
    C
}
Another possibility is having a linter which can check whether all struct fields are filled? Like this: ``` type Prm struct { A // param:obligatory B // param:obligatory C } ```
Author
Member

This linter must be smart enough to find all if/else branches.

This linter must be smart enough to find all `if/else` branches.
Owner

Well, we could enforce providing all values immediately and move all if/else branches above.

Well, we could _enforce_ providing all values immediately and move all if/else branches above.
Owner

But obviously needs discussion first.

But obviously needs discussion first.
aarifullin approved these changes 2023-07-10 08:40:57 +00:00
dstepanov-yadro force-pushed refactor/getsvc_unify_params from 08c4e219f0 to 0f348270da 2023-07-10 09:20:34 +00:00 Compare
Owner

For commit messages we had services/put, then putsvc (initiated by you, I believe #277/commits ) and now put service. Can we stay with putsvc, aclsvc etc.?

For commit messages we had `services/put`, then `putsvc` (initiated by you, I believe https://git.frostfs.info/TrueCloudLab/frostfs-node/pulls/277/commits ) and now `put service`. Can we stay with `putsvc`, `aclsvc` etc.?
dstepanov-yadro force-pushed refactor/getsvc_unify_params from 0f348270da to 35ecdf062d 2023-07-11 11:03:22 +00:00 Compare
Author
Member

For commit messages we had services/put, then putsvc (initiated by you, I believe #277/commits ) and now put service. Can we stay with putsvc, aclsvc etc.?

Done

> For commit messages we had `services/put`, then `putsvc` (initiated by you, I believe https://git.frostfs.info/TrueCloudLab/frostfs-node/pulls/277/commits ) and now `put service`. Can we stay with `putsvc`, `aclsvc` etc.? Done
aarifullin approved these changes 2023-07-11 11:32:00 +00:00
fyrchik reviewed 2023-07-11 14:56:21 +00:00
@ -85,0 +80,4 @@
acl ACLChecker,
cs container.Source,
opts ...Option) Service {
cfg := &cfg{
Owner

Can we remove panicOnNil below?

Can we remove `panicOnNil` below?
Author
Member

done

done
dstepanov-yadro force-pushed refactor/getsvc_unify_params from 35ecdf062d to bb832702e3 2023-07-11 15:26:51 +00:00 Compare
fyrchik approved these changes 2023-07-12 07:33:09 +00:00
fyrchik merged commit 24eb988897 into master 2023-07-12 07:42:12 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 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#495
No description provided.