2023-02-22 11:37:45 +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-05 13:29:11 +08:00
|
|
|
package rootcoord
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-09-21 15:46:51 +08:00
|
|
|
"fmt"
|
2023-01-12 09:55:42 +08:00
|
|
|
"time"
|
2022-09-05 13:29:11 +08:00
|
|
|
|
2023-06-09 01:28:37 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
|
2022-09-05 13:29:11 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/metastore/model"
|
2023-06-25 17:20:43 +08:00
|
|
|
pb "github.com/milvus-io/milvus/internal/proto/etcdpb"
|
2023-12-20 19:22:42 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/proxyutil"
|
2022-09-05 13:29:11 +08:00
|
|
|
)
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
type stepPriority int
|
|
|
|
|
|
|
|
const (
|
2023-01-12 09:55:42 +08:00
|
|
|
stepPriorityLow = 0
|
|
|
|
stepPriorityNormal = 1
|
|
|
|
stepPriorityImportant = 10
|
|
|
|
stepPriorityUrgent = 1000
|
2022-09-21 15:46:51 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type nestedStep interface {
|
|
|
|
Execute(ctx context.Context) ([]nestedStep, error)
|
|
|
|
Desc() string
|
|
|
|
Weight() stepPriority
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type baseStep struct {
|
|
|
|
core *Core
|
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
func (s baseStep) Desc() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s baseStep) Weight() stepPriority {
|
|
|
|
return stepPriorityLow
|
|
|
|
}
|
|
|
|
|
|
|
|
type addCollectionMetaStep struct {
|
2022-09-05 13:29:11 +08:00
|
|
|
baseStep
|
|
|
|
coll *model.Collection
|
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
func (s *addCollectionMetaStep) Execute(ctx context.Context) ([]nestedStep, error) {
|
|
|
|
err := s.core.meta.AddCollection(ctx, s.coll)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *addCollectionMetaStep) Desc() string {
|
|
|
|
return fmt.Sprintf("add collection to meta table, name: %s, id: %d, ts: %d", s.coll.Name, s.coll.CollectionID, s.coll.CreateTime)
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
type deleteCollectionMetaStep struct {
|
2022-09-05 13:29:11 +08:00
|
|
|
baseStep
|
|
|
|
collectionID UniqueID
|
|
|
|
ts Timestamp
|
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
func (s *deleteCollectionMetaStep) Execute(ctx context.Context) ([]nestedStep, error) {
|
|
|
|
err := s.core.meta.RemoveCollection(ctx, s.collectionID, s.ts)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *deleteCollectionMetaStep) Desc() string {
|
|
|
|
return fmt.Sprintf("delete collection from meta table, id: %d, ts: %d", s.collectionID, s.ts)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *deleteCollectionMetaStep) Weight() stepPriority {
|
|
|
|
return stepPriorityNormal
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
type removeDmlChannelsStep struct {
|
2022-09-05 13:29:11 +08:00
|
|
|
baseStep
|
2022-09-21 15:46:51 +08:00
|
|
|
pChannels []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *removeDmlChannelsStep) Execute(ctx context.Context) ([]nestedStep, error) {
|
|
|
|
s.core.chanTimeTick.removeDmlChannels(s.pChannels...)
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *removeDmlChannelsStep) Desc() string {
|
|
|
|
// this shouldn't be called.
|
|
|
|
return fmt.Sprintf("remove dml channels: %v", s.pChannels)
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
func (s *removeDmlChannelsStep) Weight() stepPriority {
|
|
|
|
// avoid too frequent tt.
|
|
|
|
return stepPriorityUrgent
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
type watchChannelsStep struct {
|
2022-09-05 13:29:11 +08:00
|
|
|
baseStep
|
|
|
|
info *watchInfo
|
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
func (s *watchChannelsStep) Execute(ctx context.Context) ([]nestedStep, error) {
|
|
|
|
err := s.core.broker.WatchChannels(ctx, s.info)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *watchChannelsStep) Desc() string {
|
|
|
|
return fmt.Sprintf("watch channels, ts: %d, collection: %d, partition: %d, vChannels: %v",
|
|
|
|
s.info.ts, s.info.collectionID, s.info.partitionID, s.info.vChannels)
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
type unwatchChannelsStep struct {
|
2022-09-05 13:29:11 +08:00
|
|
|
baseStep
|
|
|
|
collectionID UniqueID
|
|
|
|
channels collectionChannels
|
2023-10-20 14:26:09 +08:00
|
|
|
|
|
|
|
isSkip bool
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
func (s *unwatchChannelsStep) Execute(ctx context.Context) ([]nestedStep, error) {
|
2022-09-23 16:56:50 +08:00
|
|
|
unwatchByDropMsg := &deleteCollectionDataStep{
|
|
|
|
baseStep: baseStep{core: s.core},
|
|
|
|
coll: &model.Collection{CollectionID: s.collectionID, PhysicalChannelNames: s.channels.physicalChannels},
|
2023-10-20 14:26:09 +08:00
|
|
|
isSkip: s.isSkip,
|
2022-09-23 16:56:50 +08:00
|
|
|
}
|
|
|
|
return unwatchByDropMsg.Execute(ctx)
|
2022-09-21 15:46:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *unwatchChannelsStep) Desc() string {
|
|
|
|
return fmt.Sprintf("unwatch channels, collection: %d, pChannels: %v, vChannels: %v",
|
|
|
|
s.collectionID, s.channels.physicalChannels, s.channels.virtualChannels)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *unwatchChannelsStep) Weight() stepPriority {
|
|
|
|
return stepPriorityNormal
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
type changeCollectionStateStep struct {
|
2022-09-05 13:29:11 +08:00
|
|
|
baseStep
|
|
|
|
collectionID UniqueID
|
|
|
|
state pb.CollectionState
|
|
|
|
ts Timestamp
|
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
func (s *changeCollectionStateStep) Execute(ctx context.Context) ([]nestedStep, error) {
|
|
|
|
err := s.core.meta.ChangeCollectionState(ctx, s.collectionID, s.state, s.ts)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *changeCollectionStateStep) Desc() string {
|
|
|
|
return fmt.Sprintf("change collection state, collection: %d, ts: %d, state: %s",
|
|
|
|
s.collectionID, s.ts, s.state.String())
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
type expireCacheStep struct {
|
2022-09-05 13:29:11 +08:00
|
|
|
baseStep
|
2023-06-25 17:20:43 +08:00
|
|
|
dbName string
|
2022-09-05 13:29:11 +08:00
|
|
|
collectionNames []string
|
|
|
|
collectionID UniqueID
|
2024-01-30 16:45:02 +08:00
|
|
|
partitionName string
|
2022-09-05 13:29:11 +08:00
|
|
|
ts Timestamp
|
2023-12-20 19:22:42 +08:00
|
|
|
opts []proxyutil.ExpireCacheOpt
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
func (s *expireCacheStep) Execute(ctx context.Context) ([]nestedStep, error) {
|
2024-01-30 16:45:02 +08:00
|
|
|
err := s.core.ExpireMetaCache(ctx, s.dbName, s.collectionNames, s.collectionID, s.partitionName, s.ts, s.opts...)
|
2022-09-21 15:46:51 +08:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *expireCacheStep) Desc() string {
|
|
|
|
return fmt.Sprintf("expire cache, collection id: %d, collection names: %s, ts: %d",
|
|
|
|
s.collectionID, s.collectionNames, s.ts)
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
type deleteCollectionDataStep struct {
|
2022-09-05 13:29:11 +08:00
|
|
|
baseStep
|
|
|
|
coll *model.Collection
|
2023-10-20 14:26:09 +08:00
|
|
|
|
|
|
|
isSkip bool
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
func (s *deleteCollectionDataStep) Execute(ctx context.Context) ([]nestedStep, error) {
|
2023-10-20 14:26:09 +08:00
|
|
|
if s.isSkip {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2022-09-21 15:46:51 +08:00
|
|
|
ddlTs, err := s.core.garbageCollector.GcCollectionData(ctx, s.coll)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
// wait for ts synced.
|
|
|
|
children := make([]nestedStep, 0, len(s.coll.PhysicalChannelNames))
|
|
|
|
for _, channel := range s.coll.PhysicalChannelNames {
|
|
|
|
children = append(children, &waitForTsSyncedStep{
|
|
|
|
baseStep: baseStep{core: s.core},
|
|
|
|
ts: ddlTs,
|
|
|
|
channel: channel,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return children, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *deleteCollectionDataStep) Desc() string {
|
|
|
|
return fmt.Sprintf("delete collection data, collection: %d", s.coll.CollectionID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *deleteCollectionDataStep) Weight() stepPriority {
|
|
|
|
return stepPriorityImportant
|
|
|
|
}
|
|
|
|
|
|
|
|
// waitForTsSyncedStep child step of deleteCollectionDataStep.
|
|
|
|
type waitForTsSyncedStep struct {
|
|
|
|
baseStep
|
|
|
|
ts Timestamp
|
|
|
|
channel string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *waitForTsSyncedStep) Execute(ctx context.Context) ([]nestedStep, error) {
|
|
|
|
syncedTs := s.core.chanTimeTick.getSyncedTimeTick(s.channel)
|
|
|
|
if syncedTs < s.ts {
|
2022-09-22 17:36:52 +08:00
|
|
|
// TODO: there may be frequent log here.
|
|
|
|
// time.Sleep(Params.ProxyCfg.TimeTickInterval)
|
2022-09-21 15:46:51 +08:00
|
|
|
return nil, fmt.Errorf("ts not synced yet, channel: %s, synced: %d, want: %d", s.channel, syncedTs, s.ts)
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *waitForTsSyncedStep) Desc() string {
|
|
|
|
return fmt.Sprintf("wait for ts synced, channel: %s, want: %d", s.channel, s.ts)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *waitForTsSyncedStep) Weight() stepPriority {
|
|
|
|
return stepPriorityNormal
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
type deletePartitionDataStep struct {
|
2022-09-05 13:29:11 +08:00
|
|
|
baseStep
|
|
|
|
pchans []string
|
|
|
|
partition *model.Partition
|
2023-10-20 14:26:09 +08:00
|
|
|
|
|
|
|
isSkip bool
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
func (s *deletePartitionDataStep) Execute(ctx context.Context) ([]nestedStep, error) {
|
2023-10-20 14:26:09 +08:00
|
|
|
if s.isSkip {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2022-09-21 15:46:51 +08:00
|
|
|
_, err := s.core.garbageCollector.GcPartitionData(ctx, s.pchans, s.partition)
|
|
|
|
return nil, err
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
func (s *deletePartitionDataStep) Desc() string {
|
|
|
|
return fmt.Sprintf("delete partition data, collection: %d, partition: %d", s.partition.CollectionID, s.partition.PartitionID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *deletePartitionDataStep) Weight() stepPriority {
|
|
|
|
return stepPriorityImportant
|
|
|
|
}
|
|
|
|
|
|
|
|
type releaseCollectionStep struct {
|
2022-09-05 13:29:11 +08:00
|
|
|
baseStep
|
|
|
|
collectionID UniqueID
|
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
func (s *releaseCollectionStep) Execute(ctx context.Context) ([]nestedStep, error) {
|
|
|
|
err := s.core.broker.ReleaseCollection(ctx, s.collectionID)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *releaseCollectionStep) Desc() string {
|
|
|
|
return fmt.Sprintf("release collection: %d", s.collectionID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *releaseCollectionStep) Weight() stepPriority {
|
|
|
|
return stepPriorityUrgent
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
|
|
|
|
2023-03-20 14:55:57 +08:00
|
|
|
type releasePartitionsStep struct {
|
|
|
|
baseStep
|
|
|
|
collectionID UniqueID
|
|
|
|
partitionIDs []UniqueID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *releasePartitionsStep) Execute(ctx context.Context) ([]nestedStep, error) {
|
|
|
|
err := s.core.broker.ReleasePartitions(ctx, s.collectionID, s.partitionIDs...)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *releasePartitionsStep) Desc() string {
|
|
|
|
return fmt.Sprintf("release partitions, collectionID=%d, partitionIDs=%v", s.collectionID, s.partitionIDs)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *releasePartitionsStep) Weight() stepPriority {
|
|
|
|
return stepPriorityUrgent
|
|
|
|
}
|
|
|
|
|
|
|
|
type syncNewCreatedPartitionStep struct {
|
|
|
|
baseStep
|
|
|
|
collectionID UniqueID
|
|
|
|
partitionID UniqueID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *syncNewCreatedPartitionStep) Execute(ctx context.Context) ([]nestedStep, error) {
|
|
|
|
err := s.core.broker.SyncNewCreatedPartition(ctx, s.collectionID, s.partitionID)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *syncNewCreatedPartitionStep) Desc() string {
|
|
|
|
return fmt.Sprintf("sync new partition, collectionID=%d, partitionID=%d", s.partitionID, s.partitionID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *syncNewCreatedPartitionStep) Weight() stepPriority {
|
|
|
|
return stepPriorityUrgent
|
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
type dropIndexStep struct {
|
2022-09-05 13:29:11 +08:00
|
|
|
baseStep
|
2022-09-23 09:36:51 +08:00
|
|
|
collID UniqueID
|
|
|
|
partIDs []UniqueID
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
func (s *dropIndexStep) Execute(ctx context.Context) ([]nestedStep, error) {
|
2022-09-23 09:36:51 +08:00
|
|
|
err := s.core.broker.DropCollectionIndex(ctx, s.collID, s.partIDs)
|
2022-09-21 15:46:51 +08:00
|
|
|
return nil, err
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
func (s *dropIndexStep) Desc() string {
|
|
|
|
return fmt.Sprintf("drop collection index: %d", s.collID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *dropIndexStep) Weight() stepPriority {
|
|
|
|
return stepPriorityNormal
|
|
|
|
}
|
|
|
|
|
|
|
|
type addPartitionMetaStep struct {
|
2022-09-05 13:29:11 +08:00
|
|
|
baseStep
|
|
|
|
partition *model.Partition
|
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
func (s *addPartitionMetaStep) Execute(ctx context.Context) ([]nestedStep, error) {
|
|
|
|
err := s.core.meta.AddPartition(ctx, s.partition)
|
|
|
|
return nil, err
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
func (s *addPartitionMetaStep) Desc() string {
|
|
|
|
return fmt.Sprintf("add partition to meta table, collection: %d, partition: %d", s.partition.CollectionID, s.partition.PartitionID)
|
|
|
|
}
|
|
|
|
|
|
|
|
type changePartitionStateStep struct {
|
2022-09-05 13:29:11 +08:00
|
|
|
baseStep
|
|
|
|
collectionID UniqueID
|
|
|
|
partitionID UniqueID
|
|
|
|
state pb.PartitionState
|
|
|
|
ts Timestamp
|
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
func (s *changePartitionStateStep) Execute(ctx context.Context) ([]nestedStep, error) {
|
|
|
|
err := s.core.meta.ChangePartitionState(ctx, s.collectionID, s.partitionID, s.state, s.ts)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *changePartitionStateStep) Desc() string {
|
|
|
|
return fmt.Sprintf("change partition step, collection: %d, partition: %d, state: %s, ts: %d",
|
|
|
|
s.collectionID, s.partitionID, s.state.String(), s.ts)
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
type removePartitionMetaStep struct {
|
2022-09-05 13:29:11 +08:00
|
|
|
baseStep
|
2023-06-25 17:20:43 +08:00
|
|
|
dbID UniqueID
|
2022-09-05 13:29:11 +08:00
|
|
|
collectionID UniqueID
|
|
|
|
partitionID UniqueID
|
|
|
|
ts Timestamp
|
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
func (s *removePartitionMetaStep) Execute(ctx context.Context) ([]nestedStep, error) {
|
2023-06-25 17:20:43 +08:00
|
|
|
err := s.core.meta.RemovePartition(ctx, s.dbID, s.collectionID, s.partitionID, s.ts)
|
2022-09-21 15:46:51 +08:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *removePartitionMetaStep) Desc() string {
|
|
|
|
return fmt.Sprintf("remove partition meta, collection: %d, partition: %d, ts: %d", s.collectionID, s.partitionID, s.ts)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *removePartitionMetaStep) Weight() stepPriority {
|
|
|
|
return stepPriorityNormal
|
|
|
|
}
|
|
|
|
|
2023-09-21 09:45:27 +08:00
|
|
|
type nullStep struct{}
|
2022-09-21 15:46:51 +08:00
|
|
|
|
|
|
|
func (s *nullStep) Execute(ctx context.Context) ([]nestedStep, error) {
|
|
|
|
return nil, nil
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
func (s *nullStep) Desc() string {
|
|
|
|
return ""
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
|
|
|
|
2022-09-21 15:46:51 +08:00
|
|
|
func (s *nullStep) Weight() stepPriority {
|
|
|
|
return stepPriorityLow
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
2022-10-10 20:31:22 +08:00
|
|
|
|
|
|
|
type AlterCollectionStep struct {
|
|
|
|
baseStep
|
|
|
|
oldColl *model.Collection
|
|
|
|
newColl *model.Collection
|
|
|
|
ts Timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AlterCollectionStep) Execute(ctx context.Context) ([]nestedStep, error) {
|
|
|
|
err := a.core.meta.AlterCollection(ctx, a.oldColl, a.newColl, a.ts)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AlterCollectionStep) Desc() string {
|
|
|
|
return fmt.Sprintf("alter collection, collectionID: %d, ts: %d", a.oldColl.CollectionID, a.ts)
|
|
|
|
}
|
|
|
|
|
|
|
|
type BroadcastAlteredCollectionStep struct {
|
|
|
|
baseStep
|
|
|
|
req *milvuspb.AlterCollectionRequest
|
|
|
|
core *Core
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *BroadcastAlteredCollectionStep) Execute(ctx context.Context) ([]nestedStep, error) {
|
|
|
|
// TODO: support online schema change mechanism
|
|
|
|
// It only broadcast collection properties to DataCoord service
|
2022-10-11 21:07:23 +08:00
|
|
|
err := b.core.broker.BroadcastAlteredCollection(ctx, b.req)
|
2022-10-10 20:31:22 +08:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *BroadcastAlteredCollectionStep) Desc() string {
|
|
|
|
return fmt.Sprintf("broadcast altered collection, collectionID: %d", b.req.CollectionID)
|
|
|
|
}
|
2023-01-12 09:55:42 +08:00
|
|
|
|
|
|
|
var (
|
|
|
|
confirmGCInterval = time.Minute * 20
|
|
|
|
allPartition UniqueID = -1
|
|
|
|
)
|
|
|
|
|
|
|
|
type confirmGCStep struct {
|
|
|
|
baseStep
|
|
|
|
collectionID UniqueID
|
|
|
|
partitionID UniqueID
|
|
|
|
lastScheduledTime time.Time
|
|
|
|
}
|
|
|
|
|
|
|
|
func newConfirmGCStep(core *Core, collectionID, partitionID UniqueID) *confirmGCStep {
|
|
|
|
return &confirmGCStep{
|
|
|
|
baseStep: baseStep{core: core},
|
|
|
|
collectionID: collectionID,
|
|
|
|
partitionID: partitionID,
|
|
|
|
lastScheduledTime: time.Now(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *confirmGCStep) Execute(ctx context.Context) ([]nestedStep, error) {
|
|
|
|
if time.Since(b.lastScheduledTime) < confirmGCInterval {
|
|
|
|
return nil, fmt.Errorf("wait for reschedule to confirm GC, collection: %d, partition: %d, last scheduled time: %s, now: %s",
|
|
|
|
b.collectionID, b.partitionID, b.lastScheduledTime.String(), time.Now().String())
|
|
|
|
}
|
|
|
|
|
|
|
|
finished := b.core.broker.GcConfirm(ctx, b.collectionID, b.partitionID)
|
|
|
|
if finished {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
b.lastScheduledTime = time.Now()
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("GC is not finished, collection: %d, partition: %d, last scheduled time: %s, now: %s",
|
|
|
|
b.collectionID, b.partitionID, b.lastScheduledTime.String(), time.Now().String())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *confirmGCStep) Desc() string {
|
|
|
|
return fmt.Sprintf("wait for GC finished, collection: %d, partition: %d, last scheduled time: %s, now: %s",
|
|
|
|
b.collectionID, b.partitionID, b.lastScheduledTime.String(), time.Now().String())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *confirmGCStep) Weight() stepPriority {
|
|
|
|
return stepPriorityLow
|
|
|
|
}
|
2023-08-04 18:37:08 +08:00
|
|
|
|
|
|
|
type simpleStep struct {
|
|
|
|
desc string
|
|
|
|
weight stepPriority
|
|
|
|
executeFunc func(ctx context.Context) ([]nestedStep, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSimpleStep(desc string, executeFunc func(ctx context.Context) ([]nestedStep, error)) nestedStep {
|
|
|
|
return &simpleStep{
|
|
|
|
desc: desc,
|
|
|
|
weight: stepPriorityNormal,
|
|
|
|
executeFunc: executeFunc,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simpleStep) Execute(ctx context.Context) ([]nestedStep, error) {
|
|
|
|
return s.executeFunc(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simpleStep) Desc() string {
|
|
|
|
return s.desc
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simpleStep) Weight() stepPriority {
|
|
|
|
return s.weight
|
|
|
|
}
|