2022-10-11 11:39:22 +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
|
|
|
|
// 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.
|
|
|
|
|
2022-09-21 14:42:51 +08:00
|
|
|
package task
|
|
|
|
|
|
|
|
import (
|
2023-06-09 01:28:37 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/msgpb"
|
2022-09-21 14:42:51 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MergeableTask[K comparable, R any] interface {
|
|
|
|
ID() K
|
|
|
|
Merge(other MergeableTask[K, R])
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ MergeableTask[segmentIndex, *querypb.LoadSegmentsRequest] = (*LoadSegmentsTask)(nil)
|
|
|
|
|
|
|
|
type segmentIndex struct {
|
|
|
|
NodeID int64
|
|
|
|
CollectionID int64
|
|
|
|
Shard string
|
|
|
|
}
|
|
|
|
|
|
|
|
type LoadSegmentsTask struct {
|
|
|
|
tasks []*SegmentTask
|
|
|
|
steps []int
|
|
|
|
req *querypb.LoadSegmentsRequest
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewLoadSegmentsTask(task *SegmentTask, step int, req *querypb.LoadSegmentsRequest) *LoadSegmentsTask {
|
|
|
|
return &LoadSegmentsTask{
|
|
|
|
tasks: []*SegmentTask{task},
|
|
|
|
steps: []int{step},
|
|
|
|
req: req,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (task *LoadSegmentsTask) ID() segmentIndex {
|
|
|
|
return segmentIndex{
|
|
|
|
NodeID: task.req.GetDstNodeID(),
|
|
|
|
CollectionID: task.req.GetCollectionID(),
|
|
|
|
Shard: task.req.GetInfos()[0].GetInsertChannel(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (task *LoadSegmentsTask) Merge(other MergeableTask[segmentIndex, *querypb.LoadSegmentsRequest]) {
|
|
|
|
otherTask := other.(*LoadSegmentsTask)
|
|
|
|
task.tasks = append(task.tasks, otherTask.tasks...)
|
|
|
|
task.steps = append(task.steps, otherTask.steps...)
|
|
|
|
task.req.Infos = append(task.req.Infos, otherTask.req.GetInfos()...)
|
2023-03-04 23:21:50 +08:00
|
|
|
positions := make(map[string]*msgpb.MsgPosition)
|
2022-09-21 14:42:51 +08:00
|
|
|
for _, position := range task.req.DeltaPositions {
|
2022-09-30 17:20:55 +08:00
|
|
|
positions[position.GetChannelName()] = position
|
2022-09-21 14:42:51 +08:00
|
|
|
}
|
|
|
|
for _, position := range otherTask.req.GetDeltaPositions() {
|
2022-09-30 17:20:55 +08:00
|
|
|
merged, ok := positions[position.GetChannelName()]
|
2022-09-21 14:42:51 +08:00
|
|
|
if !ok || merged.GetTimestamp() > position.GetTimestamp() {
|
|
|
|
merged = position
|
|
|
|
}
|
2022-09-30 17:20:55 +08:00
|
|
|
positions[position.GetChannelName()] = merged
|
2022-09-21 14:42:51 +08:00
|
|
|
}
|
2023-03-04 23:21:50 +08:00
|
|
|
task.req.DeltaPositions = make([]*msgpb.MsgPosition, 0, len(positions))
|
2022-09-30 17:20:55 +08:00
|
|
|
for _, position := range positions {
|
2022-09-21 14:42:51 +08:00
|
|
|
task.req.DeltaPositions = append(task.req.DeltaPositions, position)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (task *LoadSegmentsTask) Result() *querypb.LoadSegmentsRequest {
|
|
|
|
return task.req
|
|
|
|
}
|