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-15 18:48:32 +08:00
|
|
|
package task
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2023-02-26 11:31:49 +08:00
|
|
|
"github.com/cockroachdb/errors"
|
2023-09-21 09:45:27 +08:00
|
|
|
"go.opentelemetry.io/otel"
|
|
|
|
"go.opentelemetry.io/otel/trace"
|
|
|
|
"go.uber.org/atomic"
|
|
|
|
|
2022-09-15 18:48:32 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
|
|
|
"github.com/milvus-io/milvus/internal/querycoordv2/meta"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/merr"
|
2024-01-10 09:58:49 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/typeutil"
|
2022-09-15 18:48:32 +08:00
|
|
|
)
|
|
|
|
|
2023-09-21 09:45:27 +08:00
|
|
|
type (
|
2023-11-10 14:32:20 +08:00
|
|
|
Status = string
|
2023-09-21 09:45:27 +08:00
|
|
|
Priority int32
|
|
|
|
)
|
2022-09-15 18:48:32 +08:00
|
|
|
|
|
|
|
const (
|
2023-11-10 14:32:20 +08:00
|
|
|
TaskStatusCreated = "created"
|
|
|
|
TaskStatusStarted = "started"
|
|
|
|
TaskStatusSucceeded = "succeeded"
|
|
|
|
TaskStatusCanceled = "canceled"
|
|
|
|
TaskStatusFailed = "failed"
|
2022-09-15 18:48:32 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2023-07-24 13:57:00 +08:00
|
|
|
TaskPriorityLow Priority = iota // for balance checker
|
|
|
|
TaskPriorityNormal // for segment checker
|
|
|
|
TaskPriorityHigh // for channel checker
|
2022-09-15 18:48:32 +08:00
|
|
|
)
|
|
|
|
|
2023-07-24 13:57:00 +08:00
|
|
|
var TaskPriorityName = map[Priority]string{
|
|
|
|
TaskPriorityLow: "Low",
|
|
|
|
TaskPriorityNormal: "Normal",
|
2023-10-11 14:19:35 +08:00
|
|
|
TaskPriorityHigh: "High",
|
2023-07-24 13:57:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p Priority) String() string {
|
|
|
|
return TaskPriorityName[p]
|
|
|
|
}
|
|
|
|
|
2023-09-21 09:45:27 +08:00
|
|
|
// All task priorities from low to high
|
|
|
|
var TaskPriorities = []Priority{TaskPriorityLow, TaskPriorityNormal, TaskPriorityHigh}
|
2022-09-15 18:48:32 +08:00
|
|
|
|
2023-10-27 01:08:12 +08:00
|
|
|
type Source fmt.Stringer
|
|
|
|
|
2022-09-15 18:48:32 +08:00
|
|
|
type Task interface {
|
|
|
|
Context() context.Context
|
2023-10-27 01:08:12 +08:00
|
|
|
Source() Source
|
2024-01-10 09:58:49 +08:00
|
|
|
ID() typeutil.UniqueID
|
|
|
|
CollectionID() typeutil.UniqueID
|
2024-03-21 11:59:12 +08:00
|
|
|
// Return 0 if the task is a reduce task without given replica.
|
2024-01-10 09:58:49 +08:00
|
|
|
ReplicaID() typeutil.UniqueID
|
2024-03-21 11:59:12 +08:00
|
|
|
// Return "" if the task is a reduce task without given replica.
|
|
|
|
ResourceGroup() string
|
2024-02-21 11:08:51 +08:00
|
|
|
Shard() string
|
2024-01-10 09:58:49 +08:00
|
|
|
SetID(id typeutil.UniqueID)
|
2022-09-15 18:48:32 +08:00
|
|
|
Status() Status
|
|
|
|
SetStatus(status Status)
|
|
|
|
Err() error
|
|
|
|
Priority() Priority
|
|
|
|
SetPriority(priority Priority)
|
2023-07-26 08:51:02 +08:00
|
|
|
Index() string // dedup indexing string
|
2022-09-15 18:48:32 +08:00
|
|
|
|
2023-08-01 10:11:05 +08:00
|
|
|
// cancel the task as we don't need to continue it
|
2023-03-16 17:43:55 +08:00
|
|
|
Cancel(err error)
|
2023-08-01 10:11:05 +08:00
|
|
|
// fail the task as we encounter some error so be unable to continue,
|
|
|
|
// this error will be recorded for response to user requests
|
|
|
|
Fail(err error)
|
2022-09-15 18:48:32 +08:00
|
|
|
Wait() error
|
|
|
|
Actions() []Action
|
|
|
|
Step() int
|
2022-11-30 13:57:15 +08:00
|
|
|
StepUp() int
|
2022-09-15 18:48:32 +08:00
|
|
|
IsFinished(dist *meta.DistributionManager) bool
|
2023-03-06 10:13:50 +08:00
|
|
|
SetReason(reason string)
|
2022-09-15 18:48:32 +08:00
|
|
|
String() string
|
2024-03-20 19:29:06 +08:00
|
|
|
|
|
|
|
RecordStartTs()
|
|
|
|
GetTaskLatency() int64
|
2022-09-15 18:48:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type baseTask struct {
|
|
|
|
ctx context.Context
|
|
|
|
cancel context.CancelFunc
|
|
|
|
doneCh chan struct{}
|
|
|
|
canceled *atomic.Bool
|
|
|
|
|
2024-01-10 09:58:49 +08:00
|
|
|
id typeutil.UniqueID // Set by scheduler
|
|
|
|
collectionID typeutil.UniqueID
|
2024-03-21 11:59:12 +08:00
|
|
|
replica *meta.Replica
|
2022-09-28 12:10:54 +08:00
|
|
|
shard string
|
2022-09-15 18:48:32 +08:00
|
|
|
loadType querypb.LoadType
|
|
|
|
|
2023-10-27 01:08:12 +08:00
|
|
|
source Source
|
2023-11-10 14:32:20 +08:00
|
|
|
status *atomic.String
|
2022-09-15 18:48:32 +08:00
|
|
|
priority Priority
|
|
|
|
err error
|
|
|
|
actions []Action
|
|
|
|
step int
|
2023-03-06 10:13:50 +08:00
|
|
|
reason string
|
2023-09-14 09:59:19 +08:00
|
|
|
|
|
|
|
// span for tracing
|
|
|
|
span trace.Span
|
2024-03-20 19:29:06 +08:00
|
|
|
|
|
|
|
// startTs
|
|
|
|
startTs time.Time
|
2022-09-15 18:48:32 +08:00
|
|
|
}
|
|
|
|
|
2024-03-21 11:59:12 +08:00
|
|
|
func newBaseTask(ctx context.Context, source Source, collectionID typeutil.UniqueID, replica *meta.Replica, shard string, taskTag string) *baseTask {
|
2022-09-30 19:48:55 +08:00
|
|
|
ctx, cancel := context.WithCancel(ctx)
|
2024-01-10 09:58:49 +08:00
|
|
|
ctx, span := otel.Tracer(typeutil.QueryCoordRole).Start(ctx, taskTag)
|
2022-09-15 18:48:32 +08:00
|
|
|
|
|
|
|
return &baseTask{
|
2023-10-27 01:08:12 +08:00
|
|
|
source: source,
|
2022-09-15 18:48:32 +08:00
|
|
|
collectionID: collectionID,
|
2024-03-21 11:59:12 +08:00
|
|
|
replica: replica,
|
2022-09-28 12:10:54 +08:00
|
|
|
shard: shard,
|
2022-09-15 18:48:32 +08:00
|
|
|
|
2023-11-10 14:32:20 +08:00
|
|
|
status: atomic.NewString(TaskStatusStarted),
|
2022-09-15 18:48:32 +08:00
|
|
|
priority: TaskPriorityNormal,
|
|
|
|
ctx: ctx,
|
|
|
|
cancel: cancel,
|
|
|
|
doneCh: make(chan struct{}),
|
|
|
|
canceled: atomic.NewBool(false),
|
2023-09-14 09:59:19 +08:00
|
|
|
span: span,
|
2024-03-20 19:29:06 +08:00
|
|
|
startTs: time.Now(),
|
2022-09-15 18:48:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (task *baseTask) Context() context.Context {
|
|
|
|
return task.ctx
|
|
|
|
}
|
|
|
|
|
2023-10-27 01:08:12 +08:00
|
|
|
func (task *baseTask) Source() Source {
|
|
|
|
return task.source
|
2022-09-15 18:48:32 +08:00
|
|
|
}
|
|
|
|
|
2024-01-10 09:58:49 +08:00
|
|
|
func (task *baseTask) ID() typeutil.UniqueID {
|
2022-09-15 18:48:32 +08:00
|
|
|
return task.id
|
|
|
|
}
|
|
|
|
|
2024-01-10 09:58:49 +08:00
|
|
|
func (task *baseTask) SetID(id typeutil.UniqueID) {
|
2022-09-15 18:48:32 +08:00
|
|
|
task.id = id
|
|
|
|
}
|
|
|
|
|
2024-01-10 09:58:49 +08:00
|
|
|
func (task *baseTask) CollectionID() typeutil.UniqueID {
|
2022-09-15 18:48:32 +08:00
|
|
|
return task.collectionID
|
|
|
|
}
|
|
|
|
|
2024-01-10 09:58:49 +08:00
|
|
|
func (task *baseTask) ReplicaID() typeutil.UniqueID {
|
2024-03-21 11:59:12 +08:00
|
|
|
// replica may be nil, 0 will be generated.
|
|
|
|
return task.replica.GetID()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (task *baseTask) ResourceGroup() string {
|
|
|
|
// replica may be nil, empty string will be generated.
|
|
|
|
return task.replica.GetResourceGroup()
|
2022-09-15 18:48:32 +08:00
|
|
|
}
|
|
|
|
|
2024-02-21 11:08:51 +08:00
|
|
|
func (task *baseTask) Shard() string {
|
|
|
|
return task.shard
|
|
|
|
}
|
|
|
|
|
2022-09-15 18:48:32 +08:00
|
|
|
func (task *baseTask) LoadType() querypb.LoadType {
|
|
|
|
return task.loadType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (task *baseTask) Status() Status {
|
|
|
|
return task.status.Load()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (task *baseTask) SetStatus(status Status) {
|
|
|
|
task.status.Store(status)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (task *baseTask) Priority() Priority {
|
|
|
|
return task.priority
|
|
|
|
}
|
|
|
|
|
|
|
|
func (task *baseTask) SetPriority(priority Priority) {
|
|
|
|
task.priority = priority
|
|
|
|
}
|
|
|
|
|
2023-07-26 08:51:02 +08:00
|
|
|
func (task *baseTask) Index() string {
|
2024-03-21 11:59:12 +08:00
|
|
|
return fmt.Sprintf("[replica=%d]", task.ReplicaID())
|
2023-07-26 08:51:02 +08:00
|
|
|
}
|
|
|
|
|
2024-03-20 19:29:06 +08:00
|
|
|
func (task *baseTask) RecordStartTs() {
|
|
|
|
task.startTs = time.Now()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (task *baseTask) GetTaskLatency() int64 {
|
|
|
|
return time.Since(task.startTs).Milliseconds()
|
|
|
|
}
|
|
|
|
|
2022-09-15 18:48:32 +08:00
|
|
|
func (task *baseTask) Err() error {
|
2023-03-16 17:43:55 +08:00
|
|
|
select {
|
|
|
|
case <-task.doneCh:
|
|
|
|
return task.err
|
|
|
|
default:
|
|
|
|
return nil
|
|
|
|
}
|
2022-09-15 18:48:32 +08:00
|
|
|
}
|
|
|
|
|
2023-03-16 17:43:55 +08:00
|
|
|
func (task *baseTask) Cancel(err error) {
|
|
|
|
if task.canceled.CompareAndSwap(false, true) {
|
2022-09-15 18:48:32 +08:00
|
|
|
task.cancel()
|
2023-03-16 17:43:55 +08:00
|
|
|
if task.Status() != TaskStatusSucceeded {
|
|
|
|
task.SetStatus(TaskStatusCanceled)
|
|
|
|
}
|
|
|
|
task.err = err
|
2022-09-15 18:48:32 +08:00
|
|
|
close(task.doneCh)
|
2023-09-14 09:59:19 +08:00
|
|
|
if task.span != nil {
|
|
|
|
task.span.End()
|
|
|
|
}
|
2022-09-15 18:48:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-01 10:11:05 +08:00
|
|
|
func (task *baseTask) Fail(err error) {
|
|
|
|
if task.canceled.CompareAndSwap(false, true) {
|
|
|
|
task.cancel()
|
|
|
|
if task.Status() != TaskStatusSucceeded {
|
|
|
|
task.SetStatus(TaskStatusFailed)
|
|
|
|
}
|
|
|
|
task.err = err
|
|
|
|
close(task.doneCh)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-15 18:48:32 +08:00
|
|
|
func (task *baseTask) Wait() error {
|
|
|
|
<-task.doneCh
|
|
|
|
return task.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (task *baseTask) Actions() []Action {
|
|
|
|
return task.actions
|
|
|
|
}
|
|
|
|
|
|
|
|
func (task *baseTask) Step() int {
|
|
|
|
return task.step
|
|
|
|
}
|
|
|
|
|
2022-11-30 13:57:15 +08:00
|
|
|
func (task *baseTask) StepUp() int {
|
|
|
|
task.step++
|
|
|
|
return task.step
|
|
|
|
}
|
|
|
|
|
2022-09-15 18:48:32 +08:00
|
|
|
func (task *baseTask) IsFinished(distMgr *meta.DistributionManager) bool {
|
|
|
|
if task.Status() != TaskStatusStarted {
|
|
|
|
return false
|
|
|
|
}
|
2022-11-30 13:57:15 +08:00
|
|
|
return task.Step() >= len(task.Actions())
|
2022-09-15 18:48:32 +08:00
|
|
|
}
|
|
|
|
|
2023-03-06 10:13:50 +08:00
|
|
|
func (task *baseTask) SetReason(reason string) {
|
|
|
|
task.reason = reason
|
|
|
|
}
|
|
|
|
|
2022-09-15 18:48:32 +08:00
|
|
|
func (task *baseTask) String() string {
|
|
|
|
var actionsStr string
|
2024-06-24 10:16:02 +08:00
|
|
|
for _, action := range task.actions {
|
|
|
|
actionsStr += action.String() + ","
|
2022-09-15 18:48:32 +08:00
|
|
|
}
|
|
|
|
return fmt.Sprintf(
|
2024-03-21 11:59:12 +08:00
|
|
|
"[id=%d] [type=%s] [source=%s] [reason=%s] [collectionID=%d] [replicaID=%d] [resourceGroup=%s] [priority=%s] [actionsCount=%d] [actions=%s]",
|
2022-09-15 18:48:32 +08:00
|
|
|
task.id,
|
2023-07-24 13:57:00 +08:00
|
|
|
GetTaskType(task).String(),
|
2023-10-27 01:08:12 +08:00
|
|
|
task.source.String(),
|
2023-03-06 10:13:50 +08:00
|
|
|
task.reason,
|
2022-09-15 18:48:32 +08:00
|
|
|
task.collectionID,
|
2024-03-21 11:59:12 +08:00
|
|
|
task.ReplicaID(),
|
|
|
|
task.ResourceGroup(),
|
2023-07-24 13:57:00 +08:00
|
|
|
task.priority.String(),
|
2022-09-15 18:48:32 +08:00
|
|
|
len(task.actions),
|
|
|
|
actionsStr,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
type SegmentTask struct {
|
|
|
|
*baseTask
|
|
|
|
|
2024-01-10 09:58:49 +08:00
|
|
|
segmentID typeutil.UniqueID
|
2022-09-15 18:48:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewSegmentTask creates a SegmentTask with actions,
|
|
|
|
// all actions must process the same segment,
|
|
|
|
// empty actions is not allowed
|
|
|
|
func NewSegmentTask(ctx context.Context,
|
|
|
|
timeout time.Duration,
|
2023-10-27 01:08:12 +08:00
|
|
|
source Source,
|
2024-03-21 11:59:12 +08:00
|
|
|
collectionID typeutil.UniqueID,
|
|
|
|
replica *meta.Replica,
|
2023-09-21 09:45:27 +08:00
|
|
|
actions ...Action,
|
|
|
|
) (*SegmentTask, error) {
|
2022-09-15 18:48:32 +08:00
|
|
|
if len(actions) == 0 {
|
2023-03-14 18:51:53 +08:00
|
|
|
return nil, errors.WithStack(merr.WrapErrParameterInvalid("non-empty actions", "no action"))
|
2022-09-15 18:48:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
segmentID := int64(-1)
|
2022-09-28 12:10:54 +08:00
|
|
|
shard := ""
|
2022-09-15 18:48:32 +08:00
|
|
|
for _, action := range actions {
|
|
|
|
action, ok := action.(*SegmentAction)
|
|
|
|
if !ok {
|
2023-03-14 18:51:53 +08:00
|
|
|
return nil, errors.WithStack(merr.WrapErrParameterInvalid("SegmentAction", "other action", "all actions must be with the same type"))
|
2022-09-15 18:48:32 +08:00
|
|
|
}
|
|
|
|
if segmentID == -1 {
|
2022-09-28 12:10:54 +08:00
|
|
|
segmentID = action.SegmentID()
|
|
|
|
shard = action.Shard()
|
2022-09-15 18:48:32 +08:00
|
|
|
} else if segmentID != action.SegmentID() {
|
2023-03-14 18:51:53 +08:00
|
|
|
return nil, errors.WithStack(merr.WrapErrParameterInvalid(segmentID, action.SegmentID(), "all actions must operate the same segment"))
|
2022-09-15 18:48:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-21 11:59:12 +08:00
|
|
|
base := newBaseTask(ctx, source, collectionID, replica, shard, fmt.Sprintf("SegmentTask-%s-%d", actions[0].Type().String(), segmentID))
|
2022-09-15 18:48:32 +08:00
|
|
|
base.actions = actions
|
|
|
|
return &SegmentTask{
|
2022-09-28 12:10:54 +08:00
|
|
|
baseTask: base,
|
2022-09-15 18:48:32 +08:00
|
|
|
segmentID: segmentID,
|
2022-10-28 17:15:32 +08:00
|
|
|
}, nil
|
2022-09-15 18:48:32 +08:00
|
|
|
}
|
|
|
|
|
2024-01-10 09:58:49 +08:00
|
|
|
func (task *SegmentTask) SegmentID() typeutil.UniqueID {
|
2022-09-15 18:48:32 +08:00
|
|
|
return task.segmentID
|
|
|
|
}
|
|
|
|
|
2023-07-26 08:51:02 +08:00
|
|
|
func (task *SegmentTask) Index() string {
|
|
|
|
return fmt.Sprintf("%s[segment=%d][growing=%t]", task.baseTask.Index(), task.segmentID, task.Actions()[0].(*SegmentAction).Scope() == querypb.DataScope_Streaming)
|
|
|
|
}
|
|
|
|
|
2022-09-15 18:48:32 +08:00
|
|
|
func (task *SegmentTask) String() string {
|
|
|
|
return fmt.Sprintf("%s [segmentID=%d]", task.baseTask.String(), task.segmentID)
|
|
|
|
}
|
|
|
|
|
|
|
|
type ChannelTask struct {
|
|
|
|
*baseTask
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewChannelTask creates a ChannelTask with actions,
|
|
|
|
// all actions must process the same channel, and the same type of channel
|
|
|
|
// empty actions is not allowed
|
|
|
|
func NewChannelTask(ctx context.Context,
|
|
|
|
timeout time.Duration,
|
2023-10-27 01:08:12 +08:00
|
|
|
source Source,
|
2024-03-21 11:59:12 +08:00
|
|
|
collectionID typeutil.UniqueID,
|
|
|
|
replica *meta.Replica,
|
2023-09-21 09:45:27 +08:00
|
|
|
actions ...Action,
|
|
|
|
) (*ChannelTask, error) {
|
2022-09-15 18:48:32 +08:00
|
|
|
if len(actions) == 0 {
|
2023-03-14 18:51:53 +08:00
|
|
|
return nil, errors.WithStack(merr.WrapErrParameterInvalid("non-empty actions", "no action"))
|
2022-09-15 18:48:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
channel := ""
|
|
|
|
for _, action := range actions {
|
2023-03-14 18:51:53 +08:00
|
|
|
channelAction, ok := action.(*ChannelAction)
|
2022-09-15 18:48:32 +08:00
|
|
|
if !ok {
|
2023-03-14 18:51:53 +08:00
|
|
|
return nil, errors.WithStack(merr.WrapErrParameterInvalid("ChannelAction", "other action", "all actions must be with the same type"))
|
2022-09-15 18:48:32 +08:00
|
|
|
}
|
|
|
|
if channel == "" {
|
|
|
|
channel = channelAction.ChannelName()
|
|
|
|
} else if channel != channelAction.ChannelName() {
|
2023-03-14 18:51:53 +08:00
|
|
|
return nil, errors.WithStack(merr.WrapErrParameterInvalid(channel, channelAction.ChannelName(), "all actions must operate the same segment"))
|
2022-09-15 18:48:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-21 11:59:12 +08:00
|
|
|
base := newBaseTask(ctx, source, collectionID, replica, channel, fmt.Sprintf("ChannelTask-%s-%s", actions[0].Type().String(), channel))
|
2022-09-15 18:48:32 +08:00
|
|
|
base.actions = actions
|
|
|
|
return &ChannelTask{
|
|
|
|
baseTask: base,
|
2022-10-28 17:15:32 +08:00
|
|
|
}, nil
|
2022-09-15 18:48:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (task *ChannelTask) Channel() string {
|
2022-09-28 12:10:54 +08:00
|
|
|
return task.shard
|
2022-09-15 18:48:32 +08:00
|
|
|
}
|
|
|
|
|
2023-07-26 08:51:02 +08:00
|
|
|
func (task *ChannelTask) Index() string {
|
|
|
|
return fmt.Sprintf("%s[channel=%s]", task.baseTask.Index(), task.shard)
|
|
|
|
}
|
|
|
|
|
2022-09-15 18:48:32 +08:00
|
|
|
func (task *ChannelTask) String() string {
|
2022-09-28 12:10:54 +08:00
|
|
|
return fmt.Sprintf("%s [channel=%s]", task.baseTask.String(), task.Channel())
|
2022-09-15 18:48:32 +08:00
|
|
|
}
|
2024-02-21 11:08:51 +08:00
|
|
|
|
|
|
|
type LeaderTask struct {
|
|
|
|
*baseTask
|
|
|
|
|
|
|
|
segmentID typeutil.UniqueID
|
|
|
|
leaderID int64
|
|
|
|
}
|
|
|
|
|
2024-06-10 21:34:08 +08:00
|
|
|
func NewLeaderSegmentTask(ctx context.Context,
|
2024-02-21 11:08:51 +08:00
|
|
|
source Source,
|
2024-03-21 11:59:12 +08:00
|
|
|
collectionID typeutil.UniqueID,
|
|
|
|
replica *meta.Replica,
|
2024-02-21 11:08:51 +08:00
|
|
|
leaderID int64,
|
|
|
|
action *LeaderAction,
|
|
|
|
) *LeaderTask {
|
|
|
|
segmentID := action.SegmentID()
|
2024-06-10 21:34:08 +08:00
|
|
|
base := newBaseTask(ctx, source, collectionID, replica, action.Shard(), fmt.Sprintf("LeaderSegmentTask-%s-%d", action.Type().String(), segmentID))
|
2024-02-21 11:08:51 +08:00
|
|
|
base.actions = []Action{action}
|
|
|
|
return &LeaderTask{
|
|
|
|
baseTask: base,
|
|
|
|
segmentID: segmentID,
|
|
|
|
leaderID: leaderID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-10 21:34:08 +08:00
|
|
|
func NewLeaderPartStatsTask(ctx context.Context,
|
|
|
|
source Source,
|
|
|
|
collectionID typeutil.UniqueID,
|
|
|
|
replica *meta.Replica,
|
|
|
|
leaderID int64,
|
|
|
|
action *LeaderAction,
|
|
|
|
) *LeaderTask {
|
|
|
|
base := newBaseTask(ctx, source, collectionID, replica, action.Shard(), fmt.Sprintf("LeaderPartitionStatsTask-%s", action.Type().String()))
|
|
|
|
base.actions = []Action{action}
|
|
|
|
return &LeaderTask{
|
|
|
|
baseTask: base,
|
|
|
|
leaderID: leaderID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-21 11:08:51 +08:00
|
|
|
func (task *LeaderTask) SegmentID() typeutil.UniqueID {
|
|
|
|
return task.segmentID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (task *LeaderTask) Index() string {
|
|
|
|
return fmt.Sprintf("%s[segment=%d][growing=false]", task.baseTask.Index(), task.segmentID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (task *LeaderTask) String() string {
|
|
|
|
return fmt.Sprintf("%s [segmentID=%d][leader=%d]", task.baseTask.String(), task.segmentID, task.leaderID)
|
|
|
|
}
|