2020-12-02 23:45:25 +00:00
|
|
|
package getsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-05-18 08:12:51 +00:00
|
|
|
"errors"
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2023-03-13 11:37:35 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/pkg/tracing"
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/client"
|
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2020-12-02 23:45:25 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2023-04-24 09:09:43 +00:00
|
|
|
func (r *request) processNode(ctx context.Context, info client.NodeInfo) bool {
|
2023-03-13 11:37:35 +00:00
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "getService.processNode")
|
|
|
|
defer span.End()
|
|
|
|
|
2023-04-24 09:09:43 +00:00
|
|
|
r.log.Debug(logs.ProcessingNode)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2023-04-24 09:09:43 +00:00
|
|
|
rs, ok := r.getRemoteStorage(info)
|
2020-12-02 23:45:25 +00:00
|
|
|
if !ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2023-04-24 09:09:43 +00:00
|
|
|
obj, err := r.getRemote(ctx, rs, info)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
var errSplitInfo *objectSDK.SplitInfoError
|
2022-03-17 08:03:58 +00:00
|
|
|
var errRemoved *apistatus.ObjectAlreadyRemoved
|
2022-06-29 17:33:48 +00:00
|
|
|
var errOutOfRange *apistatus.ObjectOutOfRange
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
switch {
|
|
|
|
default:
|
2022-03-17 08:03:58 +00:00
|
|
|
var errNotFound apistatus.ObjectNotFound
|
|
|
|
|
2023-04-24 09:09:43 +00:00
|
|
|
r.status = statusUndefined
|
|
|
|
r.err = errNotFound
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2023-04-24 09:09:43 +00:00
|
|
|
r.log.Debug(logs.GetRemoteCallFailed,
|
2020-12-02 23:45:25 +00:00
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
case err == nil:
|
2023-04-24 09:09:43 +00:00
|
|
|
r.status = statusOK
|
|
|
|
r.err = nil
|
2022-07-15 06:55:53 +00:00
|
|
|
|
|
|
|
// 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 {
|
2023-04-24 09:09:43 +00:00
|
|
|
r.collectedObject = obj
|
|
|
|
r.writeCollectedObject(ctx)
|
2022-07-15 06:55:53 +00:00
|
|
|
}
|
2022-03-17 08:03:58 +00:00
|
|
|
case errors.As(err, &errRemoved):
|
2023-04-24 09:09:43 +00:00
|
|
|
r.status = statusINHUMED
|
|
|
|
r.err = errRemoved
|
2022-06-29 17:33:48 +00:00
|
|
|
case errors.As(err, &errOutOfRange):
|
2023-04-24 09:09:43 +00:00
|
|
|
r.status = statusOutOfRange
|
|
|
|
r.err = errOutOfRange
|
2020-12-02 23:45:25 +00:00
|
|
|
case errors.As(err, &errSplitInfo):
|
2023-04-24 09:09:43 +00:00
|
|
|
r.status = statusVIRTUAL
|
|
|
|
mergeSplitInfo(r.splitInfo(), errSplitInfo.SplitInfo())
|
|
|
|
r.err = objectSDK.NewSplitInfoError(r.infoSplit)
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
2023-04-24 09:09:43 +00:00
|
|
|
return r.status != statusUndefined
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
2023-04-21 15:21:46 +00:00
|
|
|
|
2023-04-24 09:09:43 +00:00
|
|
|
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)
|
2023-04-21 15:21:46 +00:00
|
|
|
}
|
|
|
|
|
2023-04-24 09:09:43 +00:00
|
|
|
key, err := r.key()
|
2023-04-21 15:21:46 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
prm := RemoteRequestParams{
|
2023-04-24 09:09:43 +00:00
|
|
|
Epoch: r.curProcEpoch,
|
|
|
|
TTL: r.prm.common.TTL(),
|
2023-04-21 15:21:46 +00:00
|
|
|
PrivateKey: key,
|
2023-04-24 09:09:43 +00:00
|
|
|
SessionToken: r.prm.common.SessionToken(),
|
|
|
|
BearerToken: r.prm.common.BearerToken(),
|
|
|
|
XHeaders: r.prm.common.XHeaders(),
|
|
|
|
IsRaw: r.isRaw(),
|
2023-04-21 15:21:46 +00:00
|
|
|
}
|
|
|
|
|
2023-04-24 09:09:43 +00:00
|
|
|
if r.headOnly() {
|
|
|
|
return rs.Head(ctx, r.address(), prm)
|
2023-04-21 15:21:46 +00:00
|
|
|
}
|
|
|
|
// we don't specify payload writer because we accumulate
|
|
|
|
// the object locally (even huge).
|
2023-04-24 09:09:43 +00:00
|
|
|
if rng := r.ctxRange(); rng != nil {
|
2023-04-21 15:21:46 +00:00
|
|
|
// Current spec allows other storage node to deny access,
|
|
|
|
// fallback to GET here.
|
2023-04-24 09:09:43 +00:00
|
|
|
return rs.Range(ctx, r.address(), rng, prm)
|
2023-04-21 15:21:46 +00:00
|
|
|
}
|
|
|
|
|
2023-04-24 09:09:43 +00:00
|
|
|
return rs.Get(ctx, r.address(), prm)
|
2023-04-21 15:21:46 +00:00
|
|
|
}
|