frostfs-node/pkg/services/object/get/local.go
Dmitrii Stepanov 22d47376a6
All checks were successful
ci/woodpecker/push/pre-commit Pipeline was successful
[#277] getsvc: Refactor errors
Move errors to separate files.
Use zap.Error for error logging.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-04-28 14:03:12 +00:00

59 lines
1.5 KiB
Go

package getsvc
import (
"context"
"errors"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/pkg/tracing"
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
"go.uber.org/zap"
)
func (r *request) executeLocal(ctx context.Context) {
ctx, span := tracing.StartSpanFromContext(ctx, "getService.executeLocal")
defer func() {
span.End()
}()
var err error
r.collectedObject, err = r.get(ctx)
var errSplitInfo *objectSDK.SplitInfoError
var errRemoved apistatus.ObjectAlreadyRemoved
var errOutOfRange apistatus.ObjectOutOfRange
switch {
default:
r.status = statusUndefined
r.err = err
r.log.Debug(logs.GetLocalGetFailed, zap.Error(err))
case err == nil:
r.status = statusOK
r.err = nil
r.writeCollectedObject(ctx)
case errors.As(err, &errRemoved):
r.status = statusINHUMED
r.err = errRemoved
case errors.As(err, &errSplitInfo):
r.status = statusVIRTUAL
mergeSplitInfo(r.splitInfo(), errSplitInfo.SplitInfo())
r.err = objectSDK.NewSplitInfoError(r.infoSplit)
case errors.As(err, &errOutOfRange):
r.status = statusOutOfRange
r.err = errOutOfRange
}
}
func (r *request) get(ctx context.Context) (*objectSDK.Object, error) {
if r.headOnly() {
return r.localStorage.Head(ctx, r.address(), r.isRaw())
}
if rng := r.ctxRange(); rng != nil {
return r.localStorage.Range(ctx, r.address(), rng)
}
return r.localStorage.Get(ctx, r.address())
}