mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-07 17:48:29 +08:00
Add unconvert & durationcheck linters and fix issues (#22161)
Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
This commit is contained in:
parent
5351fee733
commit
f2575e5fa8
@ -19,6 +19,8 @@ linters:
|
|||||||
- gosimple
|
- gosimple
|
||||||
- gosec
|
- gosec
|
||||||
- revive
|
- revive
|
||||||
|
- durationcheck
|
||||||
|
- unconvert
|
||||||
# - gocritic
|
# - gocritic
|
||||||
|
|
||||||
linters-settings:
|
linters-settings:
|
||||||
|
|||||||
@ -298,7 +298,7 @@ func (c *mockDataNodeClient) ShowConfigurations(ctx context.Context, req *intern
|
|||||||
|
|
||||||
func (c *mockDataNodeClient) GetMetrics(ctx context.Context, req *milvuspb.GetMetricsRequest) (*milvuspb.GetMetricsResponse, error) {
|
func (c *mockDataNodeClient) GetMetrics(ctx context.Context, req *milvuspb.GetMetricsRequest) (*milvuspb.GetMetricsResponse, error) {
|
||||||
// TODO(dragondriver): change the id, though it's not important in ut
|
// TODO(dragondriver): change the id, though it's not important in ut
|
||||||
nodeID := UniqueID(c.id)
|
nodeID := c.id
|
||||||
|
|
||||||
nodeInfos := metricsinfo.DataNodeInfos{
|
nodeInfos := metricsinfo.DataNodeInfos{
|
||||||
BaseComponentInfos: metricsinfo.BaseComponentInfos{
|
BaseComponentInfos: metricsinfo.BaseComponentInfos{
|
||||||
|
|||||||
@ -796,7 +796,7 @@ func Test_parseBinlogKey(t *testing.T) {
|
|||||||
|
|
||||||
func verifyBinlogs(t *testing.T, binlogBytes []byte) {
|
func verifyBinlogs(t *testing.T, binlogBytes []byte) {
|
||||||
binlogs := &datapb.FieldBinlog{}
|
binlogs := &datapb.FieldBinlog{}
|
||||||
err := proto.Unmarshal([]byte(binlogBytes), binlogs)
|
err := proto.Unmarshal(binlogBytes, binlogs)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, 1, len(binlogs.Binlogs))
|
assert.Equal(t, 1, len(binlogs.Binlogs))
|
||||||
assert.Equal(t, int64(99), binlogs.Binlogs[0].GetLogID())
|
assert.Equal(t, int64(99), binlogs.Binlogs[0].GetLogID())
|
||||||
|
|||||||
@ -403,9 +403,9 @@ func TestRocksmq_Dummy(t *testing.T) {
|
|||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
|
||||||
channelName2 := strings.Repeat(channelName1, 100)
|
channelName2 := strings.Repeat(channelName1, 100)
|
||||||
err = rmq.CreateTopic(string(channelName2))
|
err = rmq.CreateTopic(channelName2)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
_, err = rmq.Produce(string(channelName2), nil)
|
_, err = rmq.Produce(channelName2, nil)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
|
||||||
channelName3 := "channel/dummy"
|
channelName3 := "channel/dummy"
|
||||||
@ -950,7 +950,7 @@ func TestRocksmq_GetLatestMsg(t *testing.T) {
|
|||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
msgID, err := rmq.GetLatestMsg(channelName)
|
msgID, err := rmq.GetLatestMsg(channelName)
|
||||||
assert.Equal(t, msgID, int64(DefaultMessageID))
|
assert.Equal(t, msgID, DefaultMessageID)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
loopNum := 10
|
loopNum := 10
|
||||||
@ -990,7 +990,7 @@ func TestRocksmq_GetLatestMsg(t *testing.T) {
|
|||||||
rmq.DestroyTopic(channelName)
|
rmq.DestroyTopic(channelName)
|
||||||
rmq.Close()
|
rmq.Close()
|
||||||
msgID, err = rmq.GetLatestMsg(channelName)
|
msgID, err = rmq.GetLatestMsg(channelName)
|
||||||
assert.Equal(t, msgID, int64(DefaultMessageID))
|
assert.Equal(t, msgID, DefaultMessageID)
|
||||||
assert.NotNil(t, err)
|
assert.NotNil(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2270,7 +2270,7 @@ func (node *Proxy) Upsert(ctx context.Context, request *milvuspb.UpsertRequest)
|
|||||||
|
|
||||||
req: &milvuspb.UpsertRequest{
|
req: &milvuspb.UpsertRequest{
|
||||||
Base: commonpbutil.NewMsgBase(
|
Base: commonpbutil.NewMsgBase(
|
||||||
commonpbutil.WithMsgType(commonpb.MsgType(commonpb.MsgType_Upsert)),
|
commonpbutil.WithMsgType(commonpb.MsgType_Upsert),
|
||||||
commonpbutil.WithSourceID(paramtable.GetNodeID()),
|
commonpbutil.WithSourceID(paramtable.GetNodeID()),
|
||||||
),
|
),
|
||||||
CollectionName: request.CollectionName,
|
CollectionName: request.CollectionName,
|
||||||
|
|||||||
@ -634,8 +634,8 @@ func parseGuaranteeTs(ts, tMax typeutil.Timestamp) typeutil.Timestamp {
|
|||||||
case strongTS:
|
case strongTS:
|
||||||
ts = tMax
|
ts = tMax
|
||||||
case boundedTS:
|
case boundedTS:
|
||||||
ratio := time.Duration(-Params.CommonCfg.GracefulTime.GetAsInt64())
|
ratio := Params.CommonCfg.GracefulTime.GetAsDuration(time.Millisecond)
|
||||||
ts = tsoutil.AddPhysicalDurationOnTs(tMax, ratio*time.Millisecond)
|
ts = tsoutil.AddPhysicalDurationOnTs(tMax, -ratio)
|
||||||
}
|
}
|
||||||
return ts
|
return ts
|
||||||
}
|
}
|
||||||
|
|||||||
@ -70,8 +70,8 @@ func HandleCProto(cRes *C.CProto, msg proto.Message) error {
|
|||||||
|
|
||||||
// CopyCProtoBlob returns the copy of C memory
|
// CopyCProtoBlob returns the copy of C memory
|
||||||
func CopyCProtoBlob(cProto *C.CProto) []byte {
|
func CopyCProtoBlob(cProto *C.CProto) []byte {
|
||||||
blob := C.GoBytes(unsafe.Pointer(cProto.proto_blob), C.int32_t(cProto.proto_size))
|
blob := C.GoBytes(cProto.proto_blob, C.int32_t(cProto.proto_size))
|
||||||
C.free(unsafe.Pointer(cProto.proto_blob))
|
C.free(cProto.proto_blob)
|
||||||
return blob
|
return blob
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -90,7 +90,7 @@ func reduceSearchResultsAndFillData(plan *SearchPlan, searchResults []*SearchRes
|
|||||||
}
|
}
|
||||||
cSearchResults = append(cSearchResults, res.cSearchResult)
|
cSearchResults = append(cSearchResults, res.cSearchResult)
|
||||||
}
|
}
|
||||||
cSearchResultPtr := (*C.CSearchResult)(&cSearchResults[0])
|
cSearchResultPtr := &cSearchResults[0]
|
||||||
cNumSegments := C.int64_t(numSegments)
|
cNumSegments := C.int64_t(numSegments)
|
||||||
var cSliceNQSPtr = (*C.int64_t)(&sliceNQs[0])
|
var cSliceNQSPtr = (*C.int64_t)(&sliceNQs[0])
|
||||||
var cSliceTopKSPtr = (*C.int64_t)(&sliceTopKs[0])
|
var cSliceTopKSPtr = (*C.int64_t)(&sliceTopKs[0])
|
||||||
|
|||||||
@ -1293,7 +1293,7 @@ func TestNewBinlogReaderError(t *testing.T) {
|
|||||||
assert.NotNil(t, err)
|
assert.NotNil(t, err)
|
||||||
|
|
||||||
buffer := new(bytes.Buffer)
|
buffer := new(bytes.Buffer)
|
||||||
err = binary.Write(buffer, common.Endian, int32(MagicNumber))
|
err = binary.Write(buffer, common.Endian, MagicNumber)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
data = buffer.Bytes()
|
data = buffer.Bytes()
|
||||||
|
|
||||||
|
|||||||
@ -503,12 +503,12 @@ func getTypeName(dt schemapb.DataType) string {
|
|||||||
|
|
||||||
func pkToShard(pk interface{}, shardNum uint32) (uint32, error) {
|
func pkToShard(pk interface{}, shardNum uint32) (uint32, error) {
|
||||||
var shard uint32
|
var shard uint32
|
||||||
strPK, ok := interface{}(pk).(string)
|
strPK, ok := pk.(string)
|
||||||
if ok {
|
if ok {
|
||||||
hash := typeutil.HashString2Uint32(strPK)
|
hash := typeutil.HashString2Uint32(strPK)
|
||||||
shard = hash % shardNum
|
shard = hash % shardNum
|
||||||
} else {
|
} else {
|
||||||
intPK, ok := interface{}(pk).(int64)
|
intPK, ok := pk.(int64)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Error("Numpy parser: primary key field must be int64 or varchar")
|
log.Error("Numpy parser: primary key field must be int64 or varchar")
|
||||||
return 0, fmt.Errorf("primary key field must be int64 or varchar")
|
return 0, fmt.Errorf("primary key field must be int64 or varchar")
|
||||||
|
|||||||
@ -634,7 +634,7 @@ func (w *sessionWatcher) handleWatchResponse(wresp clientv3.WatchResponse) {
|
|||||||
case mvccpb.PUT:
|
case mvccpb.PUT:
|
||||||
log.Debug("watch services",
|
log.Debug("watch services",
|
||||||
zap.Any("add kv", ev.Kv))
|
zap.Any("add kv", ev.Kv))
|
||||||
err := json.Unmarshal([]byte(ev.Kv.Value), session)
|
err := json.Unmarshal(ev.Kv.Value, session)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("watch services", zap.Error(err))
|
log.Error("watch services", zap.Error(err))
|
||||||
continue
|
continue
|
||||||
@ -650,7 +650,7 @@ func (w *sessionWatcher) handleWatchResponse(wresp clientv3.WatchResponse) {
|
|||||||
case mvccpb.DELETE:
|
case mvccpb.DELETE:
|
||||||
log.Debug("watch services",
|
log.Debug("watch services",
|
||||||
zap.Any("delete kv", ev.PrevKv))
|
zap.Any("delete kv", ev.PrevKv))
|
||||||
err := json.Unmarshal([]byte(ev.PrevKv.Value), session)
|
err := json.Unmarshal(ev.PrevKv.Value, session)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("watch services", zap.Error(err))
|
log.Error("watch services", zap.Error(err))
|
||||||
continue
|
continue
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user