2020-12-02 23:45:25 +00:00
|
|
|
package getsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-12-28 10:04:29 +00:00
|
|
|
"encoding/hex"
|
2021-05-18 08:12:51 +00:00
|
|
|
"errors"
|
2020-12-02 23:45:25 +00:00
|
|
|
|
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"
|
2023-05-31 09:24:04 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
2023-03-07 13:38:26 +00:00
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2024-07-15 15:03:43 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
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()
|
|
|
|
|
2024-10-21 07:22:54 +00:00
|
|
|
r.log.Debug(ctx, logs.ProcessingNode, zap.String("node_key", hex.EncodeToString(info.PublicKey())))
|
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
|
2024-04-22 06:43:42 +00:00
|
|
|
var errECInfo *objectSDK.ECInfoError
|
2022-03-17 08:03:58 +00:00
|
|
|
var errRemoved *apistatus.ObjectAlreadyRemoved
|
2022-06-29 17:33:48 +00:00
|
|
|
var errOutOfRange *apistatus.ObjectOutOfRange
|
2024-08-28 10:56:45 +00:00
|
|
|
var errAccessDenied *apistatus.ObjectAccessDenied
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
switch {
|
|
|
|
default:
|
2024-10-21 07:22:54 +00:00
|
|
|
r.log.Debug(ctx, logs.GetRemoteCallFailed, zap.Error(err))
|
2024-07-23 14:46:02 +00:00
|
|
|
if r.status != statusEC {
|
|
|
|
// for raw requests, continue to collect other parts
|
|
|
|
r.status = statusUndefined
|
2024-08-28 10:56:45 +00:00
|
|
|
if errors.As(err, &errAccessDenied) {
|
|
|
|
r.err = err
|
2024-09-16 09:38:45 +00:00
|
|
|
} else if r.err == nil || !errors.As(r.err, &errAccessDenied) {
|
2024-08-28 10:56:45 +00:00
|
|
|
r.err = new(apistatus.ObjectNotFound)
|
|
|
|
}
|
2024-07-23 14:46:02 +00:00
|
|
|
}
|
|
|
|
return false
|
2020-12-02 23:45:25 +00:00
|
|
|
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
|
|
|
}
|
2024-07-23 14:46:02 +00:00
|
|
|
return true
|
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
|
2024-07-23 14:46:02 +00:00
|
|
|
return true
|
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
|
2024-07-23 14:46:02 +00:00
|
|
|
return true
|
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)
|
2024-07-23 14:46:02 +00:00
|
|
|
return true
|
2024-04-22 06:43:42 +00:00
|
|
|
case errors.As(err, &errECInfo):
|
|
|
|
r.status = statusEC
|
2024-07-15 15:03:43 +00:00
|
|
|
r.err = r.infoEC.addRemote(string(info.PublicKey()), errECInfo.ECInfo())
|
2024-07-23 14:46:02 +00:00
|
|
|
if r.isRaw() {
|
|
|
|
return false // continue to collect all parts
|
|
|
|
}
|
|
|
|
return true
|
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
|
|
|
}
|
2024-07-15 15:03:43 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|