[#6] services/object: Remove pointer unneeded indirections

All `Service` are accessed by pointer.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2022-12-30 14:19:42 +03:00
parent 617988460b
commit 8b50b042c4
12 changed files with 83 additions and 107 deletions

View file

@ -45,31 +45,30 @@ type headerSource struct {
incompleteObjectHeaders bool incompleteObjectHeaders bool
} }
func defaultCfg() *cfg { func (c *cfg) initDefault() {
return &cfg{ c.storage = new(localStorage)
storage: new(localStorage),
}
} }
func NewMessageHeaderSource(opts ...Option) (eaclSDK.TypedHeaderSource, error) { func NewMessageHeaderSource(opts ...Option) (eaclSDK.TypedHeaderSource, error) {
cfg := defaultCfg() var c cfg
c.initDefault()
for i := range opts { for i := range opts {
opts[i](cfg) opts[i](&c)
} }
if cfg.msg == nil { if c.msg == nil {
return nil, errors.New("message is not provided") return nil, errors.New("message is not provided")
} }
var res headerSource var res headerSource
err := cfg.readObjectHeaders(&res) err := c.readObjectHeaders(&res)
if err != nil { if err != nil {
return nil, err return nil, err
} }
res.requestHeaders = requestHeaders(cfg.msg) res.requestHeaders = requestHeaders(c.msg)
return res, nil return res, nil
} }

View file

@ -21,7 +21,7 @@ import (
// Service checks basic ACL rules. // Service checks basic ACL rules.
type Service struct { type Service struct {
*cfg cfg
c senderClassifier c senderClassifier
} }
@ -72,18 +72,17 @@ type cfg struct {
next object.ServiceServer next object.ServiceServer
} }
func defaultCfg() *cfg { func (c *cfg) initDefault() {
return &cfg{ c.log = &logger.Logger{Logger: zap.L()}
log: &logger.Logger{Logger: zap.L()},
}
} }
// New is a constructor for object ACL checking service. // New is a constructor for object ACL checking service.
func New(opts ...Option) Service { func New(opts ...Option) *Service {
cfg := defaultCfg() var s Service
s.cfg.initDefault()
for i := range opts { for i := range opts {
opts[i](cfg) opts[i](&s.cfg)
} }
panicOnNil := func(v any, name string) { panicOnNil := func(v any, name string) {
@ -92,20 +91,18 @@ func New(opts ...Option) Service {
} }
} }
panicOnNil(cfg.next, "next Service") panicOnNil(s.cfg.next, "next Service")
panicOnNil(cfg.nm, "netmap client") panicOnNil(s.cfg.nm, "netmap client")
panicOnNil(cfg.irFetcher, "inner Ring fetcher") panicOnNil(s.cfg.irFetcher, "inner Ring fetcher")
panicOnNil(cfg.checker, "acl checker") panicOnNil(s.cfg.checker, "acl checker")
panicOnNil(cfg.containers, "container source") panicOnNil(s.cfg.containers, "container source")
return Service{ s.c = senderClassifier{
cfg: cfg, log: s.cfg.log,
c: senderClassifier{ innerRing: s.cfg.irFetcher,
log: cfg.log, netmap: s.cfg.nm,
innerRing: cfg.irFetcher,
netmap: cfg.nm,
},
} }
return &s
} }
// Get implements ServiceServer interface, makes ACL checks and calls // Get implements ServiceServer interface, makes ACL checks and calls

View file

@ -15,7 +15,7 @@ import (
// Service utility serving requests of Object.Get service. // Service utility serving requests of Object.Get service.
type Service struct { type Service struct {
*cfg cfg
} }
// Option is a Service's constructor option. // Option is a Service's constructor option.
@ -60,24 +60,21 @@ type cfg struct {
keyStorage *util.KeyStorage keyStorage *util.KeyStorage
} }
func defaultCfg() *cfg { func (c *cfg) initDefault() {
return &cfg{ c.log = &logger.Logger{Logger: zap.L()}
log: &logger.Logger{Logger: zap.L()},
}
} }
// New creates, initializes and returns utility serving // New creates, initializes and returns utility serving
// Object.Get service requests. // Object.Get service requests.
func New(opts ...Option) *Service { func New(opts ...Option) *Service {
c := defaultCfg() var s Service
s.cfg.initDefault()
for i := range opts { for i := range opts {
opts[i](c) opts[i](&s.cfg)
} }
return &Service{ return &s
cfg: c,
}
} }
// WithLogger returns option to specify Delete service's logger. // WithLogger returns option to specify Delete service's logger.

View file

