mirror of
https://github.com/cubefs/cubefs.git
synced 2026-08-02 02:00:56 +00:00
fix(shardnode): convert kvstore key not found err to err with code
with #22357426 Signed-off-by: xiejian <xiejian3@oppo.com>
This commit is contained in:
parent
ba801c5c77
commit
eb0499a6c9
@ -165,6 +165,7 @@ var errCodeMap = map[int]string{
|
||||
CodeShardConflicts: "shardnode:shard conflicts",
|
||||
CodeKeySizeTooLarge: "shardnode:key size large than 32KB",
|
||||
CodeValueSizeTooLarge: "shardnode:value size large than 16MB",
|
||||
CodeKeyNotFound: "shardnode:key not found",
|
||||
}
|
||||
|
||||
// HTTPError make rpc.HTTPError
|
||||
|
||||
@ -28,6 +28,7 @@ const (
|
||||
CodeShardConflicts = 1011
|
||||
CodeKeySizeTooLarge = 1012
|
||||
CodeValueSizeTooLarge = 1013
|
||||
CodeKeyNotFound = 1014
|
||||
)
|
||||
|
||||
// 10xx
|
||||
@ -45,4 +46,5 @@ var (
|
||||
ErrShardConflicts = Error(CodeShardConflicts)
|
||||
ErrKeySizeTooLarge = Error(CodeKeySizeTooLarge)
|
||||
ErrValueSizeTooLarge = Error(CodeValueSizeTooLarge)
|
||||
ErrKeyNotFound = Error(CodeKeyNotFound)
|
||||
)
|
||||
|
||||
@ -24,7 +24,6 @@ import (
|
||||
"github.com/cubefs/cubefs/blobstore/api/clustermgr"
|
||||
"github.com/cubefs/cubefs/blobstore/api/shardnode"
|
||||
apierr "github.com/cubefs/cubefs/blobstore/common/errors"
|
||||
kvstore "github.com/cubefs/cubefs/blobstore/common/kvstorev2"
|
||||
"github.com/cubefs/cubefs/blobstore/common/proto"
|
||||
"github.com/cubefs/cubefs/blobstore/common/rpc2"
|
||||
"github.com/cubefs/cubefs/blobstore/common/security"
|
||||
@ -187,7 +186,7 @@ func (s *Space) CreateBlob(ctx context.Context, req *shardnode.CreateBlobArgs) (
|
||||
Header: req.Header,
|
||||
Name: req.Name,
|
||||
})
|
||||
if getErr != nil && !errors.Is(getErr, kvstore.ErrNotFound) {
|
||||
if getErr != nil && !errors.Is(getErr, apierr.ErrKeyNotFound) {
|
||||
err = getErr
|
||||
return
|
||||
}
|
||||
@ -269,12 +268,11 @@ func (s *Space) GetBlob(ctx context.Context, req *shardnode.GetBlobArgs) (resp s
|
||||
}, key)
|
||||
|
||||
withErr := err
|
||||
if errors.Is(err, kvstore.ErrNotFound) {
|
||||
if errors.Is(err, apierr.ErrKeyNotFound) {
|
||||
withErr = nil
|
||||
}
|
||||
span.AppendTrackLog(opGet, start, withErr, trace.OptSpanDurationUs())
|
||||
if err != nil {
|
||||
err = errors.Info(err, fmt.Sprintf("get failed, blob name: %v", req.Name))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@ -27,7 +27,6 @@ import (
|
||||
"github.com/cubefs/cubefs/blobstore/api/shardnode"
|
||||
"github.com/cubefs/cubefs/blobstore/common/codemode"
|
||||
apierr "github.com/cubefs/cubefs/blobstore/common/errors"
|
||||
kvstore "github.com/cubefs/cubefs/blobstore/common/kvstorev2"
|
||||
"github.com/cubefs/cubefs/blobstore/common/proto"
|
||||
"github.com/cubefs/cubefs/blobstore/common/rpc2"
|
||||
"github.com/cubefs/cubefs/blobstore/common/security"
|
||||
@ -169,7 +168,7 @@ func TestSpace_CreateBlob(t *testing.T) {
|
||||
|
||||
gomock.InOrder(alc.EXPECT().AllocSlices(A, A, A, A, A).Return(slices, nil))
|
||||
|
||||
mockSpace.mockHandler.EXPECT().Get(A, A, A).Return(nil, kvstore.ErrNotFound)
|
||||
mockSpace.mockHandler.EXPECT().Get(A, A, A).Return(nil, apierr.ErrKeyNotFound)
|
||||
mockSpace.mockHandler.EXPECT().Insert(A, A, A).Return(nil)
|
||||
|
||||
ret, err := mockSpace.space.CreateBlob(ctx, args)
|
||||
@ -189,7 +188,7 @@ func TestSpace_CreateBlob(t *testing.T) {
|
||||
// create with alloc size 0
|
||||
args.Size_ = 0
|
||||
|
||||
mockSpace.mockHandler.EXPECT().Get(A, A, A).Return(nil, kvstore.ErrNotFound)
|
||||
mockSpace.mockHandler.EXPECT().Get(A, A, A).Return(nil, apierr.ErrKeyNotFound)
|
||||
mockSpace.mockHandler.EXPECT().Insert(A, A, A).Return(nil)
|
||||
ret, err = mockSpace.space.CreateBlob(ctx, args)
|
||||
require.Nil(t, err)
|
||||
|
||||
@ -351,6 +351,9 @@ func (s *shard) Get(ctx context.Context, h OpHeader, key []byte) (ValGetter, err
|
||||
kvStore := s.store.KVStore()
|
||||
ret, err := kvStore.Get(ctx, dataCF, s.shardKeys.encodeItemKey(key), nil)
|
||||
if err != nil {
|
||||
if errors.Is(err, kvstore.ErrNotFound) {
|
||||
return nil, apierr.ErrKeyNotFound
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return ret, nil
|
||||
|
||||
@ -21,6 +21,7 @@ import (
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/cubefs/cubefs/blobstore/common/errors"
|
||||
kvstore "github.com/cubefs/cubefs/blobstore/common/kvstorev2"
|
||||
cproto "github.com/cubefs/cubefs/blobstore/common/proto"
|
||||
"github.com/cubefs/cubefs/blobstore/common/raft"
|
||||
@ -75,13 +76,13 @@ func TestServerShardSM_Item(t *testing.T) {
|
||||
_, err = mockShard.shard.GetItem(ctx, OpHeader{
|
||||
ShardKeys: [][]byte{newProtoItem.ID},
|
||||
}, newProtoItem.ID)
|
||||
require.ErrorIs(t, err, kvstore.ErrNotFound)
|
||||
require.ErrorIs(t, err, errors.ErrKeyNotFound)
|
||||
err = mockShard.shardSM.applyDeleteRaw(ctx, newProtoItem.ID)
|
||||
require.Nil(t, err)
|
||||
_, err = mockShard.shard.GetItem(ctx, OpHeader{
|
||||
ShardKeys: [][]byte{newProtoItem.ID},
|
||||
}, newProtoItem.ID)
|
||||
require.ErrorIs(t, err, kvstore.ErrNotFound)
|
||||
require.ErrorIs(t, err, errors.ErrKeyNotFound)
|
||||
|
||||
// List
|
||||
n := 4
|
||||
@ -155,7 +156,7 @@ func TestServerShardSM_Raw(t *testing.T) {
|
||||
err = mockShard.shardSM.applyDeleteRaw(ctx, key)
|
||||
require.Nil(t, err)
|
||||
_, err = mockShard.shard.Get(ctx, OpHeader{ShardKeys: [][]byte{key}}, key)
|
||||
require.ErrorIs(t, err, kvstore.ErrNotFound)
|
||||
require.ErrorIs(t, err, errors.ErrKeyNotFound)
|
||||
|
||||
// List
|
||||
n := 4
|
||||
|
||||
Loading…
Reference in New Issue
Block a user