refactor(shardnode): fix code review problems

with: #22409856 of #22357426

Signed-off-by: xiejian <xiejian3@oppo.com>
This commit is contained in:
xiejian 2024-07-25 11:24:03 +08:00 committed by slasher
parent eb1a280bc0
commit d6415c38f8
14 changed files with 237 additions and 107 deletions

View File

@ -679,7 +679,8 @@ func (m *ListItemRequest) GetCount() uint64 {
}
type ListItemResponse struct {
Items []*Item `protobuf:"bytes,1,rep,name=items,proto3" json:"items,omitempty"`
Items []Item `protobuf:"bytes,1,rep,name=items,proto3" json:"items"`
NextMarker []byte `protobuf:"bytes,2,opt,name=nextMarker,proto3" json:"nextMarker,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@ -718,13 +719,20 @@ func (m *ListItemResponse) XXX_DiscardUnknown() {
var xxx_messageInfo_ListItemResponse proto.InternalMessageInfo
func (m *ListItemResponse) GetItems() []*Item {
func (m *ListItemResponse) GetItems() []Item {
if m != nil {
return m.Items
}
return nil
}
func (m *ListItemResponse) GetNextMarker() []byte {
if m != nil {
return m.NextMarker
}
return nil
}
type AddShardRequest struct {
DiskID github_com_cubefs_cubefs_blobstore_common_proto.DiskID `protobuf:"varint,1,opt,name=disk_id,json=diskId,proto3,casttype=github.com/cubefs/cubefs/blobstore/common/proto.DiskID" json:"disk_id,omitempty"`
Suid github_com_cubefs_cubefs_blobstore_common_proto.Suid `protobuf:"varint,2,opt,name=suid,proto3,casttype=github.com/cubefs/cubefs/blobstore/common/proto.Suid" json:"suid,omitempty"`
@ -1080,60 +1088,60 @@ func init() {
func init() { proto.RegisterFile("shardnode.proto", fileDescriptor_9d3815ca0e5f30f0) }
var fileDescriptor_9d3815ca0e5f30f0 = []byte{
// 845 bytes of a gzipped FileDescriptorProto
// 833 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x55, 0xcd, 0x6e, 0xe4, 0x44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a, 0x21, 0x96, 0x7c, 0x01, 0xdd, 0x2a, 0x67, 0x52, 0x78, 0x0e,
0xea, 0x1d, 0xfe, 0xb9, 0xde, 0xe7, 0x8f, 0xb3, 0xbe, 0x16, 0x8f, 0x73, 0x26, 0x47, 0xf9, 0x21,
0x6f, 0x6b, 0x61, 0x09, 0xb5, 0x65, 0x5a, 0xf0, 0xf4, 0xc8, 0xd8, 0xaf, 0x3e, 0x04, 0x04, 0xd6,
0xcf, 0xe5, 0x36, 0x9f, 0xda, 0x8f, 0x9d, 0xd6, 0x11, 0x6e, 0xfe, 0x1a, 0xbe, 0xb7, 0xa0, 0xaf,
0x45, 0xc1, 0x81, 0x1e, 0x9d, 0x16, 0xd4, 0x3c, 0x81, 0xfb, 0x4d, 0xed, 0x5f, 0xfe, 0xeb, 0xac,
0xf6, 0x3f, 0x5b, 0xba, 0xd9, 0xc5, 0x12, 0xf1, 0xe5, 0x9a, 0xe4, 0x3e, 0x38, 0x6a, 0x03, 0xf8,
0x75, 0x5d, 0x75, 0x87, 0x58, 0x21, 0x78, 0x15, 0x5e, 0xb9, 0xb0, 0x17, 0xb3, 0xaf, 0x5f, 0x2c,
0x34, 0xa9, 0x1b, 0xbf, 0xac, 0x60, 0x1f, 0xd6, 0xcf, 0xe7, 0x30, 0x96, 0x33, 0x84, 0x2e, 0x7e,
0x21, 0xc6, 0x18, 0xdf, 0xfe, 0x67, 0xf2, 0xb5, 0x57, 0x1f, 0xa1, 0xc3, 0xcd, 0xa7, 0xcd, 0xc0,
0xfa, 0xb5, 0x19, 0x58, 0xbf, 0x35, 0x03, 0xeb, 0x9b, 0x5e, 0x18, 0x7d, 0x32, 0xb7, 0xa8, 0xb1,
0x8b, 0x2c, 0x3e, 0xf8, 0x23, 0x00, 0x00, 0xff, 0xff, 0x6b, 0x90, 0x9a, 0xe2, 0x6d, 0x0b, 0x00,
0x00,
}
func (m *Item) Marshal() (dAtA []byte, err error) {
@ -1664,6 +1672,13 @@ func (m *ListItemResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i -= len(m.XXX_unrecognized)
copy(dAtA[i:], m.XXX_unrecognized)
}
if len(m.NextMarker) > 0 {
i -= len(m.NextMarker)
copy(dAtA[i:], m.NextMarker)
i = encodeVarintShardnode(dAtA, i, uint64(len(m.NextMarker)))
i--
dAtA[i] = 0x12
}
if len(m.Items) > 0 {
for iNdEx := len(m.Items) - 1; iNdEx >= 0; iNdEx-- {
{
@ -2167,6 +2182,10 @@ func (m *ListItemResponse) Size() (n int) {
n += 1 + l + sovShardnode(uint64(l))
}
}
l = len(m.NextMarker)
if l > 0 {
n += 1 + l + sovShardnode(uint64(l))
}
if m.XXX_unrecognized != nil {
n += len(m.XXX_unrecognized)
}
@ -3624,11 +3643,45 @@ func (m *ListItemResponse) Unmarshal(dAtA []byte) error {
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Items = append(m.Items, &Item{})
m.Items = append(m.Items, Item{})
if err := m.Items[len(m.Items)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field NextMarker", wireType)
}
var byteLen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowShardnode
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
byteLen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if byteLen < 0 {
return ErrInvalidLengthShardnode
}
postIndex := iNdEx + byteLen
if postIndex < 0 {
return ErrInvalidLengthShardnode
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.NextMarker = append(m.NextMarker[:0], dAtA[iNdEx:postIndex]...)
if m.NextMarker == nil {
m.NextMarker = []byte{}
}
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipShardnode(dAtA[iNdEx:])

View File

@ -62,13 +62,14 @@ message GetItemResponse {
message ListItemRequest {
ShardOpHeader header = 1 [(gogoproto.nullable) = false];
bytes prefix = 2 [(gogoproto.customname) = "Prefix"];
bytes marker = 3 [(gogoproto.customname) = "Marker"];
uint64 count = 4 [(gogoproto.customname) = "Count"];
bytes prefix = 2;
bytes marker = 3;
uint64 count = 4;
}
message ListItemResponse {
repeated Item items = 1 [(gogoproto.customname) = "Items"];
repeated Item items = 1 [(gogoproto.nullable) = false];
bytes nextMarker = 2;
}
message AddShardRequest {

View File

@ -6,7 +6,7 @@ import (
"go.etcd.io/etcd/raft/v3/raftpb"
)
const ReqIdKey = "req-id"
const reqIDKey = "req-id"
type (
StateMachine interface {

View File

@ -642,7 +642,7 @@ func generateServerOpts(cfg *TransportConfig) []grpc.ServerOption {
) error {
span := trace.SpanFromContextSafe(ctx)
ctx = metadata.NewOutgoingContext(ctx, metadata.Pairs(
ReqIdKey, span.TraceID(),
reqIDKey, span.TraceID(),
))
return invoker(ctx, method, req, reply, cc, opts...)
@ -652,7 +652,7 @@ func generateServerOpts(cfg *TransportConfig) []grpc.ServerOption {
func unaryInterceptorWithTracer(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error) {
span := trace.SpanFromContextSafe(ctx)
ctx = metadata.NewOutgoingContext(ctx, metadata.Pairs(
ReqIdKey, span.TraceID(),
reqIDKey, span.TraceID(),
))
return streamer(ctx, desc, cc, method, opts...)
@ -664,7 +664,7 @@ func serverUnaryInterceptorWithTracer_(ctx context.Context, req interface{}, inf
if !ok {
return nil, status.Error(codes.Internal, "failed to get metadata")
}
reqId, ok := md[ReqIdKey]
reqId, ok := md[reqIDKey]
if ok {
_, ctx = trace.StartSpanFromContextWithTraceID(ctx, "", reqId[0])
} else {
@ -681,7 +681,7 @@ func serverUnaryInterceptorWithTracer(srv interface{}, ss grpc.ServerStream, inf
if !ok {
return status.Error(codes.Internal, "failed to get metadata")
}
reqId, ok := md[ReqIdKey]
reqId, ok := md[reqIDKey]
if ok {
_, ctx = trace.StartSpanFromContextWithTraceID(ctx, "", reqId[0])
} else {

View File

@ -38,9 +38,6 @@ type Catalog struct {
func NewCatalog(ctx context.Context, cfg *Config) *Catalog {
span := trace.SpanFromContext(ctx)
defer func() {
recover()
}()
catalog := &Catalog{
cfg: cfg,

View File

@ -31,7 +31,7 @@ func TestServerCatalog_New(t *testing.T) {
cfg.Transport = tp
tp.EXPECT().GetAllSpaces(A).Return(nil, errors.New("")).Times(1)
require.NotPanics(t, func() { NewCatalog(ctx, cfg) })
require.Panics(t, func() { NewCatalog(ctx, cfg) })
tp.EXPECT().GetAllSpaces(A).Return(
[]clustermgr.Space{

View File

@ -111,16 +111,20 @@ func (s *Space) GetItem(ctx context.Context, h shardnode.ShardOpHeader, id []byt
}, s.generateItemKey(id))
}
func (s *Space) ListItem(ctx context.Context, h shardnode.ShardOpHeader, prefix, id []byte, count uint64) ([]*shardnode.Item, error) {
func (s *Space) ListItem(ctx context.Context, h shardnode.ShardOpHeader, prefix, marker []byte, count uint64) ([]shardnode.Item, []byte, error) {
shard, err := s.shardGetter.GetShard(h.DiskID, h.Suid)
if err != nil {
return nil, err
return nil, nil, err
}
return shard.ListItem(ctx, storage.OpHeader{
items, nextMarker, err := shard.ListItem(ctx, storage.OpHeader{
RouteVersion: h.RouteVersion,
ShardKeys: h.ShardKeys,
}, prefix, id, count)
}, s.generateItemKey(prefix), s.generateItemKey(marker), count)
if err != nil {
return nil, nil, err
}
return items, s.decodeItemKey(nextMarker), nil
}
func (s *Space) validateFields(fields []shardnode.Field) bool {
@ -159,6 +163,13 @@ func (s *Space) generateItemKey(id []byte) []byte {
return dest
}
func (s *Space) decodeItemKey(key []byte) []byte {
if len(key) == 0 {
return nil
}
return key[8 : len(key)-8]
}
func (s *Space) generateItemKeyLen(id []byte) int {
return 8 + len(id) + 8
}

View File

@ -1,6 +1,7 @@
package catalog
import (
"bytes"
"testing"
"github.com/golang/mock/gomock"
@ -104,3 +105,14 @@ func TestSpace_Item(t *testing.T) {
err = mockSpace.shardErrSpace.DeleteItem(ctx, oph, []byte{1})
require.Equal(t, apierr.ErrShardDoesNotExist, err)
}
func TestKey(t *testing.T) {
key := []byte("aaa")
space := Space{sid: 1000, spaceVersion: 1}
spaceKey := space.generateItemKey(key)
t.Log(spaceKey)
_key := space.decodeItemKey(spaceKey)
bytes.Equal(key, _key)
}

View File

@ -49,10 +49,11 @@ func (s *service) ListItem(ctx context.Context, req *shardnode.ListItemRequest)
if err != nil {
return
}
items, err := space.ListItem(ctx, req.GetHeader(), req.GetPrefix(), req.GetMarker(), req.GetCount())
items, nextMarker, err := space.ListItem(ctx, req.GetHeader(), req.GetPrefix(), req.GetMarker(), req.GetCount())
if err != nil {
return
}
resp.Items = items
resp.NextMarker = nextMarker
return
}

View File

@ -108,25 +108,29 @@ func TestServerDisk_Shard(t *testing.T) {
})
shardID := proto.ShardID(1)
_, err := d.d.GetShard(shardID)
suid := proto.EncodeSuid(shardID, 0, 0)
_, err := d.d.GetShard(suid)
require.Error(t, err)
require.NoError(t, d.d.AddShard(ctx, shardID, 1, *rg, []clustermgr.ShardUnitInfo{{DiskID: 1}}))
require.NoError(t, d.d.AddShard(ctx, shardID, 1, *rg, []clustermgr.ShardUnitInfo{{DiskID: 1}}))
require.NoError(t, d.d.AddShard(ctx, suid, 1, *rg, []clustermgr.ShardUnitInfo{{DiskID: 1}}))
require.NoError(t, d.d.AddShard(ctx, suid, 1, *rg, []clustermgr.ShardUnitInfo{{DiskID: 1}}))
s, err := d.d.GetShard(shardID)
s, err := d.d.GetShard(suid)
require.NoError(t, err)
require.Equal(t, uint64(1), s.GetEpoch())
require.NoError(t, d.d.AddShard(ctx, shardID+1, 1, *rg, []clustermgr.ShardUnitInfo{{DiskID: 1}}))
_, err = d.d.GetShard(shardID + 1)
shardID2 := proto.ShardID(2)
suid2 := proto.EncodeSuid(shardID2, 0, 0)
require.NoError(t, d.d.AddShard(ctx, suid2, 1, *rg, []clustermgr.ShardUnitInfo{{DiskID: 1}}))
_, err = d.d.GetShard(suid2)
require.NoError(t, err)
d.d.RangeShard(func(s ShardHandler) bool { s.Checkpoint(ctx); return true })
require.NoError(t, d.d.DeleteShard(ctx, shardID+1))
require.NoError(t, d.d.DeleteShard(ctx, shardID+1))
require.NoError(t, d.d.DeleteShard(ctx, suid2))
require.NoError(t, d.d.DeleteShard(ctx, suid2))
_, err = d.d.GetShard(shardID + 1)
_, err = d.d.GetShard(suid2)
require.Equal(t, apierr.ErrShardDoesNotExist, err)
require.NoError(t, d.d.Load(ctx))

View File

@ -107,12 +107,13 @@ func (mr *MockSpaceShardHandlerMockRecorder) InsertItem(ctx, h, i interface{}) *
}
// ListItem mocks base method.
func (m *MockSpaceShardHandler) ListItem(ctx context.Context, h OpHeader, prefix, id []byte, count uint64) ([]*shardnode.Item, error) {
func (m *MockSpaceShardHandler) ListItem(ctx context.Context, h OpHeader, prefix, id []byte, count uint64) ([]shardnode.Item, []byte, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ListItem", ctx, h, prefix, id, count)
ret0, _ := ret[0].([]*shardnode.Item)
ret1, _ := ret[1].(error)
return ret0, ret1
ret0, _ := ret[0].([]shardnode.Item)
ret1, _ := ret[1].([]byte)
ret2, _ := ret[2].(error)
return ret0, ret1, ret2
}
// ListItem indicates an expected call of ListItem.

View File

@ -26,7 +26,7 @@ type (
UpdateItem(ctx context.Context, h OpHeader, i shardnode.Item) error
DeleteItem(ctx context.Context, h OpHeader, id []byte) error
GetItem(ctx context.Context, h OpHeader, id []byte) (shardnode.Item, error)
ListItem(ctx context.Context, h OpHeader, prefix, id []byte, count uint64) ([]*shardnode.Item, error)
ListItem(ctx context.Context, h OpHeader, prefix, id []byte, count uint64) (items []shardnode.Item, nextMarker []byte, err error)
GetEpoch() uint64
Checkpoint(ctx context.Context) error
Stats() ShardStats
@ -219,36 +219,45 @@ func (s *shard) GetItem(ctx context.Context, h OpHeader, id []byte) (protoItem s
return
}
func (s *shard) ListItem(ctx context.Context, h OpHeader, prefix, id []byte, count uint64) ([]*shardnode.Item, error) {
func (s *shard) ListItem(ctx context.Context, h OpHeader, prefix, marker []byte, count uint64) (items []shardnode.Item, nextMarker []byte, err error) {
if err := s.checkShardOptHeader(h); err != nil {
return nil, err
return nil, nil, err
}
kvStore := s.store.KVStore()
ro := kvStore.NewReadOption()
cursor := kvStore.List(ctx, dataCF, s.shardKeys.encodeItemKey(prefix), s.shardKeys.encodeItemKey(marker), nil)
cursor := kvStore.List(ctx, dataCF, s.shardKeys.encodeItemKey(prefix), s.shardKeys.encodeItemKey(id), ro)
items := make([]*shardnode.Item, count)
for i := uint64(0); i < count; i++ {
_, vg, err := cursor.ReadNext()
count += 1
for count > 0 {
kg, vg, err := cursor.ReadNext()
if err != nil {
return nil, err
return nil, nil, err
}
if vg == nil {
break
}
data := make([]byte, vg.Size())
copy(data, vg.Value())
vg.Close()
itm := &item{}
if err = itm.Unmarshal(data); err != nil {
return nil, err
if err = itm.Unmarshal(vg.Value()); err != nil {
return nil, nil, err
}
items[i] = &shardnode.Item{
if count == 1 {
nextMarker = make([]byte, len(kg.Key()))
copy(nextMarker, kg.Key())
kg.Close()
vg.Close()
break
}
kg.Close()
vg.Close()
items = append(items, shardnode.Item{
ID: itm.ID,
Fields: internalFieldsToProtoFields(itm.Fields),
}
})
count--
}
return items, nil
return items, s.shardKeys.decodeItemKey(nextMarker), nil
}
func (s *shard) GetEpoch() uint64 {
@ -404,7 +413,15 @@ func (s *shardKeysGenerator) encodeItemKey(key []byte) []byte {
newKey := make([]byte, shardItemPrefixSize+len(key))
encodeShardItemPrefix(s.suid, newKey)
copy(newKey[shardItemPrefixSize:], key)
return key
return newKey
}
func (s *shardKeysGenerator) decodeItemKey(key []byte) []byte {
if len(key) == 0 {
return nil
}
shardItemPrefixSize := shardItemPrefixSize()
return key[shardItemPrefixSize:]
}
// encode shard info key with prefix: s[shardID]

View File

@ -1,6 +1,7 @@
package storage
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
@ -63,6 +64,38 @@ func TestServerShardSM_Item(t *testing.T) {
ShardKeys: [][]byte{newProtoItem.ID},
}, newProtoItem.ID)
require.ErrorIs(t, err, kvstore.ErrNotFound)
// List
n := 4
items := make([]*proto.Item, n)
for i := 0; i < n; i++ {
s := fmt.Sprint(i)
protoItem := &proto.Item{
ID: []byte(s),
Fields: []proto.Field{
{ID: 0, Value: []byte("string")},
{ID: 1, Value: []byte(s)},
},
}
protoItemBytes, err := protoItem.Marshal()
require.NoError(t, err)
err = mockShard.shardSM.applyInsertItem(ctx, protoItemBytes)
require.Nil(t, err)
items[i] = protoItem
}
rets, marker, err := mockShard.shard.ListItem(ctx, OpHeader{
ShardKeys: [][]byte{items[0].ID}}, nil, items[0].ID, uint64(n-1))
require.Nil(t, err)
require.Equal(t, items[n-1].ID, marker)
for i := 0; i < n-1; i++ {
require.Equal(t, items[i].ID, rets[i].ID)
}
_, marker, err = mockShard.shard.ListItem(ctx, OpHeader{
ShardKeys: [][]byte{items[0].ID}}, nil, items[0].ID, uint64(n))
require.Nil(t, err)
require.Nil(t, marker)
}
func TestServerShardSM_Apply(t *testing.T) {

View File

@ -37,11 +37,11 @@ func GenTmpPath() (string, error) {
}
func StringToBytes(s string) []byte {
return unsafe.Slice(unsafe.StringData(s), len(s))
return *(*[]byte)(unsafe.Pointer(&s))
}
func BytesToString(b []byte) string {
return unsafe.String(unsafe.SliceData(b), len(b))
return *(*string)(unsafe.Pointer(&b))
}
func GetLocalIP() (string, error) {