2021-10-27 19:00:48 +08:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
// "License"); you may not use this file except in compliance
|
2021-08-19 10:28:10 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-10-27 19:00:48 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-08-19 10:28:10 +08:00
|
|
|
//
|
2021-10-27 19:00:48 +08:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2021-08-19 10:28:10 +08:00
|
|
|
|
|
|
|
package indexcoord
|
|
|
|
|
2022-09-15 15:44:31 +08:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
2022-09-27 22:38:55 +08:00
|
|
|
"sync"
|
2022-09-15 15:44:31 +08:00
|
|
|
"testing"
|
|
|
|
|
2022-10-16 20:49:27 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/commonpb"
|
2022-09-15 15:44:31 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/indexnode"
|
|
|
|
"github.com/milvus-io/milvus/internal/metastore/model"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/indexpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/types"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNodeManager_PeekClient(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
nm := NewNodeManager(context.Background())
|
|
|
|
nodeID, client := nm.PeekClient(&model.SegmentIndex{})
|
|
|
|
assert.Equal(t, int64(-1), nodeID)
|
|
|
|
assert.Nil(t, client)
|
|
|
|
err := nm.AddNode(1, "indexnode-1")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
nm.pq.SetMemory(1, 100)
|
|
|
|
nodeID2, client2 := nm.PeekClient(&model.SegmentIndex{})
|
|
|
|
assert.Equal(t, int64(0), nodeID2)
|
|
|
|
assert.Nil(t, client2)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("multiple unavailable IndexNode", func(t *testing.T) {
|
|
|
|
nm := &NodeManager{
|
|
|
|
ctx: context.TODO(),
|
|
|
|
nodeClients: map[UniqueID]types.IndexNode{
|
|
|
|
1: &indexnode.Mock{
|
|
|
|
CallGetJobStats: func(ctx context.Context, req *indexpb.GetJobStatsRequest) (*indexpb.GetJobStatsResponse, error) {
|
|
|
|
return &indexpb.GetJobStatsResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
},
|
|
|
|
}, errors.New("error")
|
|
|
|
},
|
|
|
|
},
|
|
|
|
2: &indexnode.Mock{
|
|
|
|
CallGetJobStats: func(ctx context.Context, req *indexpb.GetJobStatsRequest) (*indexpb.GetJobStatsResponse, error) {
|
|
|
|
return &indexpb.GetJobStatsResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
},
|
|
|
|
}, errors.New("error")
|
|
|
|
},
|
|
|
|
},
|
|
|
|
3: &indexnode.Mock{
|
|
|
|
CallGetJobStats: func(ctx context.Context, req *indexpb.GetJobStatsRequest) (*indexpb.GetJobStatsResponse, error) {
|
|
|
|
return &indexpb.GetJobStatsResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
},
|
|
|
|
}, errors.New("error")
|
|
|
|
},
|
|
|
|
},
|
|
|
|
4: &indexnode.Mock{
|
|
|
|
CallGetJobStats: func(ctx context.Context, req *indexpb.GetJobStatsRequest) (*indexpb.GetJobStatsResponse, error) {
|
|
|
|
return &indexpb.GetJobStatsResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
},
|
|
|
|
}, errors.New("error")
|
|
|
|
},
|
|
|
|
},
|
|
|
|
5: &indexnode.Mock{
|
|
|
|
CallGetJobStats: func(ctx context.Context, req *indexpb.GetJobStatsRequest) (*indexpb.GetJobStatsResponse, error) {
|
|
|
|
return &indexpb.GetJobStatsResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
Reason: "fail reason",
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
6: &indexnode.Mock{
|
|
|
|
CallGetJobStats: func(ctx context.Context, req *indexpb.GetJobStatsRequest) (*indexpb.GetJobStatsResponse, error) {
|
|
|
|
return &indexpb.GetJobStatsResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
Reason: "fail reason",
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
7: &indexnode.Mock{
|
|
|
|
CallGetJobStats: func(ctx context.Context, req *indexpb.GetJobStatsRequest) (*indexpb.GetJobStatsResponse, error) {
|
|
|
|
return &indexpb.GetJobStatsResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
Reason: "fail reason",
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
8: &indexnode.Mock{
|
|
|
|
CallGetJobStats: func(ctx context.Context, req *indexpb.GetJobStatsRequest) (*indexpb.GetJobStatsResponse, error) {
|
|
|
|
return &indexpb.GetJobStatsResponse{
|
|
|
|
TaskSlots: 1,
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
Reason: "",
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
9: &indexnode.Mock{
|
|
|
|
CallGetJobStats: func(ctx context.Context, req *indexpb.GetJobStatsRequest) (*indexpb.GetJobStatsResponse, error) {
|
|
|
|
return &indexpb.GetJobStatsResponse{
|
|
|
|
TaskSlots: 10,
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
Reason: "",
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
nodeID, client := nm.PeekClient(&model.SegmentIndex{})
|
|
|
|
assert.NotNil(t, client)
|
|
|
|
assert.Contains(t, []UniqueID{8, 9}, nodeID)
|
|
|
|
})
|
|
|
|
}
|
2022-09-27 22:38:55 +08:00
|
|
|
|
|
|
|
func TestNodeManager_ClientSupportDisk(t *testing.T) {
|
|
|
|
t.Run("support", func(t *testing.T) {
|
|
|
|
nm := &NodeManager{
|
|
|
|
ctx: context.Background(),
|
|
|
|
lock: sync.RWMutex{},
|
|
|
|
nodeClients: map[UniqueID]types.IndexNode{
|
|
|
|
1: &indexnode.Mock{
|
|
|
|
CallGetJobStats: func(ctx context.Context, in *indexpb.GetJobStatsRequest) (*indexpb.GetJobStatsResponse, error) {
|
|
|
|
return &indexpb.GetJobStatsResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
Reason: "",
|
|
|
|
},
|
|
|
|
TaskSlots: 1,
|
|
|
|
JobInfos: nil,
|
|
|
|
EnableDisk: true,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
support := nm.ClientSupportDisk()
|
|
|
|
assert.True(t, support)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("not support", func(t *testing.T) {
|
|
|
|
nm := &NodeManager{
|
|
|
|
ctx: context.Background(),
|
|
|
|
lock: sync.RWMutex{},
|
|
|
|
nodeClients: map[UniqueID]types.IndexNode{
|
|
|
|
1: &indexnode.Mock{
|
|
|
|
CallGetJobStats: func(ctx context.Context, in *indexpb.GetJobStatsRequest) (*indexpb.GetJobStatsResponse, error) {
|
|
|
|
return &indexpb.GetJobStatsResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
Reason: "",
|
|
|
|
},
|
|
|
|
TaskSlots: 1,
|
|
|
|
JobInfos: nil,
|
|
|
|
EnableDisk: false,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
support := nm.ClientSupportDisk()
|
|
|
|
assert.False(t, support)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("no indexnode", func(t *testing.T) {
|
|
|
|
nm := &NodeManager{
|
|
|
|
ctx: context.Background(),
|
|
|
|
lock: sync.RWMutex{},
|
|
|
|
nodeClients: map[UniqueID]types.IndexNode{},
|
|
|
|
}
|
|
|
|
|
|
|
|
support := nm.ClientSupportDisk()
|
|
|
|
assert.False(t, support)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("error", func(t *testing.T) {
|
|
|
|
nm := &NodeManager{
|
|
|
|
ctx: context.Background(),
|
|
|
|
lock: sync.RWMutex{},
|
|
|
|
nodeClients: map[UniqueID]types.IndexNode{
|
|
|
|
1: &indexnode.Mock{
|
|
|
|
CallGetJobStats: func(ctx context.Context, in *indexpb.GetJobStatsRequest) (*indexpb.GetJobStatsResponse, error) {
|
|
|
|
return nil, errors.New("error")
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
support := nm.ClientSupportDisk()
|
|
|
|
assert.False(t, support)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("fail reason", func(t *testing.T) {
|
|
|
|
nm := &NodeManager{
|
|
|
|
ctx: context.Background(),
|
|
|
|
lock: sync.RWMutex{},
|
|
|
|
nodeClients: map[UniqueID]types.IndexNode{
|
|
|
|
1: &indexnode.Mock{
|
|
|
|
CallGetJobStats: func(ctx context.Context, in *indexpb.GetJobStatsRequest) (*indexpb.GetJobStatsResponse, error) {
|
|
|
|
return &indexpb.GetJobStatsResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
Reason: "fail reason",
|
|
|
|
},
|
|
|
|
TaskSlots: 0,
|
|
|
|
JobInfos: nil,
|
|
|
|
EnableDisk: false,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
support := nm.ClientSupportDisk()
|
|
|
|
assert.False(t, support)
|
|
|
|
})
|
|
|
|
}
|