[#85] get-service: Fix corrupted chain logic

Should return an error in case of a broken LOB reference chain.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-03-09 09:54:12 +03:00
parent 2886b1581b
commit 07de839f18
3 changed files with 19 additions and 15 deletions

View file

@ -1,6 +1,8 @@
package getsvc package getsvc
import ( import (
"errors"
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
@ -90,6 +92,7 @@ func (exec *execCtx) initFromChild(obj oid.ID) (prev *oid.ID, children []oid.ID)
par := child.Parent() par := child.Parent()
if par == nil { if par == nil {
exec.status = statusUndefined exec.status = statusUndefined
exec.err = errors.New("received child with empty parent")
log.Debug("received child with empty parent") log.Debug("received child with empty parent")

View file

@ -220,6 +220,8 @@ func (exec *execCtx) getChild(id oid.ID, rng *objectSDK.Range, withHdr bool) (*o
exec.err = errors.New("wrong child header") exec.err = errors.New("wrong child header")
exec.log.Debug("parent address in child object differs") exec.log.Debug("parent address in child object differs")
return nil, false
} }
return child, ok return child, ok
@ -256,8 +258,10 @@ func (exec *execCtx) headChild(id oid.ID) (*objectSDK.Object, bool) {
if !exec.isChild(child) { if !exec.isChild(child) {
exec.status = statusUndefined exec.status = statusUndefined
exec.err = errors.New("parent address in child object differs")
exec.log.Debug("parent address in child object differs") exec.log.Debug("parent address in child object differs")
return nil, false
} else { } else {
exec.status = statusOK exec.status = statusOK
exec.err = nil exec.err = nil

View file

@ -1094,8 +1094,8 @@ func TestGetRemoteSmall(t *testing.T) {
p.WithAddress(addr) p.WithAddress(addr)
err := svc.Get(ctx, p) err := svc.Get(ctx, p)
require.NoError(t, err) //TODO fix me require.Error(t, err)
//require.Equal(t, err.Error(), "wrong child header") require.Equal(t, err.Error(), "wrong child header")
w = NewSimpleObjectWriter() w = NewSimpleObjectWriter()
payloadSz := srcObj.PayloadSize() payloadSz := srcObj.PayloadSize()
@ -1107,9 +1107,8 @@ func TestGetRemoteSmall(t *testing.T) {
rngPrm.WithAddress(addr) rngPrm.WithAddress(addr)
err = svc.GetRange(ctx, rngPrm) err = svc.GetRange(ctx, rngPrm)
require.ErrorAs(t, err, new(*apistatus.ObjectOutOfRange)) //TODO fix me require.Error(t, err)
//require.Equal(t, err.Error(), "wrong child header") require.Equal(t, err.Error(), "wrong child header")
}) })
t.Run("linked object with parent udefined", func(t *testing.T) { t.Run("linked object with parent udefined", func(t *testing.T) {
@ -1180,8 +1179,8 @@ func TestGetRemoteSmall(t *testing.T) {
p.WithAddress(addr) p.WithAddress(addr)
err := svc.Get(ctx, p) err := svc.Get(ctx, p)
require.NoError(t, err) //TODO fix me require.Error(t, err)
//require.Equal(t, err.Error(), "received child with empty parent") require.Equal(t, err.Error(), "received child with empty parent")
w = NewSimpleObjectWriter() w = NewSimpleObjectWriter()
payloadSz := srcObj.PayloadSize() payloadSz := srcObj.PayloadSize()
@ -1193,8 +1192,8 @@ func TestGetRemoteSmall(t *testing.T) {
rngPrm.WithAddress(addr) rngPrm.WithAddress(addr)
err = svc.GetRange(ctx, rngPrm) err = svc.GetRange(ctx, rngPrm)
require.NoError(t, err) //TODO fix me require.Error(t, err)
//require.Equal(t, err.Error(), "received child with empty parent") require.Equal(t, err.Error(), "received child with empty parent")
}) })
t.Run("out of range", func(t *testing.T) { t.Run("out of range", func(t *testing.T) {
@ -1465,9 +1464,8 @@ func TestGetRemoteSmall(t *testing.T) {
p.WithAddress(addr) p.WithAddress(addr)
err := svc.Get(ctx, p) err := svc.Get(ctx, p)
require.NoError(t, err) //TODO fix me, it must be an error, corrupted chain require.Error(t, err)
//require.Equal(t, err.Error(), "parent address in child object differs") require.Equal(t, err.Error(), "parent address in child object differs")
require.Equal(t, srcObj, w.Object())
w = NewSimpleObjectWriter() w = NewSimpleObjectWriter()
payloadSz := srcObj.PayloadSize() payloadSz := srcObj.PayloadSize()
@ -1479,9 +1477,8 @@ func TestGetRemoteSmall(t *testing.T) {
rngPrm.WithAddress(addr) rngPrm.WithAddress(addr)
err = svc.GetRange(ctx, rngPrm) err = svc.GetRange(ctx, rngPrm)
require.NoError(t, err) //TODO fix me, it must be an error, corrupted chain require.Error(t, err)
//require.Equal(t, err.Error(), "parent address in child object differs") require.Equal(t, err.Error(), "parent address in child object differs")
require.Equal(t, payload[off:off+ln], w.Object().Payload())
}) })
t.Run("OK", func(t *testing.T) { t.Run("OK", func(t *testing.T) {