Dmitrii Stepanov
839dead226
Do not replace the access denied error if it was received earlier. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
163 lines
4.3 KiB
Go
163 lines
4.3 KiB
Go
package getsvc
|
|
|
|
import (
|
|
"context"
|
|
"encoding/hex"
|
|
"errors"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/client"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
func (r *request) processNode(ctx context.Context, info client.NodeInfo) bool {
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "getService.processNode")
|
|
defer span.End()
|
|
|
|
r.log.Debug(logs.ProcessingNode, zap.String("node_key", hex.EncodeToString(info.PublicKey())))
|
|
|
|
rs, ok := r.getRemoteStorage(info)
|
|
if !ok {
|
|
return true
|
|
}
|
|
|
|
obj, err := r.getRemote(ctx, rs, info)
|
|
|
|
var errSplitInfo *objectSDK.SplitInfoError
|
|
var errECInfo *objectSDK.ECInfoError
|
|
var errRemoved *apistatus.ObjectAlreadyRemoved
|
|
var errOutOfRange *apistatus.ObjectOutOfRange
|
|
var errAccessDenied *apistatus.ObjectAccessDenied
|
|
|
|
switch {
|
|
default:
|
|
r.log.Debug(logs.GetRemoteCallFailed, zap.Error(err))
|
|
if r.status != statusEC {
|
|
// for raw requests, continue to collect other parts
|
|
r.status = statusUndefined
|
|
if errors.As(err, &errAccessDenied) {
|
|
r.err = err
|
|
} else if r.err == nil || !errors.As(r.err, &errAccessDenied) {
|
|
r.err = new(apistatus.ObjectNotFound)
|
|
}
|
|
}
|
|
return false
|
|
case err == nil:
|
|
r.status = statusOK
|
|
r.err = nil
|
|
|
|
// both object and err are nil only if the original
|
|
// request was forwarded to another node and the object
|
|
// has already been streamed to the requesting party
|
|
if obj != nil {
|
|
r.collectedObject = obj
|
|
r.writeCollectedObject(ctx)
|
|
}
|
|
return true
|
|
case errors.As(err, &errRemoved):
|
|
r.status = statusINHUMED
|
|
r.err = errRemoved
|
|
return true
|
|
case errors.As(err, &errOutOfRange):
|
|
r.status = statusOutOfRange
|
|
r.err = errOutOfRange
|
|
return true
|
|
case errors.As(err, &errSplitInfo):
|
|
r.status = statusVIRTUAL
|
|
mergeSplitInfo(r.splitInfo(), errSplitInfo.SplitInfo())
|
|
r.err = objectSDK.NewSplitInfoError(r.infoSplit)
|
|
return true
|
|
case errors.As(err, &errECInfo):
|
|
r.status = statusEC
|
|
r.err = r.infoEC.addRemote(string(info.PublicKey()), errECInfo.ECInfo())
|
|
if r.isRaw() {
|
|
return false // continue to collect all parts
|
|
}
|
|
return true
|
|
}
|
|
}
|
|
|
|
func (r *request) getRemote(ctx context.Context, rs remoteStorage, info client.NodeInfo) (*objectSDK.Object, error) {
|
|
if r.isForwardingEnabled() {
|
|
return rs.ForwardRequest(ctx, info, r.prm.forwarder)
|
|
}
|
|
|
|
key, err := r.key()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prm := RemoteRequestParams{
|
|
Epoch: r.curProcEpoch,
|
|
TTL: r.prm.common.TTL(),
|
|
PrivateKey: key,
|
|
SessionToken: r.prm.common.SessionToken(),
|
|
BearerToken: r.prm.common.BearerToken(),
|
|
XHeaders: r.prm.common.XHeaders(),
|
|
IsRaw: r.isRaw(),
|
|
}
|
|
|
|
if r.headOnly() {
|
|
return rs.Head(ctx, r.address(), prm)
|
|
}
|
|
// we don't specify payload writer because we accumulate
|
|
// the object locally (even huge).
|
|
if rng := r.ctxRange(); rng != nil {
|
|
// Current spec allows other storage node to deny access,
|
|
// fallback to GET here.
|
|
return rs.Range(ctx, r.address(), rng, prm)
|
|
}
|
|
|
|
return rs.Get(ctx, r.address(), prm)
|
|
}
|
|
|
|
func (r *request) getObjectFromNode(ctx context.Context, addr oid.Address, info client.NodeInfo) (*objectSDK.Object, error) {
|
|
rs, err := r.remoteStorageConstructor.Get(info)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
key, err := r.key()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prm := RemoteRequestParams{
|
|
Epoch: r.curProcEpoch,
|
|
TTL: 1,
|
|
PrivateKey: key,
|
|
SessionToken: r.prm.common.SessionToken(),
|
|
BearerToken: r.prm.common.BearerToken(),
|
|
XHeaders: r.prm.common.XHeaders(),
|
|
}
|
|
|
|
return rs.Get(ctx, addr, prm)
|
|
}
|
|
|
|
func (r *request) headObjectFromNode(ctx context.Context, addr oid.Address, info client.NodeInfo, raw bool) (*objectSDK.Object, error) {
|
|
rs, err := r.remoteStorageConstructor.Get(info)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
key, err := r.key()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prm := RemoteRequestParams{
|
|
Epoch: r.curProcEpoch,
|
|
TTL: 1,
|
|
PrivateKey: key,
|
|
SessionToken: r.prm.common.SessionToken(),
|
|
BearerToken: r.prm.common.BearerToken(),
|
|
XHeaders: r.prm.common.XHeaders(),
|
|
IsRaw: raw,
|
|
}
|
|
|
|
return rs.Head(ctx, addr, prm)
|
|
}
|