2020-12-02 23:45:25 +00:00
|
|
|
package getsvc
|
|
|
|
|
|
|
|
import (
|
2023-03-09 08:02:27 +00:00
|
|
|
"context"
|
2023-03-09 06:54:12 +00:00
|
|
|
"errors"
|
|
|
|
|
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"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2020-12-02 23:45:25 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2023-03-31 11:49:40 +00:00
|
|
|
func (exec *execCtx) assemble(ctx context.Context) {
|
2020-12-02 23:45:25 +00:00
|
|
|
if !exec.canAssemble() {
|
|
|
|
exec.log.Debug("can not assemble the object")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-11 17:57:56 +00:00
|
|
|
// Any access tokens are not expected to be used in the assembly process:
|
|
|
|
// - there is no requirement to specify child objects in session/bearer
|
|
|
|
// token for `GET`/`GETRANGE`/`RANGEHASH` requests in the API protocol,
|
|
|
|
// and, therefore, their missing in the original request should not be
|
|
|
|
// considered as error; on the other hand, without session for every child
|
|
|
|
// object, it is impossible to attach bearer token in the new generated
|
|
|
|
// requests correctly because the token has not been issued for that node's
|
|
|
|
// key;
|
|
|
|
// - the assembly process is expected to be handled on a container node
|
|
|
|
// only since the requests forwarding mechanism presentation; such the
|
|
|
|
// node should have enough rights for getting any child object by design.
|
|
|
|
exec.prm.common.ForgetTokens()
|
|
|
|
|
2021-09-27 06:52:03 +00:00
|
|
|
// Do not use forwarding during assembly stage.
|
|
|
|
// Request forwarding closure inherited in produced
|
|
|
|
// `execCtx` so it should be disabled there.
|
|
|
|
exec.disableForwarding()
|
2021-04-29 12:18:29 +00:00
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
exec.log.Debug("trying to assemble the object...")
|
|
|
|
|
2023-03-09 08:02:27 +00:00
|
|
|
assembler := newAssembler(exec.address(), exec.splitInfo(), exec.ctxRange(), exec)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2023-03-09 08:02:27 +00:00
|
|
|
exec.log.Debug("assembling splitted object...",
|
|
|
|
zap.Stringer("address", exec.address()),
|
|
|
|
zap.Uint64("range_offset", exec.ctxRange().GetOffset()),
|
|
|
|
zap.Uint64("range_length", exec.ctxRange().GetLength()),
|
|
|
|
)
|
|
|
|
defer exec.log.Debug("assembling splitted object completed",
|
|
|
|
zap.Stringer("address", exec.address()),
|
|
|
|
zap.Uint64("range_offset", exec.ctxRange().GetOffset()),
|
|
|
|
zap.Uint64("range_length", exec.ctxRange().GetLength()),
|
|
|
|
)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2023-03-31 11:49:40 +00:00
|
|
|
obj, err := assembler.Assemble(ctx, exec.prm.objWriter)
|
2023-03-09 08:02:27 +00:00
|
|
|
if err != nil {
|
|
|
|
exec.log.Warn("failed to assemble splitted object",
|
|
|
|
zap.Error(err),
|
|
|
|
zap.Stringer("address", exec.address()),
|
|
|
|
zap.Uint64("range_offset", exec.ctxRange().GetOffset()),
|
|
|
|
zap.Uint64("range_length", exec.ctxRange().GetLength()),
|
|
|
|
)
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
2023-03-09 08:02:27 +00:00
|
|
|
var errSplitInfo *objectSDK.SplitInfoError
|
|
|
|
var errRemovedRemote *apistatus.ObjectAlreadyRemoved
|
|
|
|
var errOutOfRangeRemote *apistatus.ObjectOutOfRange
|
|
|
|
var errRemovedLocal apistatus.ObjectAlreadyRemoved
|
|
|
|
var errOutOfRangeLocal apistatus.ObjectOutOfRange
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2023-03-09 08:02:27 +00:00
|
|
|
switch {
|
|
|
|
default:
|
2020-12-02 23:45:25 +00:00
|
|
|
exec.status = statusUndefined
|
2023-03-09 08:02:27 +00:00
|
|
|
exec.err = err
|
|
|
|
case err == nil:
|
|
|
|
exec.status = statusOK
|
|
|
|
exec.err = nil
|
|
|
|
exec.collectedObject = obj
|
|
|
|
case errors.As(err, &errRemovedRemote):
|
|
|
|
exec.status = statusINHUMED
|
|
|
|
exec.err = errRemovedRemote
|
|
|
|
case errors.As(err, &errRemovedLocal):
|
|
|
|
exec.status = statusINHUMED
|
|
|
|
exec.err = errRemovedLocal
|
|
|
|
case errors.As(err, &errSplitInfo):
|
|
|
|
exec.status = statusVIRTUAL
|
|
|
|
exec.err = errSplitInfo
|
|
|
|
case errors.As(err, &errOutOfRangeRemote):
|
|
|
|
exec.status = statusOutOfRange
|
|
|
|
exec.err = errOutOfRangeRemote
|
|
|
|
case errors.As(err, &errOutOfRangeLocal):
|
|
|
|
exec.status = statusOutOfRange
|
|
|
|
exec.err = errOutOfRangeLocal
|
2020-12-07 17:49:47 +00:00
|
|
|
}
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
2023-03-09 08:02:27 +00:00
|
|
|
func equalAddresses(a, b oid.Address) bool {
|
|
|
|
return a.Container().Equals(b.Container()) && a.Object().Equals(b.Object())
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
2023-03-09 08:02:27 +00:00
|
|
|
func (exec *execCtx) HeadObject(ctx context.Context, id oid.ID) (*objectSDK.Object, error) {
|
|
|
|
p := exec.prm
|
|
|
|
p.common = p.common.WithLocalOnly(false)
|
|
|
|
p.addr.SetContainer(exec.containerID())
|
|
|
|
p.addr.SetObject(id)
|
|
|
|
|
|
|
|
prm := HeadPrm{
|
|
|
|
commonPrm: p.commonPrm,
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
2023-03-09 08:02:27 +00:00
|
|
|
w := NewSimpleObjectWriter()
|
|
|
|
prm.SetHeaderWriter(w)
|
2023-03-31 11:49:40 +00:00
|
|
|
err := exec.svc.Head(ctx, prm)
|
2020-12-07 17:49:47 +00:00
|
|
|
|
2023-03-09 08:02:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
2023-03-09 08:02:27 +00:00
|
|
|
return w.Object(), nil
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
2023-03-09 08:02:27 +00:00
|
|
|
func (exec *execCtx) GetObject(ctx context.Context, id oid.ID, rng *objectSDK.Range) (*objectSDK.Object, error) {
|
|
|
|
w := NewSimpleObjectWriter()
|
2022-05-12 16:37:46 +00:00
|
|
|
|
2023-03-09 08:02:27 +00:00
|
|
|
p := exec.prm
|
|
|
|
p.common = p.common.WithLocalOnly(false)
|
|
|
|
p.objWriter = w
|
|
|
|
p.SetRange(rng)
|
2020-12-07 17:49:47 +00:00
|
|
|
|
2023-03-09 08:02:27 +00:00
|
|
|
p.addr.SetContainer(exec.containerID())
|
|
|
|
p.addr.SetObject(id)
|
2020-12-07 17:49:47 +00:00
|
|
|
|
2023-03-31 11:49:40 +00:00
|
|
|
statusError := exec.svc.get(ctx, p.commonPrm, withPayloadRange(rng))
|
2020-12-07 17:49:47 +00:00
|
|
|
|
2023-03-09 08:02:27 +00:00
|
|
|
if statusError.err != nil {
|
|
|
|
return nil, statusError.err
|
2020-12-07 17:49:47 +00:00
|
|
|
}
|
2023-03-09 08:02:27 +00:00
|
|
|
return w.Object(), nil
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|