Skip to content

Commit

Permalink
Refine state check (milvus-io#27541)
Browse files Browse the repository at this point in the history
Signed-off-by: yah01 <yah2er0ne@outlook.com>
  • Loading branch information
yah01 authored Oct 11, 2023
1 parent 0f2f4a0 commit be980fb
Show file tree
Hide file tree
Showing 112 changed files with 985 additions and 1,171 deletions.
19 changes: 12 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
run:
go: '1.18'
go: "1.18"
skip-dirs:
- build
- configs
Expand Down Expand Up @@ -89,20 +89,20 @@ linters-settings:
settings:
ruleguard:
failOnError: true
rules: 'rules.go'
rules: "rules.go"
depguard:
rules:
main:
deny:
- pkg: 'errors'
- pkg: "errors"
desc: not allowd, use github.com/cockroachdb/errors
- pkg: 'github.com/pkg/errors'
- pkg: "github.com/pkg/errors"
desc: not allowd, use github.com/cockroachdb/errors
- pkg: 'github.com/pingcap/errors'
- pkg: "github.com/pingcap/errors"
desc: not allowd, use github.com/cockroachdb/errors
- pkg: 'golang.org/x/xerrors'
- pkg: "golang.org/x/xerrors"
desc: not allowd, use github.com/cockroachdb/errors
- pkg: 'github.com/go-errors/errors'
- pkg: "github.com/go-errors/errors"
desc: not allowd, use github.com/cockroachdb/errors
forbidigo:
forbid:
Expand All @@ -112,10 +112,15 @@ linters-settings:
- '\.(ErrorCode|Reason) = '
- 'Reason:\s+\w+\.Error\(\)'
- 'errors.New\((.+)\.GetReason\(\)\)'
- 'commonpb\.Status\{[\s\n]*ErrorCode:[\s\n]*.+[\s\S\n]*?\}'
#- 'fmt\.Print.*' WIP

issues:
exclude-use-default: false
exclude-rules:
- path: .+_test\.go
linters:
- forbidigo
exclude:
- should have a package comment
- should have comment
Expand Down
2 changes: 1 addition & 1 deletion internal/allocator/id_allocator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type mockIDAllocator struct{}

func (tso *mockIDAllocator) AllocID(ctx context.Context, req *rootcoordpb.AllocIDRequest, opts ...grpc.CallOption) (*rootcoordpb.AllocIDResponse, error) {
return &rootcoordpb.AllocIDResponse{
Status: merr.Status(nil),
Status: merr.Success(),
ID: int64(1),
Count: req.Count,
}, nil
Expand Down
18 changes: 9 additions & 9 deletions internal/datacoord/index_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ func TestIndexBuilder(t *testing.T) {
ic := mocks.NewMockIndexNodeClient(t)
ic.EXPECT().GetJobStats(mock.Anything, mock.Anything, mock.Anything).
Return(&indexpb.GetJobStatsResponse{
Status: merr.Status(nil),
Status: merr.Success(),
TotalJobNum: 1,
EnqueueJobNum: 0,
InProgressJobNum: 1,
Expand All @@ -645,17 +645,17 @@ func TestIndexBuilder(t *testing.T) {
})
}
return &indexpb.QueryJobsResponse{
Status: merr.Status(nil),
Status: merr.Success(),
ClusterID: in.ClusterID,
IndexInfos: indexInfos,
}, nil
})

ic.EXPECT().CreateJob(mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(merr.Status(nil), nil)
Return(merr.Success(), nil)

ic.EXPECT().DropJobs(mock.Anything, mock.Anything, mock.Anything).
Return(merr.Status(nil), nil)
Return(merr.Success(), nil)
mt := createMetaTable(catalog)
nodeManager := &IndexNodeManager{
ctx: ctx,
Expand Down Expand Up @@ -811,7 +811,7 @@ func TestIndexBuilder_Error(t *testing.T) {
ic := mocks.NewMockIndexNodeClient(t)
ic.EXPECT().CreateJob(mock.Anything, mock.Anything, mock.Anything).Return(nil, errors.New("error"))
ic.EXPECT().GetJobStats(mock.Anything, mock.Anything, mock.Anything).Return(&indexpb.GetJobStatsResponse{
Status: merr.Status(nil),
Status: merr.Success(),
TaskSlots: 1,
}, nil)

Expand All @@ -836,7 +836,7 @@ func TestIndexBuilder_Error(t *testing.T) {
Reason: "mock fail",
}, nil)
ic.EXPECT().GetJobStats(mock.Anything, mock.Anything, mock.Anything).Return(&indexpb.GetJobStatsResponse{
Status: merr.Status(nil),
Status: merr.Success(),
TaskSlots: 1,
}, nil)

Expand Down Expand Up @@ -963,7 +963,7 @@ func TestIndexBuilder_Error(t *testing.T) {
ib.meta.catalog = ec
ic := mocks.NewMockIndexNodeClient(t)
ic.EXPECT().QueryJobs(mock.Anything, mock.Anything, mock.Anything).Return(&indexpb.QueryJobsResponse{
Status: merr.Status(nil),
Status: merr.Success(),
IndexInfos: []*indexpb.IndexTaskInfo{
{
BuildID: buildID,
Expand Down Expand Up @@ -995,7 +995,7 @@ func TestIndexBuilder_Error(t *testing.T) {
ib.meta.catalog = ec
ic := mocks.NewMockIndexNodeClient(t)
ic.EXPECT().QueryJobs(mock.Anything, mock.Anything, mock.Anything).Return(&indexpb.QueryJobsResponse{
Status: merr.Status(nil),
Status: merr.Success(),
IndexInfos: []*indexpb.IndexTaskInfo{
{
BuildID: buildID,
Expand Down Expand Up @@ -1027,7 +1027,7 @@ func TestIndexBuilder_Error(t *testing.T) {
ib.meta.catalog = sc
ic := mocks.NewMockIndexNodeClient(t)
ic.EXPECT().QueryJobs(mock.Anything, mock.Anything, mock.Anything).Return(&indexpb.QueryJobsResponse{
Status: merr.Status(nil),
Status: merr.Success(),
IndexInfos: nil,
}, nil)
ib.nodeManager = &IndexNodeManager{
Expand Down
23 changes: 9 additions & 14 deletions internal/datacoord/index_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (s *Server) CreateIndex(ctx context.Context, req *indexpb.CreateIndexReques
zap.String("IndexName", req.GetIndexName()), zap.Int64("fieldID", req.GetFieldID()),
zap.Int64("IndexID", indexID))
metrics.IndexRequestCounter.WithLabelValues(metrics.SuccessLabel).Inc()
return merr.Status(nil), nil
return merr.Success(), nil
}

// GetIndexState gets the index state of the index name in the request from Proxy.
Expand Down Expand Up @@ -240,7 +240,7 @@ func (s *Server) GetIndexState(ctx context.Context, req *indexpb.GetIndexStateRe
}, nil
}
ret := &indexpb.GetIndexStateResponse{
Status: merr.Status(nil),
Status: merr.Success(),
State: commonpb.IndexState_Finished,
}

Expand Down Expand Up @@ -274,7 +274,7 @@ func (s *Server) GetSegmentIndexState(ctx context.Context, req *indexpb.GetSegme
}

ret := &indexpb.GetSegmentIndexStateResponse{
Status: merr.Status(nil),
Status: merr.Success(),
States: make([]*indexpb.SegmentIndexState, 0),
}
indexID2CreateTs := s.meta.GetIndexIDByName(req.GetCollectionID(), req.GetIndexName())
Expand Down Expand Up @@ -469,7 +469,7 @@ func (s *Server) GetIndexBuildProgress(ctx context.Context, req *indexpb.GetInde
log.Info("GetIndexBuildProgress success", zap.Int64("collectionID", req.GetCollectionID()),
zap.String("indexName", req.GetIndexName()))
return &indexpb.GetIndexBuildProgressResponse{
Status: merr.Status(nil),
Status: merr.Success(),
IndexedRows: indexInfo.IndexedRows,
TotalRows: indexInfo.TotalRows,
PendingIndexRows: indexInfo.PendingIndexRows,
Expand Down Expand Up @@ -531,7 +531,7 @@ func (s *Server) DescribeIndex(ctx context.Context, req *indexpb.DescribeIndexRe
}
log.Info("DescribeIndex success")
return &indexpb.DescribeIndexResponse{
Status: merr.Status(nil),
Status: merr.Success(),
IndexInfos: indexInfos,
}, nil
}
Expand Down Expand Up @@ -586,7 +586,7 @@ func (s *Server) GetIndexStatistics(ctx context.Context, req *indexpb.GetIndexSt
log.Debug("GetIndexStatisticsResponse success",
zap.String("indexName", req.GetIndexName()))
return &indexpb.GetIndexStatisticsResponse{
Status: merr.Status(nil),
Status: merr.Success(),
IndexInfos: indexInfos,
}, nil
}
Expand All @@ -610,7 +610,7 @@ func (s *Server) DropIndex(ctx context.Context, req *indexpb.DropIndexRequest) (
indexes := s.meta.GetIndexesForCollection(req.GetCollectionID(), req.GetIndexName())
if len(indexes) == 0 {
log.Info(fmt.Sprintf("there is no index on collection: %d with the index name: %s", req.CollectionID, req.IndexName))
return merr.Status(nil), nil
return merr.Success(), nil
}

if !req.GetDropAll() && len(indexes) > 1 {
Expand All @@ -635,7 +635,7 @@ func (s *Server) DropIndex(ctx context.Context, req *indexpb.DropIndexRequest) (

log.Debug("DropIndex success", zap.Int64s("partitionIDs", req.GetPartitionIDs()),
zap.String("indexName", req.GetIndexName()), zap.Int64s("indexIDs", indexIDs))
return merr.Status(nil), nil
return merr.Success(), nil
}

// GetIndexInfos gets the index file paths for segment from DataCoord.
Expand All @@ -651,7 +651,7 @@ func (s *Server) GetIndexInfos(ctx context.Context, req *indexpb.GetIndexInfoReq
}, nil
}
ret := &indexpb.GetIndexInfoResponse{
Status: merr.Status(nil),
Status: merr.Success(),
SegmentInfo: map[int64]*indexpb.SegmentInfo{},
}

Expand Down Expand Up @@ -694,8 +694,3 @@ func (s *Server) GetIndexInfos(ctx context.Context, req *indexpb.GetIndexInfoReq

return ret, nil
}

func (s *Server) UnhealthyStatus() *commonpb.Status {
code := s.stateCode.Load().(commonpb.StateCode)
return merr.Status(merr.WrapErrServiceNotReady(code.String()))
}
8 changes: 4 additions & 4 deletions internal/datacoord/indexnode_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ func TestIndexNodeManager_PeekClient(t *testing.T) {
}, nil),
8: getMockedGetJobStatsClient(&indexpb.GetJobStatsResponse{
TaskSlots: 1,
Status: merr.Status(nil),
Status: merr.Success(),
}, nil),
9: getMockedGetJobStatsClient(&indexpb.GetJobStatsResponse{
TaskSlots: 10,
Status: merr.Status(nil),
Status: merr.Success(),
}, nil),
},
}
Expand All @@ -115,7 +115,7 @@ func TestIndexNodeManager_ClientSupportDisk(t *testing.T) {
lock: sync.RWMutex{},
nodeClients: map[UniqueID]types.IndexNodeClient{
1: getMockedGetJobStatsClient(&indexpb.GetJobStatsResponse{
Status: merr.Status(nil),
Status: merr.Success(),
TaskSlots: 1,
JobInfos: nil,
EnableDisk: true,
Expand All @@ -133,7 +133,7 @@ func TestIndexNodeManager_ClientSupportDisk(t *testing.T) {
lock: sync.RWMutex{},
nodeClients: map[UniqueID]types.IndexNodeClient{
1: getMockedGetJobStatsClient(&indexpb.GetJobStatsResponse{
Status: merr.Status(nil),
Status: merr.Success(),
TaskSlots: 1,
JobInfos: nil,
EnableDisk: false,
Expand Down
2 changes: 1 addition & 1 deletion internal/datacoord/metrics_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s *Server) getSystemInfoMetrics(
}

resp := &milvuspb.GetMetricsResponse{
Status: merr.Status(nil),
Status: merr.Success(),
ComponentName: metricsinfo.ConstructComponentName(typeutil.DataCoordRole, paramtable.GetNodeID()),
}
var err error
Expand Down
6 changes: 3 additions & 3 deletions internal/datacoord/metrics_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestGetDataNodeMetrics(t *testing.T) {
// mock parse error
mockFailClientCreator = getMockFailedClientCreator(func() (*milvuspb.GetMetricsResponse, error) {
return &milvuspb.GetMetricsResponse{
Status: merr.Status(nil),
Status: merr.Success(),
Response: `{"error_reason": 1}`,
}, nil
})
Expand Down Expand Up @@ -157,7 +157,7 @@ func TestGetIndexNodeMetrics(t *testing.T) {
info, err = svr.getIndexNodeMetrics(ctx, req, &mockMetricIndexNodeClient{
mock: func() (*milvuspb.GetMetricsResponse, error) {
return &milvuspb.GetMetricsResponse{
Status: merr.Status(nil),
Status: merr.Success(),
Response: "XXXXXXXXXXXXX",
ComponentName: "indexnode100",
}, nil
Expand Down Expand Up @@ -187,7 +187,7 @@ func TestGetIndexNodeMetrics(t *testing.T) {
}

return &milvuspb.GetMetricsResponse{
Status: merr.Status(nil),
Status: merr.Success(),
Response: resp,
ComponentName: metricsinfo.ConstructComponentName(typeutil.IndexNodeRole, nodeID),
}, nil
Expand Down
Loading

0 comments on commit be980fb

Please sign in to comment.