forked from TrueCloudLab/frostfs-node
[#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:
parent
591c4e7d50
commit
1440450606
5 changed files with 45 additions and 20 deletions
|
@ -97,18 +97,16 @@ func equalAddresses(a, b oid.Address) bool {
|
|||
}
|
||||
|
||||
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.addr.SetContainer(exec.containerID())
|
||||
p.addr.SetObject(id)
|
||||
p.head = true
|
||||
p.SetHeaderWriter(w)
|
||||
|
||||
prm := HeadPrm{
|
||||
commonPrm: p.commonPrm,
|
||||
}
|
||||
|
||||
w := NewSimpleObjectWriter()
|
||||
prm.SetHeaderWriter(w)
|
||||
err := exec.svc.Head(ctx, prm)
|
||||
err := exec.getDetached(ctx, p)
|
||||
|
||||
if err != nil {
|
||||
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.SetObject(id)
|
||||
|
||||
if err := exec.svc.get(ctx, p); err != nil {
|
||||
if err := exec.getDetached(ctx, p); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
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
|
||||
}
|
||||
|
|
|
@ -27,8 +27,6 @@ type RequestParameters struct {
|
|||
}
|
||||
|
||||
type execCtx struct {
|
||||
svc *Service
|
||||
|
||||
prm RequestParameters
|
||||
|
||||
statusError
|
||||
|
@ -40,6 +38,12 @@ type execCtx struct {
|
|||
collectedObject *objectSDK.Object
|
||||
|
||||
curProcEpoch uint64
|
||||
|
||||
keyStore keyStorage
|
||||
epochSource epochSource
|
||||
traverserGenerator traverserGenerator
|
||||
remoteStorageConstructor remoteStorageConstructor
|
||||
localStorage localStorage
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -133,7 +137,7 @@ func (exec *execCtx) initEpoch() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
e, err := exec.svc.epochSource.Epoch()
|
||||
e, err := exec.epochSource.Epoch()
|
||||
|
||||
switch {
|
||||
default:
|
||||
|
@ -154,7 +158,7 @@ func (exec *execCtx) initEpoch() bool {
|
|||
func (exec *execCtx) generateTraverser(addr oid.Address) (*placement.Traverser, bool) {
|
||||
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 {
|
||||
default:
|
||||
|
@ -172,7 +176,7 @@ func (exec *execCtx) generateTraverser(addr oid.Address) (*placement.Traverser,
|
|||
}
|
||||
|
||||
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 {
|
||||
exec.status = statusUndefined
|
||||
exec.err = err
|
||||
|
|
|
@ -67,7 +67,12 @@ func (s *Service) Head(ctx context.Context, prm HeadPrm) error {
|
|||
|
||||
func (s *Service) get(ctx context.Context, prm RequestParameters) error {
|
||||
exec := &execCtx{
|
||||
svc: s,
|
||||
keyStore: s.keyStore,
|
||||
traverserGenerator: s.traverserGenerator,
|
||||
remoteStorageConstructor: s.remoteStorageConstructor,
|
||||
epochSource: s.epochSource,
|
||||
localStorage: s.localStorage,
|
||||
|
||||
prm: prm,
|
||||
infoSplit: object.NewSplitInfo(),
|
||||
}
|
||||
|
|
|
@ -52,10 +52,10 @@ func (exec *execCtx) executeLocal(ctx context.Context) {
|
|||
|
||||
func (exec *execCtx) get(ctx context.Context) (*objectSDK.Object, error) {
|
||||
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 {
|
||||
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())
|
||||
}
|
||||
|
|
|
@ -158,7 +158,7 @@ func (p *commonPrm) WithCachedSignerKey(signerKey *ecdsa.PrivateKey) {
|
|||
}
|
||||
|
||||
// SetHeaderWriter sets target component to write the object header.
|
||||
func (p *HeadPrm) SetHeaderWriter(w HeaderWriter) {
|
||||
func (p *commonPrm) SetHeaderWriter(w HeaderWriter) {
|
||||
p.objWriter = &partWriter{
|
||||
headWriter: w,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue