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"
|
2024-04-22 06:43:42 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/policy"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util"
|
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"
|
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-12-28 10:04:29 +00:00
|
|
|
r.log.Debug(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
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
switch {
|
|
|
|
default:
|
2024-04-22 06:43:42 +00:00
|
|
|
r.log.Debug(logs.GetRemoteCallFailed, zap.Error(err))
|
|
|
|
if r.status == statusEC {
|
|
|
|
// we need to continue getting another chunks from another nodes
|
|
|
|
// in case of network issue
|
|
|
|
return false
|
|
|
|
}
|
2023-04-24 09:09:43 +00:00
|
|
|
r.status = statusUndefined
|
2023-08-04 11:14:07 +00:00
|
|
|
r.err = new(apistatus.ObjectNotFound)
|
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
|
|
|
}
|
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)
|
2024-04-22 06:43:42 +00:00
|
|
|
case errors.As(err, &errECInfo):
|
|
|
|
r.status = statusEC
|
|
|
|
util.MergeECInfo(r.infoEC, errECInfo.ECInfo())
|
|
|
|
r.infoEC = errECInfo.ECInfo()
|
|
|
|
r.err = objectSDK.NewECInfoError(r.infoEC)
|
|
|
|
if r.isRaw() {
|
|
|
|
return len(r.infoEC.Chunks) == int(r.infoEC.Chunks[0].Total)
|
|
|
|
}
|
|
|
|
cnt, err := r.containerSource.Get(r.address().Container())
|
|
|
|
if err == nil {
|
|
|
|
return len(r.infoEC.Chunks) == policy.ECDataCount(cnt.Value.PlacementPolicy())
|
|
|
|
}
|
|
|
|
r.log.Debug(logs.GetUnableToGetECObjectContainer, zap.Error(err))
|
|
|
|
return len(r.infoEC.Chunks) == int(r.infoEC.Chunks[0].Total)
|
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
|
|
|
}
|