@ -9,7 +9,7 @@ import (
// Service implements Delete operation of Object service v2. // Service implements Delete operation of Object service v2.
type Service struct { type Service struct {
*cfg cfg
} }
// Option represents Service constructor option. // Option represents Service constructor option.
@ -21,15 +21,13 @@ type cfg struct {
// NewService constructs Service instance from provided options. // NewService constructs Service instance from provided options.
func NewService(opts ...Option) *Service { func NewService(opts ...Option) *Service {
c := new(cfg) var s Service
for i := range opts { for i := range opts {
opts[i](c) opts[i](&s.cfg)
} }
return &Service{ return &s
cfg: c,
}
} }
// Delete calls internal service. // Delete calls internal service.

View file

@ -211,7 +211,7 @@ func TestGetLocalOnly(t *testing.T) {
ctx := context.Background() ctx := context.Background()
newSvc := func(storage *testStorage) *Service { newSvc := func(storage *testStorage) *Service {
svc := &Service{cfg: new(cfg)} svc := &Service{}
svc.log = test.NewLogger(false) svc.log = test.NewLogger(false)
svc.localStorage = storage svc.localStorage = storage
svc.assembly = true svc.assembly = true
@ -473,7 +473,7 @@ func TestGetRemoteSmall(t *testing.T) {
container.CalculateID(&idCnr, cnr) container.CalculateID(&idCnr, cnr)
newSvc := func(b *testPlacementBuilder, c *testClientCache) *Service { newSvc := func(b *testPlacementBuilder, c *testClientCache) *Service {
svc := &Service{cfg: new(cfg)} svc := &Service{}
svc.log = test.NewLogger(false) svc.log = test.NewLogger(false)
svc.localStorage = newTestStorage() svc.localStorage = newTestStorage()
svc.assembly = true svc.assembly = true
@ -1150,7 +1150,7 @@ func TestGetFromPastEpoch(t *testing.T) {
c22 := newTestClient() c22 := newTestClient()
c22.addResult(addr, obj, nil) c22.addResult(addr, obj, nil)
svc := &Service{cfg: new(cfg)} svc := &Service{}
svc.log = test.NewLogger(false) svc.log = test.NewLogger(false)
svc.localStorage = newTestStorage() svc.localStorage = newTestStorage()
svc.assembly = true svc.assembly = true

View file

@ -15,7 +15,7 @@ import (
// Service utility serving requests of Object.Get service. // Service utility serving requests of Object.Get service.
type Service struct { type Service struct {
*cfg cfg
} }
// Option is a Service's constructor option. // Option is a Service's constructor option.
@ -51,27 +51,24 @@ type epochSource interface {
Epoch() (uint64, error) Epoch() (uint64, error)
} }
func defaultCfg() *cfg { func (c *cfg) initDefault() {
return &cfg{ c.log = &logger.Logger{Logger: zap.L()}
assembly: true, c.localStorage = new(storageEngineWrapper)
log: &logger.Logger{Logger: zap.L()}, c.assembly = true
localStorage: new(storageEngineWrapper), c.clientCache = new(clientCacheWrapper)
clientCache: new(clientCacheWrapper),
}
} }
// New creates, initializes and returns utility serving // New creates, initializes and returns utility serving
// Object.Get service requests. // Object.Get service requests.
func New(opts ...Option) *Service { func New(opts ...Option) *Service {
c := defaultCfg() var s Service
s.cfg.initDefault()
for i := range opts { for i := range opts {
opts[i](c) opts[i](&s.cfg)
} }
return &Service{ return &s
cfg: c,
}
} }
// WithLogger returns option to specify Get service's logger. // WithLogger returns option to specify Get service's logger.

View file

@ -13,7 +13,7 @@ import (
// Service implements Get operation of Object service v2. // Service implements Get operation of Object service v2.
type Service struct { type Service struct {
*cfg cfg
} }
// Option represents Service constructor option. // Option represents Service constructor option.
@ -27,15 +27,13 @@ type cfg struct {
// NewService constructs Service instance from provided options. // NewService constructs Service instance from provided options.
func NewService(opts ...Option) *Service { func NewService(opts ...Option) *Service {
c := new(cfg) var s Service
for i := range opts { for i := range opts {
opts[i](c) opts[i](&s.cfg)
} }
return &Service{ return &s
cfg: c,
}
} }
// Get calls internal service and returns v2 object stream. // Get calls internal service and returns v2 object stream.

View file

@ -22,7 +22,7 @@ type MaxSizeSource interface {
} }
type Service struct { type Service struct {
*cfg cfg
} }
type Option func(*cfg) type Option func(*cfg)
@ -57,31 +57,28 @@ type cfg struct {
log *logger.Logger log *logger.Logger
} }
func defaultCfg() *cfg { func (c *cfg) initDefault() {
return &cfg{ c.remotePool = util.NewPseudoWorkerPool()
remotePool: util.NewPseudoWorkerPool(), c.localPool = util.NewPseudoWorkerPool()
localPool: util.NewPseudoWorkerPool(), c.log = &logger.Logger{Logger: zap.L()}
log: &logger.Logger{Logger: zap.L()},
}
} }
func NewService(opts ...Option) *Service { func NewService(opts ...Option) *Service {
c := defaultCfg() var s Service
s.cfg.initDefault()
for i := range opts { for i := range opts {
opts[i](c) opts[i](&s.cfg)
} }
c.fmtValidator = object.NewFormatValidator(c.fmtValidatorOpts...) s.cfg.fmtValidator = object.NewFormatValidator(s.cfg.fmtValidatorOpts...)
return &Service{ return &s
cfg: c,
}
} }
func (p *Service) Put(ctx context.Context) (*Streamer, error) { func (p *Service) Put(ctx context.Context) (*Streamer, error) {
return &Streamer{ return &Streamer{
cfg: p.cfg, cfg: &p.cfg,
ctx: ctx, ctx: ctx,
}, nil }, nil
} }

View file

@ -11,7 +11,7 @@ import (
// Service implements Put operation of Object service v2. // Service implements Put operation of Object service v2.
type Service struct { type Service struct {
*cfg cfg
} }
// Option represents Service constructor option. // Option represents Service constructor option.
@ -24,15 +24,13 @@ type cfg struct {
// NewService constructs Service instance from provided options. // NewService constructs Service instance from provided options.
func NewService(opts ...Option) *Service { func NewService(opts ...Option) *Service {
c := new(cfg) var s Service
for i := range opts { for i := range opts {
opts[i](c) opts[i](&s.cfg)
} }
return &Service{ return &s
cfg: c,
}
} }
// Put calls internal service and returns v2 object streamer. // Put calls internal service and returns v2 object streamer.

View file

@ -146,7 +146,7 @@ func TestGetLocalOnly(t *testing.T) {
ctx := context.Background() ctx := context.Background()
newSvc := func(storage *testStorage) *Service { newSvc := func(storage *testStorage) *Service {
svc := &Service{cfg: new(cfg)} svc := &Service{}
svc.log = test.NewLogger(false) svc.log = test.NewLogger(false)
svc.localStorage = storage svc.localStorage = storage
@ -248,7 +248,7 @@ func TestGetRemoteSmall(t *testing.T) {
container.CalculateID(&id, cnr) container.CalculateID(&id, cnr)
newSvc := func(b *testPlacementBuilder, c *testClientCache) *Service { newSvc := func(b *testPlacementBuilder, c *testClientCache) *Service {
svc := &Service{cfg: new(cfg)} svc := &Service{}
svc.log = test.NewLogger(false) svc.log = test.NewLogger(false)
svc.localStorage = newTestStorage() svc.localStorage = newTestStorage()
@ -357,7 +357,7 @@ func TestGetFromPastEpoch(t *testing.T) {
ids22 := generateIDs(10) ids22 := generateIDs(10)
c22.addResult(idCnr, ids22, nil) c22.addResult(idCnr, ids22, nil)
svc := &Service{cfg: new(cfg)} svc := &Service{}
svc.log = test.NewLogger(false) svc.log = test.NewLogger(false)
svc.localStorage = newTestStorage() svc.localStorage = newTestStorage()

View file

@ -15,7 +15,7 @@ import (
// Service is an utility serving requests // Service is an utility serving requests
// of Object.Search service. // of Object.Search service.
type Service struct { type Service struct {
*cfg cfg
} }
// Option is a Service's constructor option. // Option is a Service's constructor option.
@ -55,25 +55,22 @@ type epochSource interface {
Epoch() (uint64, error) Epoch() (uint64, error)
} }
func defaultCfg() *cfg { func (c *cfg) initDefault() {
return &cfg{ c.log = &logger.Logger{Logger: zap.L()}
log: &logger.Logger{Logger: zap.L()}, c.clientConstructor = new(clientConstructorWrapper)
clientConstructor: new(clientConstructorWrapper),
}
} }
// New creates, initializes and returns utility serving // New creates, initializes and returns utility serving
// Object.Get service requests. // Object.Get service requests.
func New(opts ...Option) *Service { func New(opts ...Option) *Service {
c := defaultCfg() var s Service
s.cfg.initDefault()
for i := range opts { for i := range opts {
opts[i](c) opts[i](&s.cfg)
} }
return &Service{ return &s
cfg: c,
}
} }
// WithLogger returns option to specify Get service's logger. // WithLogger returns option to specify Get service's logger.

View file

@ -9,7 +9,7 @@ import (
// Service implements Search operation of Object service v2. // Service implements Search operation of Object service v2.
type Service struct { type Service struct {
*cfg cfg
} }
// Option represents Service constructor option. // Option represents Service constructor option.
@ -23,15 +23,13 @@ type cfg struct {
// NewService constructs Service instance from provided options. // NewService constructs Service instance from provided options.
func NewService(opts ...Option) *Service { func NewService(opts ...Option) *Service {
c := new(cfg) var s Service
for i := range opts { for i := range opts {
opts[i](c) opts[i](&s.cfg)
} }
return &Service{ return &s
cfg: c,
}
} }
// Search calls internal service and returns v2 object stream. // Search calls internal service and returns v2 object stream.