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 job
|
|
|
|
|
|
|
|
import (
|
2023-03-20 14:55:57 +08:00
|
|
|
"context"
|
2022-09-15 18:48:32 +08:00
|
|
|
"time"
|
|
|
|
|
2023-03-20 14:55:57 +08:00
|
|
|
"github.com/samber/lo"
|
2023-05-18 09:17:23 +08:00
|
|
|
"go.uber.org/zap"
|
2023-03-20 14:55:57 +08:00
|
|
|
|
2023-06-09 01:28:37 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
|
2023-03-20 14:55:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
2023-05-30 17:41:28 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/querycoordv2/checkers"
|
2022-09-15 18:48:32 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/querycoordv2/meta"
|
2023-03-20 14:55:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/querycoordv2/session"
|
2023-05-18 09:17:23 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/log"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/merr"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/typeutil"
|
2022-09-15 18:48:32 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// waitCollectionReleased blocks until
|
|
|
|
// all channels and segments of given collection(partitions) are released,
|
|
|
|
// empty partition list means wait for collection released
|
2023-05-30 17:41:28 +08:00
|
|
|
func waitCollectionReleased(dist *meta.DistributionManager, checkerController *checkers.CheckerController, collection int64, partitions ...int64) {
|
2022-09-15 18:48:32 +08:00
|
|
|
partitionSet := typeutil.NewUniqueSet(partitions...)
|
|
|
|
for {
|
|
|
|
var (
|
|
|
|
channels []*meta.DmChannel
|
|
|
|
segments []*meta.Segment = dist.SegmentDistManager.GetByCollection(collection)
|
|
|
|
)
|
|
|
|
if partitionSet.Len() > 0 {
|
|
|
|
segments = lo.Filter(segments, func(segment *meta.Segment, _ int) bool {
|
|
|
|
return partitionSet.Contain(segment.GetPartitionID())
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
channels = dist.ChannelDistManager.GetByCollection(collection)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(channels)+len(segments) == 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2023-05-30 17:41:28 +08:00
|
|
|
// trigger check more frequently
|
|
|
|
checkerController.Check()
|
2022-09-15 18:48:32 +08:00
|
|
|
time.Sleep(200 * time.Millisecond)
|
|
|
|
}
|
|
|
|
}
|
2023-03-20 14:55:57 +08:00
|
|
|
|
2023-05-01 16:36:38 +08:00
|
|
|
func loadPartitions(ctx context.Context,
|
|
|
|
meta *meta.Meta,
|
|
|
|
cluster session.Cluster,
|
2023-05-18 09:17:23 +08:00
|
|
|
broker meta.Broker,
|
2023-05-29 20:55:28 +08:00
|
|
|
withSchema bool,
|
2023-05-01 16:36:38 +08:00
|
|
|
collection int64,
|
2023-09-21 09:45:27 +08:00
|
|
|
partitions ...int64,
|
|
|
|
) error {
|
2023-05-29 20:55:28 +08:00
|
|
|
var err error
|
|
|
|
var schema *schemapb.CollectionSchema
|
|
|
|
if withSchema {
|
|
|
|
schema, err = broker.GetCollectionSchema(ctx, collection)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-05-18 09:17:23 +08:00
|
|
|
}
|
|
|
|
indexes, err := broker.DescribeIndex(ctx, collection)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-03-20 14:55:57 +08:00
|
|
|
replicas := meta.ReplicaManager.GetByCollection(collection)
|
|
|
|
loadReq := &querypb.LoadPartitionsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_LoadPartitions,
|
|
|
|
},
|
2023-05-18 09:17:23 +08:00
|
|
|
CollectionID: collection,
|
|
|
|
PartitionIDs: partitions,
|
|
|
|
Schema: schema,
|
|
|
|
IndexInfoList: indexes,
|
2023-03-20 14:55:57 +08:00
|
|
|
}
|
|
|
|
for _, replica := range replicas {
|
|
|
|
for _, node := range replica.GetNodes() {
|
|
|
|
status, err := cluster.LoadPartitions(ctx, node, loadReq)
|
2023-05-18 09:17:23 +08:00
|
|
|
// There is no need to rollback LoadPartitions as the load job will fail
|
|
|
|
// and the Delegator will not be created,
|
|
|
|
// resulting in search and query requests failing due to the absence of Delegator.
|
2023-03-20 14:55:57 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-05-18 09:17:23 +08:00
|
|
|
if !merr.Ok(status) {
|
|
|
|
return merr.Error(status)
|
2023-03-20 14:55:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-05-01 16:36:38 +08:00
|
|
|
func releasePartitions(ctx context.Context,
|
|
|
|
meta *meta.Meta,
|
|
|
|
cluster session.Cluster,
|
|
|
|
collection int64,
|
2023-09-21 09:45:27 +08:00
|
|
|
partitions ...int64,
|
|
|
|
) {
|
2023-05-18 09:17:23 +08:00
|
|
|
log := log.Ctx(ctx).With(zap.Int64("collection", collection), zap.Int64s("partitions", partitions))
|
2023-03-20 14:55:57 +08:00
|
|
|
replicas := meta.ReplicaManager.GetByCollection(collection)
|
|
|
|
releaseReq := &querypb.ReleasePartitionsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_ReleasePartitions,
|
|
|
|
},
|
|
|
|
CollectionID: collection,
|
|
|
|
PartitionIDs: partitions,
|
|
|
|
}
|
|
|
|
for _, replica := range replicas {
|
|
|
|
for _, node := range replica.GetNodes() {
|
|
|
|
status, err := cluster.ReleasePartitions(ctx, node, releaseReq)
|
2023-05-18 09:17:23 +08:00
|
|
|
// Ignore error as the Delegator will be removed from the query node,
|
|
|
|
// causing search and query requests to fail due to the absence of Delegator.
|
2023-03-20 14:55:57 +08:00
|
|
|
if err != nil {
|
2023-05-18 09:17:23 +08:00
|
|
|
log.Warn("failed to ReleasePartitions", zap.Int64("node", node), zap.Error(err))
|
|
|
|
continue
|
2023-03-20 14:55:57 +08:00
|
|
|
}
|
2023-05-18 09:17:23 +08:00
|
|
|
if !merr.Ok(status) {
|
|
|
|
log.Warn("failed to ReleasePartitions", zap.Int64("node", node), zap.Error(merr.Error(status)))
|
2023-03-20 14:55:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|