[#277] getsvc: Extract remote storage

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-04-21 18:21:46 +03:00 committed by Evgenii Stratonikov
parent 30e1b62b67
commit 265d2326a0
5 changed files with 133 additions and 80 deletions

View file

@ -18,12 +18,12 @@ func (exec *execCtx) processNode(ctx context.Context, info client.NodeInfo) bool
exec.log.Debug(logs.ProcessingNode)
client, ok := exec.remoteClient(info)
rs, ok := exec.getRemoteStorage(info)
if !ok {
return true
}
obj, err := client.GetObject(ctx, exec, info)
obj, err := exec.getRemote(ctx, rs, info)
var errSplitInfo *objectSDK.SplitInfoError
var errRemoved *apistatus.ObjectAlreadyRemoved
@ -64,3 +64,37 @@ func (exec *execCtx) processNode(ctx context.Context, info client.NodeInfo) bool
return exec.status != statusUndefined
}
func (exec *execCtx) getRemote(ctx context.Context, rs remoteStorage, info client.NodeInfo) (*objectSDK.Object, error) {
if exec.isForwardingEnabled() {
return rs.ForwardRequest(ctx, info, exec.prm.forwarder)
}
key, err := exec.key()
if err != nil {
return nil, err
}
prm := RemoteRequestParams{
Epoch: exec.curProcEpoch,
TTL: exec.prm.common.TTL(),
PrivateKey: key,
SessionToken: exec.prm.common.SessionToken(),
BearerToken: exec.prm.common.BearerToken(),
XHeaders: exec.prm.common.XHeaders(),
IsRaw: exec.isRaw(),
}
if exec.headOnly() {
return rs.Head(ctx, exec.address(), prm)
}
// we don't specify payload writer because we accumulate
// the object locally (even huge).
if rng := exec.ctxRange(); rng != nil {
// Current spec allows other storage node to deny access,
// fallback to GET here.
return rs.Range(ctx, exec.address(), rng, prm)
}
return rs.Get(ctx, exec.address(), prm)
}