2021-09-15 20:40:07 +08:00
|
|
|
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// 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-07-16 10:21:55 +08:00
|
|
|
package querycoord
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-08-26 14:17:54 +08:00
|
|
|
"fmt"
|
|
|
|
"strconv"
|
2021-07-16 10:21:55 +08:00
|
|
|
"testing"
|
|
|
|
|
2021-08-03 22:03:25 +08:00
|
|
|
etcdkv "github.com/milvus-io/milvus/internal/kv/etcd"
|
2021-07-16 10:21:55 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
2021-10-21 12:18:36 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
2021-07-16 10:21:55 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
2021-10-21 12:18:36 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/funcutil"
|
|
|
|
"github.com/stretchr/testify/assert"
|
2021-07-16 10:21:55 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type testTask struct {
|
2021-10-18 21:34:47 +08:00
|
|
|
baseTask
|
2021-10-21 12:18:36 +08:00
|
|
|
baseMsg *commonpb.MsgBase
|
|
|
|
cluster Cluster
|
|
|
|
meta Meta
|
|
|
|
nodeID int64
|
|
|
|
binlogSize int
|
2021-07-16 10:21:55 +08:00
|
|
|
}
|
|
|
|
|
2021-10-14 20:18:33 +08:00
|
|
|
func (tt *testTask) msgBase() *commonpb.MsgBase {
|
2021-07-16 10:21:55 +08:00
|
|
|
return tt.baseMsg
|
|
|
|
}
|
|
|
|
|
2021-10-14 20:18:33 +08:00
|
|
|
func (tt *testTask) marshal() ([]byte, error) {
|
2021-08-03 22:03:25 +08:00
|
|
|
return []byte{}, nil
|
2021-07-16 10:21:55 +08:00
|
|
|
}
|
|
|
|
|
2021-10-14 20:18:33 +08:00
|
|
|
func (tt *testTask) msgType() commonpb.MsgType {
|
2021-07-16 10:21:55 +08:00
|
|
|
return tt.baseMsg.MsgType
|
|
|
|
}
|
|
|
|
|
2021-10-14 20:18:33 +08:00
|
|
|
func (tt *testTask) timestamp() Timestamp {
|
2021-07-16 10:21:55 +08:00
|
|
|
return tt.baseMsg.Timestamp
|
|
|
|
}
|
|
|
|
|
2021-10-14 20:18:33 +08:00
|
|
|
func (tt *testTask) preExecute(ctx context.Context) error {
|
|
|
|
tt.setResultInfo(nil)
|
2021-07-16 10:21:55 +08:00
|
|
|
log.Debug("test task preExecute...")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-10-14 20:18:33 +08:00
|
|
|
func (tt *testTask) execute(ctx context.Context) error {
|
2021-07-16 10:21:55 +08:00
|
|
|
log.Debug("test task execute...")
|
|
|
|
|
|
|
|
switch tt.baseMsg.MsgType {
|
2021-10-21 12:18:36 +08:00
|
|
|
case commonpb.MsgType_LoadCollection:
|
|
|
|
binlogs := make([]*datapb.FieldBinlog, 0)
|
|
|
|
binlogs = append(binlogs, &datapb.FieldBinlog{
|
|
|
|
FieldID: 0,
|
|
|
|
Binlogs: []string{funcutil.RandomString(tt.binlogSize)},
|
|
|
|
})
|
|
|
|
for id := 0; id < 10; id++ {
|
|
|
|
segmentInfo := &querypb.SegmentLoadInfo{
|
|
|
|
SegmentID: UniqueID(id),
|
|
|
|
PartitionID: defaultPartitionID,
|
|
|
|
CollectionID: defaultCollectionID,
|
|
|
|
BinlogPaths: binlogs,
|
|
|
|
}
|
|
|
|
req := &querypb.LoadSegmentsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_LoadSegments,
|
|
|
|
},
|
|
|
|
Infos: []*querypb.SegmentLoadInfo{segmentInfo},
|
|
|
|
}
|
|
|
|
loadTask := &loadSegmentTask{
|
|
|
|
baseTask: &baseTask{
|
|
|
|
ctx: tt.ctx,
|
|
|
|
condition: newTaskCondition(tt.ctx),
|
|
|
|
triggerCondition: tt.triggerCondition,
|
|
|
|
},
|
|
|
|
LoadSegmentsRequest: req,
|
|
|
|
meta: tt.meta,
|
|
|
|
cluster: tt.cluster,
|
|
|
|
excludeNodeIDs: []int64{},
|
|
|
|
}
|
|
|
|
loadTask.setParentTask(tt)
|
|
|
|
tt.addChildTask(loadTask)
|
|
|
|
}
|
2021-07-16 10:21:55 +08:00
|
|
|
case commonpb.MsgType_LoadSegments:
|
2021-10-18 21:34:47 +08:00
|
|
|
childTask := &loadSegmentTask{
|
|
|
|
baseTask: &baseTask{
|
2021-07-16 10:21:55 +08:00
|
|
|
ctx: tt.ctx,
|
2021-10-21 10:51:14 +08:00
|
|
|
condition: newTaskCondition(tt.ctx),
|
2021-07-16 10:21:55 +08:00
|
|
|
triggerCondition: tt.triggerCondition,
|
|
|
|
},
|
|
|
|
LoadSegmentsRequest: &querypb.LoadSegmentsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_LoadSegments,
|
|
|
|
},
|
2021-10-22 19:07:15 +08:00
|
|
|
DstNodeID: tt.nodeID,
|
2021-07-16 10:21:55 +08:00
|
|
|
},
|
2021-10-11 09:54:37 +08:00
|
|
|
meta: tt.meta,
|
|
|
|
cluster: tt.cluster,
|
|
|
|
excludeNodeIDs: []int64{},
|
2021-07-16 10:21:55 +08:00
|
|
|
}
|
2021-10-14 20:18:33 +08:00
|
|
|
tt.addChildTask(childTask)
|
2021-07-16 10:21:55 +08:00
|
|
|
case commonpb.MsgType_WatchDmChannels:
|
2021-10-18 21:34:47 +08:00
|
|
|
childTask := &watchDmChannelTask{
|
|
|
|
baseTask: &baseTask{
|
2021-07-16 10:21:55 +08:00
|
|
|
ctx: tt.ctx,
|
2021-10-21 10:51:14 +08:00
|
|
|
condition: newTaskCondition(tt.ctx),
|
2021-07-16 10:21:55 +08:00
|
|
|
triggerCondition: tt.triggerCondition,
|
|
|
|
},
|
|
|
|
WatchDmChannelsRequest: &querypb.WatchDmChannelsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_WatchDmChannels,
|
|
|
|
},
|
|
|
|
NodeID: tt.nodeID,
|
|
|
|
},
|
2021-10-11 09:54:37 +08:00
|
|
|
cluster: tt.cluster,
|
|
|
|
meta: tt.meta,
|
|
|
|
excludeNodeIDs: []int64{},
|
2021-07-16 10:21:55 +08:00
|
|
|
}
|
2021-10-14 20:18:33 +08:00
|
|
|
tt.addChildTask(childTask)
|
2021-07-16 10:21:55 +08:00
|
|
|
case commonpb.MsgType_WatchQueryChannels:
|
2021-10-18 21:34:47 +08:00
|
|
|
childTask := &watchQueryChannelTask{
|
|
|
|
baseTask: &baseTask{
|
2021-07-16 10:21:55 +08:00
|
|
|
ctx: tt.ctx,
|
2021-10-21 10:51:14 +08:00
|
|
|
condition: newTaskCondition(tt.ctx),
|
2021-07-16 10:21:55 +08:00
|
|
|
triggerCondition: tt.triggerCondition,
|
|
|
|
},
|
|
|
|
AddQueryChannelRequest: &querypb.AddQueryChannelRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_WatchQueryChannels,
|
|
|
|
},
|
|
|
|
NodeID: tt.nodeID,
|
|
|
|
},
|
|
|
|
cluster: tt.cluster,
|
|
|
|
}
|
2021-10-14 20:18:33 +08:00
|
|
|
tt.addChildTask(childTask)
|
2021-07-16 10:21:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-10-14 20:18:33 +08:00
|
|
|
func (tt *testTask) postExecute(ctx context.Context) error {
|
2021-07-16 10:21:55 +08:00
|
|
|
log.Debug("test task postExecute...")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestWatchQueryChannel_ClearEtcdInfoAfterAssignedNodeDown(t *testing.T) {
|
2021-09-15 20:40:07 +08:00
|
|
|
refreshParams()
|
2021-07-16 10:21:55 +08:00
|
|
|
baseCtx := context.Background()
|
|
|
|
queryCoord, err := startQueryCoord(baseCtx)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
activeTaskIDKeys, _, err := queryCoord.scheduler.client.LoadWithPrefix(activeTaskPrefix)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
queryNode, err := startQueryNodeServer(baseCtx)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
queryNode.addQueryChannels = returnFailedResult
|
|
|
|
|
2021-09-15 20:40:07 +08:00
|
|
|
nodeID := queryNode.queryNodeID
|
2021-10-11 09:54:37 +08:00
|
|
|
waitQueryNodeOnline(queryCoord.cluster, nodeID)
|
2021-07-16 10:21:55 +08:00
|
|
|
testTask := &testTask{
|
2021-10-18 21:34:47 +08:00
|
|
|
baseTask: baseTask{
|
2021-07-16 10:21:55 +08:00
|
|
|
ctx: baseCtx,
|
2021-10-21 10:51:14 +08:00
|
|
|
condition: newTaskCondition(baseCtx),
|
2021-07-16 10:21:55 +08:00
|
|
|
triggerCondition: querypb.TriggerCondition_grpcRequest,
|
|
|
|
},
|
|
|
|
baseMsg: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_WatchQueryChannels,
|
|
|
|
},
|
|
|
|
cluster: queryCoord.cluster,
|
|
|
|
meta: queryCoord.meta,
|
|
|
|
nodeID: nodeID,
|
|
|
|
}
|
2021-10-11 09:54:37 +08:00
|
|
|
queryCoord.scheduler.Enqueue(testTask)
|
2021-07-16 10:21:55 +08:00
|
|
|
|
2021-09-26 22:01:57 +08:00
|
|
|
queryNode.stop()
|
|
|
|
err = removeNodeSession(queryNode.queryNodeID)
|
|
|
|
assert.Nil(t, err)
|
2021-09-15 20:40:07 +08:00
|
|
|
for {
|
|
|
|
newActiveTaskIDKeys, _, err := queryCoord.scheduler.client.LoadWithPrefix(activeTaskPrefix)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
if len(newActiveTaskIDKeys) == len(activeTaskIDKeys) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2021-07-16 10:21:55 +08:00
|
|
|
queryCoord.Stop()
|
2021-09-26 22:01:57 +08:00
|
|
|
err = removeAllSession()
|
|
|
|
assert.Nil(t, err)
|
2021-07-16 10:21:55 +08:00
|
|
|
}
|
2021-08-03 22:03:25 +08:00
|
|
|
|
2021-08-26 14:17:54 +08:00
|
|
|
func TestUnMarshalTask(t *testing.T) {
|
|
|
|
refreshParams()
|
|
|
|
kv, err := etcdkv.NewEtcdKV(Params.EtcdEndpoints, Params.MetaRootPath)
|
|
|
|
assert.Nil(t, err)
|
2021-10-11 09:54:37 +08:00
|
|
|
baseCtx, cancel := context.WithCancel(context.Background())
|
|
|
|
taskScheduler := &TaskScheduler{
|
|
|
|
ctx: baseCtx,
|
|
|
|
cancel: cancel,
|
|
|
|
}
|
2021-08-26 14:17:54 +08:00
|
|
|
|
2021-10-18 21:34:47 +08:00
|
|
|
t.Run("Test loadCollectionTask", func(t *testing.T) {
|
|
|
|
loadTask := &loadCollectionTask{
|
2021-08-26 14:17:54 +08:00
|
|
|
LoadCollectionRequest: &querypb.LoadCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_LoadCollection,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-10-14 20:18:33 +08:00
|
|
|
blobs, err := loadTask.marshal()
|
2021-08-26 14:17:54 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
err = kv.Save("testMarshalLoadCollection", string(blobs))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer kv.RemoveWithPrefix("testMarshalLoadCollection")
|
|
|
|
value, err := kv.Load("testMarshalLoadCollection")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2021-10-11 09:54:37 +08:00
|
|
|
task, err := taskScheduler.unmarshalTask(1000, value)
|
2021-08-26 14:17:54 +08:00
|
|
|
assert.Nil(t, err)
|
2021-10-14 20:18:33 +08:00
|
|
|
assert.Equal(t, task.msgType(), commonpb.MsgType_LoadCollection)
|
2021-08-26 14:17:54 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test LoadPartitionsTask", func(t *testing.T) {
|
2021-10-18 21:34:47 +08:00
|
|
|
loadTask := &loadPartitionTask{
|
2021-08-26 14:17:54 +08:00
|
|
|
LoadPartitionsRequest: &querypb.LoadPartitionsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_LoadPartitions,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-10-14 20:18:33 +08:00
|
|
|
blobs, err := loadTask.marshal()
|
2021-08-26 14:17:54 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
err = kv.Save("testMarshalLoadPartition", string(blobs))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer kv.RemoveWithPrefix("testMarshalLoadPartition")
|
|
|
|
value, err := kv.Load("testMarshalLoadPartition")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2021-10-11 09:54:37 +08:00
|
|
|
task, err := taskScheduler.unmarshalTask(1001, value)
|
2021-08-26 14:17:54 +08:00
|
|
|
assert.Nil(t, err)
|
2021-10-14 20:18:33 +08:00
|
|
|
assert.Equal(t, task.msgType(), commonpb.MsgType_LoadPartitions)
|
2021-08-26 14:17:54 +08:00
|
|
|
})
|
|
|
|
|
2021-10-18 21:34:47 +08:00
|
|
|
t.Run("Test releaseCollectionTask", func(t *testing.T) {
|
|
|
|
releaseTask := &releaseCollectionTask{
|
2021-08-26 14:17:54 +08:00
|
|
|
ReleaseCollectionRequest: &querypb.ReleaseCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_ReleaseCollection,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-10-14 20:18:33 +08:00
|
|
|
blobs, err := releaseTask.marshal()
|
2021-08-26 14:17:54 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
err = kv.Save("testMarshalReleaseCollection", string(blobs))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer kv.RemoveWithPrefix("testMarshalReleaseCollection")
|
|
|
|
value, err := kv.Load("testMarshalReleaseCollection")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2021-10-11 09:54:37 +08:00
|
|
|
task, err := taskScheduler.unmarshalTask(1002, value)
|
2021-08-26 14:17:54 +08:00
|
|
|
assert.Nil(t, err)
|
2021-10-14 20:18:33 +08:00
|
|
|
assert.Equal(t, task.msgType(), commonpb.MsgType_ReleaseCollection)
|
2021-08-26 14:17:54 +08:00
|
|
|
})
|
|
|
|
|
2021-10-18 21:34:47 +08:00
|
|
|
t.Run("Test releasePartitionTask", func(t *testing.T) {
|
|
|
|
releaseTask := &releasePartitionTask{
|
2021-08-26 14:17:54 +08:00
|
|
|
ReleasePartitionsRequest: &querypb.ReleasePartitionsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_ReleasePartitions,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-10-14 20:18:33 +08:00
|
|
|
blobs, err := releaseTask.marshal()
|
2021-08-26 14:17:54 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
err = kv.Save("testMarshalReleasePartition", string(blobs))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer kv.RemoveWithPrefix("testMarshalReleasePartition")
|
|
|
|
value, err := kv.Load("testMarshalReleasePartition")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2021-10-11 09:54:37 +08:00
|
|
|
task, err := taskScheduler.unmarshalTask(1003, value)
|
2021-08-26 14:17:54 +08:00
|
|
|
assert.Nil(t, err)
|
2021-10-14 20:18:33 +08:00
|
|
|
assert.Equal(t, task.msgType(), commonpb.MsgType_ReleasePartitions)
|
2021-08-26 14:17:54 +08:00
|
|
|
})
|
|
|
|
|
2021-10-18 21:34:47 +08:00
|
|
|
t.Run("Test loadSegmentTask", func(t *testing.T) {
|
|
|
|
loadTask := &loadSegmentTask{
|
2021-08-26 14:17:54 +08:00
|
|
|
LoadSegmentsRequest: &querypb.LoadSegmentsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_LoadSegments,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-10-14 20:18:33 +08:00
|
|
|
blobs, err := loadTask.marshal()
|
2021-08-26 14:17:54 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
err = kv.Save("testMarshalLoadSegment", string(blobs))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer kv.RemoveWithPrefix("testMarshalLoadSegment")
|
|
|
|
value, err := kv.Load("testMarshalLoadSegment")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2021-10-11 09:54:37 +08:00
|
|
|
task, err := taskScheduler.unmarshalTask(1004, value)
|
2021-08-26 14:17:54 +08:00
|
|
|
assert.Nil(t, err)
|
2021-10-14 20:18:33 +08:00
|
|
|
assert.Equal(t, task.msgType(), commonpb.MsgType_LoadSegments)
|
2021-08-26 14:17:54 +08:00
|
|
|
})
|
|
|
|
|
2021-10-18 21:34:47 +08:00
|
|
|
t.Run("Test releaseSegmentTask", func(t *testing.T) {
|
|
|
|
releaseTask := &releaseSegmentTask{
|
2021-08-26 14:17:54 +08:00
|
|
|
ReleaseSegmentsRequest: &querypb.ReleaseSegmentsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_ReleaseSegments,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-10-14 20:18:33 +08:00
|
|
|
blobs, err := releaseTask.marshal()
|
2021-08-26 14:17:54 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
err = kv.Save("testMarshalReleaseSegment", string(blobs))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer kv.RemoveWithPrefix("testMarshalReleaseSegment")
|
|
|
|
value, err := kv.Load("testMarshalReleaseSegment")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2021-10-11 09:54:37 +08:00
|
|
|
task, err := taskScheduler.unmarshalTask(1005, value)
|
2021-08-26 14:17:54 +08:00
|
|
|
assert.Nil(t, err)
|
2021-10-14 20:18:33 +08:00
|
|
|
assert.Equal(t, task.msgType(), commonpb.MsgType_ReleaseSegments)
|
2021-08-26 14:17:54 +08:00
|
|
|
})
|
|
|
|
|
2021-10-18 21:34:47 +08:00
|
|
|
t.Run("Test watchDmChannelTask", func(t *testing.T) {
|
|
|
|
watchTask := &watchDmChannelTask{
|
2021-08-26 14:17:54 +08:00
|
|
|
WatchDmChannelsRequest: &querypb.WatchDmChannelsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_WatchDmChannels,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-10-14 20:18:33 +08:00
|
|
|
blobs, err := watchTask.marshal()
|
2021-08-26 14:17:54 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
err = kv.Save("testMarshalWatchDmChannel", string(blobs))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer kv.RemoveWithPrefix("testMarshalWatchDmChannel")
|
|
|
|
value, err := kv.Load("testMarshalWatchDmChannel")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2021-10-11 09:54:37 +08:00
|
|
|
task, err := taskScheduler.unmarshalTask(1006, value)
|
2021-08-26 14:17:54 +08:00
|
|
|
assert.Nil(t, err)
|
2021-10-14 20:18:33 +08:00
|
|
|
assert.Equal(t, task.msgType(), commonpb.MsgType_WatchDmChannels)
|
2021-08-26 14:17:54 +08:00
|
|
|
})
|
|
|
|
|
2021-11-05 14:47:19 +08:00
|
|
|
t.Run("Test watchDeltaChannelTask", func(t *testing.T) {
|
|
|
|
watchTask := &watchDeltaChannelTask{
|
|
|
|
WatchDeltaChannelsRequest: &querypb.WatchDeltaChannelsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_WatchDeltaChannels,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
blobs, err := watchTask.marshal()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
err = kv.Save("testMarshalWatchDeltaChannel", string(blobs))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer kv.RemoveWithPrefix("testMarshalWatchDeltaChannel")
|
|
|
|
value, err := kv.Load("testMarshalWatchDeltaChannel")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
task, err := taskScheduler.unmarshalTask(1007, value)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, task.msgType(), commonpb.MsgType_WatchDeltaChannels)
|
|
|
|
})
|
|
|
|
|
2021-10-18 21:34:47 +08:00
|
|
|
t.Run("Test watchQueryChannelTask", func(t *testing.T) {
|
|
|
|
watchTask := &watchQueryChannelTask{
|
2021-08-26 14:17:54 +08:00
|
|
|
AddQueryChannelRequest: &querypb.AddQueryChannelRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_WatchQueryChannels,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-10-14 20:18:33 +08:00
|
|
|
blobs, err := watchTask.marshal()
|
2021-08-26 14:17:54 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
err = kv.Save("testMarshalWatchQueryChannel", string(blobs))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer kv.RemoveWithPrefix("testMarshalWatchQueryChannel")
|
|
|
|
value, err := kv.Load("testMarshalWatchQueryChannel")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2021-11-05 14:47:19 +08:00
|
|
|
task, err := taskScheduler.unmarshalTask(1008, value)
|
2021-08-26 14:17:54 +08:00
|
|
|
assert.Nil(t, err)
|
2021-10-14 20:18:33 +08:00
|
|
|
assert.Equal(t, task.msgType(), commonpb.MsgType_WatchQueryChannels)
|
2021-08-26 14:17:54 +08:00
|
|
|
})
|
|
|
|
|
2021-10-18 21:34:47 +08:00
|
|
|
t.Run("Test loadBalanceTask", func(t *testing.T) {
|
|
|
|
loadBalanceTask := &loadBalanceTask{
|
2021-08-26 14:17:54 +08:00
|
|
|
LoadBalanceRequest: &querypb.LoadBalanceRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_LoadBalanceSegments,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-10-14 20:18:33 +08:00
|
|
|
blobs, err := loadBalanceTask.marshal()
|
2021-08-26 14:17:54 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
err = kv.Save("testMarshalLoadBalanceTask", string(blobs))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer kv.RemoveWithPrefix("testMarshalLoadBalanceTask")
|
|
|
|
value, err := kv.Load("testMarshalLoadBalanceTask")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2021-11-05 14:47:19 +08:00
|
|
|
task, err := taskScheduler.unmarshalTask(1009, value)
|
2021-08-26 14:17:54 +08:00
|
|
|
assert.Nil(t, err)
|
2021-10-14 20:18:33 +08:00
|
|
|
assert.Equal(t, task.msgType(), commonpb.MsgType_LoadBalanceSegments)
|
2021-08-26 14:17:54 +08:00
|
|
|
})
|
2021-10-11 09:54:37 +08:00
|
|
|
|
2021-10-24 22:39:09 +08:00
|
|
|
t.Run("Test handoffTask", func(t *testing.T) {
|
|
|
|
handoffTask := &handoffTask{
|
|
|
|
HandoffSegmentsRequest: &querypb.HandoffSegmentsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_HandoffSegments,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
blobs, err := handoffTask.marshal()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
err = kv.Save("testMarshalHandoffTask", string(blobs))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
defer kv.RemoveWithPrefix("testMarshalHandoffTask")
|
|
|
|
value, err := kv.Load("testMarshalHandoffTask")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2021-11-05 14:47:19 +08:00
|
|
|
task, err := taskScheduler.unmarshalTask(1010, value)
|
2021-10-24 22:39:09 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, task.msgType(), commonpb.MsgType_HandoffSegments)
|
|
|
|
})
|
|
|
|
|
2021-10-11 09:54:37 +08:00
|
|
|
taskScheduler.Close()
|
2021-08-26 14:17:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestReloadTaskFromKV(t *testing.T) {
|
|
|
|
refreshParams()
|
2021-08-13 11:04:09 +08:00
|
|
|
kv, err := etcdkv.NewEtcdKV(Params.EtcdEndpoints, Params.MetaRootPath)
|
2021-08-03 22:03:25 +08:00
|
|
|
assert.Nil(t, err)
|
2021-10-11 09:54:37 +08:00
|
|
|
baseCtx, cancel := context.WithCancel(context.Background())
|
2021-08-26 14:17:54 +08:00
|
|
|
taskScheduler := &TaskScheduler{
|
2021-10-11 09:54:37 +08:00
|
|
|
ctx: baseCtx,
|
|
|
|
cancel: cancel,
|
2021-08-26 14:17:54 +08:00
|
|
|
client: kv,
|
|
|
|
triggerTaskQueue: NewTaskQueue(),
|
|
|
|
}
|
2021-08-03 22:03:25 +08:00
|
|
|
|
2021-08-26 14:17:54 +08:00
|
|
|
kvs := make(map[string]string)
|
2021-10-18 21:34:47 +08:00
|
|
|
triggerTask := &loadCollectionTask{
|
2021-08-03 22:03:25 +08:00
|
|
|
LoadCollectionRequest: &querypb.LoadCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
2021-08-26 14:17:54 +08:00
|
|
|
Timestamp: 1,
|
|
|
|
MsgType: commonpb.MsgType_LoadCollection,
|
2021-08-03 22:03:25 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-10-14 20:18:33 +08:00
|
|
|
triggerBlobs, err := triggerTask.marshal()
|
2021-08-03 22:03:25 +08:00
|
|
|
assert.Nil(t, err)
|
2021-08-26 14:17:54 +08:00
|
|
|
triggerTaskKey := fmt.Sprintf("%s/%d", triggerTaskPrefix, 100)
|
|
|
|
kvs[triggerTaskKey] = string(triggerBlobs)
|
|
|
|
|
2021-10-18 21:34:47 +08:00
|
|
|
activeTask := &loadSegmentTask{
|
2021-08-26 14:17:54 +08:00
|
|
|
LoadSegmentsRequest: &querypb.LoadSegmentsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
Timestamp: 2,
|
|
|
|
MsgType: commonpb.MsgType_LoadSegments,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-10-14 20:18:33 +08:00
|
|
|
activeBlobs, err := activeTask.marshal()
|
2021-08-03 22:03:25 +08:00
|
|
|
assert.Nil(t, err)
|
2021-08-26 14:17:54 +08:00
|
|
|
activeTaskKey := fmt.Sprintf("%s/%d", activeTaskPrefix, 101)
|
|
|
|
kvs[activeTaskKey] = string(activeBlobs)
|
2021-08-03 22:03:25 +08:00
|
|
|
|
2021-08-26 14:17:54 +08:00
|
|
|
stateKey := fmt.Sprintf("%s/%d", taskInfoPrefix, 100)
|
|
|
|
kvs[stateKey] = strconv.Itoa(int(taskDone))
|
|
|
|
err = kv.MultiSave(kvs)
|
2021-08-03 22:03:25 +08:00
|
|
|
assert.Nil(t, err)
|
2021-08-26 14:17:54 +08:00
|
|
|
|
|
|
|
taskScheduler.reloadFromKV()
|
|
|
|
|
2021-10-20 11:12:35 +08:00
|
|
|
task := taskScheduler.triggerTaskQueue.popTask()
|
2021-10-14 20:18:33 +08:00
|
|
|
assert.Equal(t, taskDone, task.getState())
|
|
|
|
assert.Equal(t, 1, len(task.getChildTask()))
|
2021-08-03 22:03:25 +08:00
|
|
|
}
|
2021-10-21 12:18:36 +08:00
|
|
|
|
|
|
|
func Test_saveInternalTaskToEtcd(t *testing.T) {
|
|
|
|
refreshParams()
|
|
|
|
ctx := context.Background()
|
|
|
|
queryCoord, err := startQueryCoord(ctx)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
testTask := &testTask{
|
|
|
|
baseTask: baseTask{
|
|
|
|
ctx: ctx,
|
|
|
|
condition: newTaskCondition(ctx),
|
|
|
|
triggerCondition: querypb.TriggerCondition_grpcRequest,
|
|
|
|
taskID: 100,
|
|
|
|
},
|
|
|
|
baseMsg: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_LoadCollection,
|
|
|
|
},
|
|
|
|
cluster: queryCoord.cluster,
|
|
|
|
meta: queryCoord.meta,
|
|
|
|
nodeID: defaultQueryNodeID,
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("Test SaveEtcdFail", func(t *testing.T) {
|
|
|
|
// max send size limit of etcd is 2097152
|
|
|
|
testTask.binlogSize = 3000000
|
|
|
|
err = queryCoord.scheduler.processTask(testTask)
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test SaveEtcdSuccess", func(t *testing.T) {
|
|
|
|
testTask.childTasks = []task{}
|
|
|
|
testTask.binlogSize = 500000
|
|
|
|
err = queryCoord.scheduler.processTask(testTask)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
})
|
|
|
|
}
|