[#277] getsvc: Drop cyclic struct dependency

Drop cyclic dependency between execCtx and Service.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-04-24 11:36:15 +03:00 committed by Evgenii Stratonikov
parent 591c4e7d50
commit 1440450606
5 changed files with 45 additions and 20 deletions

View file

@ -97,18 +97,16 @@ func equalAddresses(a, b oid.Address) bool {
} }
func (exec *execCtx) HeadObject(ctx context.Context, id oid.ID) (*objectSDK.Object, error) { func (exec *execCtx) HeadObject(ctx context.Context, id oid.ID) (*objectSDK.Object, error) {
p := exec.prm w := NewSimpleObjectWriter()
p := RequestParameters{}
p.common = p.common.WithLocalOnly(false) p.common = p.common.WithLocalOnly(false)
p.addr.SetContainer(exec.containerID()) p.addr.SetContainer(exec.containerID())
p.addr.SetObject(id) p.addr.SetObject(id)
p.head = true
p.SetHeaderWriter(w)
prm := HeadPrm{ err := exec.getDetached(ctx, p)
commonPrm: p.commonPrm,
}
w := NewSimpleObjectWriter()
prm.SetHeaderWriter(w)
err := exec.svc.Head(ctx, prm)
if err != nil { if err != nil {
return nil, err return nil, err
@ -128,8 +126,26 @@ func (exec *execCtx) GetObject(ctx context.Context, id oid.ID, rng *objectSDK.Ra
p.addr.SetContainer(exec.containerID()) p.addr.SetContainer(exec.containerID())
p.addr.SetObject(id) p.addr.SetObject(id)
if err := exec.svc.get(ctx, p); err != nil { if err := exec.getDetached(ctx, p); err != nil {
return nil, err return nil, err
} }
return w.Object(), nil return w.Object(), nil
} }
func (exec *execCtx) getDetached(ctx context.Context, prm RequestParameters) error {
detachedExecutor := &execCtx{
keyStore: exec.keyStore,
traverserGenerator: exec.traverserGenerator,
remoteStorageConstructor: exec.remoteStorageConstructor,
epochSource: exec.epochSource,
localStorage: exec.localStorage,
prm: prm,
infoSplit: objectSDK.NewSplitInfo(),
log: exec.log,
}
detachedExecutor.execute(ctx)
return detachedExecutor.statusError.err
}

View file

@ -27,8 +27,6 @@ type RequestParameters struct {
} }
type execCtx struct { type execCtx struct {
svc *Service
prm RequestParameters prm RequestParameters
statusError statusError
@ -40,6 +38,12 @@ type execCtx struct {
collectedObject *objectSDK.Object collectedObject *objectSDK.Object
curProcEpoch uint64 curProcEpoch uint64
keyStore keyStorage
epochSource epochSource
traverserGenerator traverserGenerator
remoteStorageConstructor remoteStorageConstructor
localStorage localStorage
} }
const ( const (
@ -96,7 +100,7 @@ func (exec execCtx) key() (*ecdsa.PrivateKey, error) {
} }
} }
return exec.svc.keyStore.GetKey(sessionInfo) return exec.keyStore.GetKey(sessionInfo)
} }
func (exec *execCtx) canAssemble() bool { func (exec *execCtx) canAssemble() bool {
@ -133,7 +137,7 @@ func (exec *execCtx) initEpoch() bool {
return true return true
} }
e, err := exec.svc.epochSource.Epoch() e, err := exec.epochSource.Epoch()
switch { switch {
default: default:
@ -154,7 +158,7 @@ func (exec *execCtx) initEpoch() bool {
func (exec *execCtx) generateTraverser(addr oid.Address) (*placement.Traverser, bool) { func (exec *execCtx) generateTraverser(addr oid.Address) (*placement.Traverser, bool) {
obj := addr.Object() obj := addr.Object()
t, err := exec.svc.traverserGenerator.GenerateTraverser(addr.Container(), &obj, exec.curProcEpoch) t, err := exec.traverserGenerator.GenerateTraverser(addr.Container(), &obj, exec.curProcEpoch)
switch { switch {
default: default:
@ -172,7 +176,7 @@ func (exec *execCtx) generateTraverser(addr oid.Address) (*placement.Traverser,
} }
func (exec execCtx) getRemoteStorage(info clientcore.NodeInfo) (remoteStorage, bool) { func (exec execCtx) getRemoteStorage(info clientcore.NodeInfo) (remoteStorage, bool) {
rs, err := exec.svc.remoteStorageConstructor.Get(info) rs, err := exec.remoteStorageConstructor.Get(info)
if err != nil { if err != nil {
exec.status = statusUndefined exec.status = statusUndefined
exec.err = err exec.err = err

View file

@ -67,7 +67,12 @@ func (s *Service) Head(ctx context.Context, prm HeadPrm) error {
func (s *Service) get(ctx context.Context, prm RequestParameters) error { func (s *Service) get(ctx context.Context, prm RequestParameters) error {
exec := &execCtx{ exec := &execCtx{
svc: s, keyStore: s.keyStore,
traverserGenerator: s.traverserGenerator,
remoteStorageConstructor: s.remoteStorageConstructor,
epochSource: s.epochSource,
localStorage: s.localStorage,
prm: prm, prm: prm,
infoSplit: object.NewSplitInfo(), infoSplit: object.NewSplitInfo(),
} }

View file

@ -52,10 +52,10 @@ func (exec *execCtx) executeLocal(ctx context.Context) {
func (exec *execCtx) get(ctx context.Context) (*objectSDK.Object, error) { func (exec *execCtx) get(ctx context.Context) (*objectSDK.Object, error) {
if exec.headOnly() { if exec.headOnly() {
return exec.svc.localStorage.Head(ctx, exec.address(), exec.isRaw()) return exec.localStorage.Head(ctx, exec.address(), exec.isRaw())
} }
if rng := exec.ctxRange(); rng != nil { if rng := exec.ctxRange(); rng != nil {
return exec.svc.localStorage.Range(ctx, exec.address(), rng) return exec.localStorage.Range(ctx, exec.address(), rng)
} }
return exec.svc.localStorage.Get(ctx, exec.address()) return exec.localStorage.Get(ctx, exec.address())
} }

View file

@ -158,7 +158,7 @@ func (p *commonPrm) WithCachedSignerKey(signerKey *ecdsa.PrivateKey) {
} }
// SetHeaderWriter sets target component to write the object header. // SetHeaderWriter sets target component to write the object header.
func (p *HeadPrm) SetHeaderWriter(w HeaderWriter) { func (p *commonPrm) SetHeaderWriter(w HeaderWriter) {
p.objWriter = &partWriter{ p.objWriter = &partWriter{
headWriter: w, headWriter: w,
} }