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-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
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-04-24 09:09:43 +00:00
|
|
|
func (r *request) assemble(ctx context.Context) {
|
|
|
|
if !r.canAssemble() {
|
|
|
|
r.log.Debug(logs.GetCanNotAssembleTheObject)
|
2020-12-02 23:45:25 +00:00
|
|
|
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.
|
2023-04-24 09:09:43 +00:00
|
|
|
r.prm.common.ForgetTokens()
|
2022-11-11 17:57:56 +00:00
|
|
|
|
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.
|
2023-04-24 09:09:43 +00:00
|
|
|
r.disableForwarding()
|
2021-04-29 12:18:29 +00:00
|
|
|
|
2023-04-24 09:09:43 +00:00
|
|
|
r.log.Debug(logs.GetTryingToAssembleTheObject)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2023-04-24 09:09:43 +00:00
|
|
|
assembler := newAssembler(r.address(), r.splitInfo(), r.ctxRange(), r)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2023-04-24 09:09:43 +00:00
|
|
|
r.log.Debug(logs.GetAssemblingSplittedObject,
|
|
|
|
zap.Stringer("address", r.address()),
|
|
|
|
zap.Uint64("range_offset", r.ctxRange().GetOffset()),
|
|
|
|
zap.Uint64("range_length", r.ctxRange().GetLength()),
|
2023-03-09 08:02:27 +00:00
|
|
|
)
|
2023-04-24 09:09:43 +00:00
|
|
|
defer r.log.Debug(logs.GetAssemblingSplittedObjectCompleted,
|
|
|
|
zap.Stringer("address", r.address()),
|
|
|
|
zap.Uint64("range_offset", r.ctxRange().GetOffset()),
|
|
|
|
zap.Uint64("range_length", r.ctxRange().GetLength()),
|
2023-03-09 08:02:27 +00:00
|
|
|
)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2023-04-24 09:09:43 +00:00
|
|
|
obj, err := assembler.Assemble(ctx, r.prm.objWriter)
|
2023-03-09 08:02:27 +00:00
|
|
|
if err != nil {
|
2023-04-24 09:09:43 +00:00
|
|
|
r.log.Warn(logs.GetFailedToAssembleSplittedObject,
|
2023-03-09 08:02:27 +00:00
|
|
|
zap.Error(err),
|
2023-04-24 09:09:43 +00:00
|
|
|
zap.Stringer("address", r.address()),
|
|
|
|
zap.Uint64("range_offset", r.ctxRange().GetOffset()),
|
|
|
|
zap.Uint64("range_length", r.ctxRange().GetLength()),
|
2023-03-09 08:02:27 +00:00
|
|
|
)
|
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:
|
2023-04-24 09:09:43 +00:00
|
|
|
r.status = statusUndefined
|
|
|
|
r.err = err
|
2023-03-09 08:02:27 +00:00
|
|
|
case err == nil:
|
2023-04-24 09:09:43 +00:00
|
|
|
r.status = statusOK
|
|
|
|
r.err = nil
|
|
|
|
r.collectedObject = obj
|
2023-03-09 08:02:27 +00:00
|
|
|
case errors.As(err, &errRemovedRemote):
|
2023-04-24 09:09:43 +00:00
|
|
|
r.status = statusINHUMED
|
|
|
|
r.err = errRemovedRemote
|
2023-03-09 08:02:27 +00:00
|
|
|
case errors.As(err, &errRemovedLocal):
|
2023-04-24 09:09:43 +00:00
|
|
|
r.status = statusINHUMED
|
|
|
|
r.err = errRemovedLocal
|
2023-03-09 08:02:27 +00:00
|
|
|
case errors.As(err, &errSplitInfo):
|
2023-04-24 09:09:43 +00:00
|
|
|
r.status = statusVIRTUAL
|
|
|
|
r.err = errSplitInfo
|
2023-03-09 08:02:27 +00:00
|
|
|
case errors.As(err, &errOutOfRangeRemote):
|
2023-04-24 09:09:43 +00:00
|
|
|
r.status = statusOutOfRange
|
|
|
|
r.err = errOutOfRangeRemote
|
2023-03-09 08:02:27 +00:00
|
|
|
case errors.As(err, &errOutOfRangeLocal):
|
2023-04-24 09:09:43 +00:00
|
|
|
r.status = statusOutOfRange
|
|
|
|
r.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-04-24 09:09:43 +00:00
|
|
|
func (r *request) HeadObject(ctx context.Context, id oid.ID) (*objectSDK.Object, error) {
|
2023-04-24 08:36:15 +00:00
|
|
|
w := NewSimpleObjectWriter()
|
|
|
|
|
|
|
|
p := RequestParameters{}
|
2023-03-09 08:02:27 +00:00
|
|
|
p.common = p.common.WithLocalOnly(false)
|
2023-04-24 09:09:43 +00:00
|
|
|
p.addr.SetContainer(r.containerID())
|
2023-03-09 08:02:27 +00:00
|
|
|
p.addr.SetObject(id)
|
2023-04-24 08:36:15 +00:00
|
|
|
p.head = true
|
|
|
|
p.SetHeaderWriter(w)
|
2023-03-09 08:02:27 +00:00
|
|
|
|
2023-04-24 09:09:43 +00:00
|
|
|
if err := r.getObjectWithIndependentRequest(ctx, p); err != nil {
|
2023-03-09 08:02:27 +00:00
|
|
|
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-04-24 09:09:43 +00:00
|
|
|
func (r *request) GetObject(ctx context.Context, id oid.ID, rng *objectSDK.Range) (*objectSDK.Object, error) {
|
2023-03-09 08:02:27 +00:00
|
|
|
w := NewSimpleObjectWriter()
|
2022-05-12 16:37:46 +00:00
|
|
|
|
2023-04-24 09:09:43 +00:00
|
|
|
p := r.prm
|
2023-03-09 08:02:27 +00:00
|
|
|
p.common = p.common.WithLocalOnly(false)
|
|
|
|
p.objWriter = w
|
2023-04-24 07:33:12 +00:00
|
|
|
p.rng = rng
|
2020-12-07 17:49:47 +00:00
|
|
|
|
2023-04-24 09:09:43 +00:00
|
|
|
p.addr.SetContainer(r.containerID())
|
2023-03-09 08:02:27 +00:00
|
|
|
p.addr.SetObject(id)
|
2020-12-07 17:49:47 +00:00
|
|
|
|
2023-04-24 09:09:43 +00:00
|
|
|
if err := r.getObjectWithIndependentRequest(ctx, p); err != nil {
|
2023-04-20 07:58:43 +00:00
|
|
|
return nil, 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
|
|
|
}
|
2023-04-24 08:36:15 +00:00
|
|
|
|
2023-04-24 09:09:43 +00:00
|
|
|
func (r *request) getObjectWithIndependentRequest(ctx context.Context, prm RequestParameters) error {
|
|
|
|
detachedExecutor := &request{
|
|
|
|
keyStore: r.keyStore,
|
|
|
|
traverserGenerator: r.traverserGenerator,
|
|
|
|
remoteStorageConstructor: r.remoteStorageConstructor,
|
|
|
|
epochSource: r.epochSource,
|
|
|
|
localStorage: r.localStorage,
|
2023-04-24 08:36:15 +00:00
|
|
|
|
|
|
|
prm: prm,
|
|
|
|
infoSplit: objectSDK.NewSplitInfo(),
|
2023-04-24 09:09:43 +00:00
|
|
|
log: r.log,
|
2023-04-24 08:36:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
detachedExecutor.execute(ctx)
|
|
|
|
|
|
|
|
return detachedExecutor.statusError.err
|
|
|
|
}
|