2021-12-08 01:21:56 +00: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
|
2021-04-19 05:47:10 +00:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-12-08 01:21:56 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 05:47:10 +00:00
|
|
|
//
|
2021-12-08 01:21:56 +00:00
|
|
|
// 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-04-19 05:47:10 +00:00
|
|
|
|
2021-01-16 02:12:14 +00:00
|
|
|
package querynode
|
2020-08-28 09:29:26 +00:00
|
|
|
|
2020-09-02 02:38:08 +00:00
|
|
|
/*
|
2022-06-24 13:12:15 +00:00
|
|
|
#cgo pkg-config: milvus_segcore
|
2020-09-02 02:38:08 +00:00
|
|
|
|
2020-11-25 02:31:51 +00:00
|
|
|
#include "segcore/collection_c.h"
|
|
|
|
#include "segcore/segment_c.h"
|
2020-09-02 02:38:08 +00:00
|
|
|
|
|
|
|
*/
|
2020-08-28 09:29:26 +00:00
|
|
|
import "C"
|
2021-03-05 01:21:35 +00:00
|
|
|
import (
|
2022-05-31 05:42:03 +00:00
|
|
|
"fmt"
|
|
|
|
|
2021-03-05 01:21:35 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2021-04-22 06:45:57 +00:00
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
2021-03-05 01:21:35 +00:00
|
|
|
)
|
2020-08-28 09:29:26 +00:00
|
|
|
|
2021-10-05 13:36:24 +00:00
|
|
|
// Partition is a logical division of Collection and can be considered as an attribute of Segment.
|
2020-08-28 09:29:26 +00:00
|
|
|
type Partition struct {
|
2022-05-31 05:42:03 +00:00
|
|
|
collectionID UniqueID
|
|
|
|
partitionID UniqueID
|
|
|
|
growingSegmentIDs []UniqueID
|
|
|
|
sealedSegmentIDs []UniqueID
|
2020-08-28 09:29:26 +00:00
|
|
|
}
|
|
|
|
|
2021-10-05 13:36:24 +00:00
|
|
|
// ID returns the identity of the partition.
|
2021-01-20 01:36:50 +00:00
|
|
|
func (p *Partition) ID() UniqueID {
|
2021-02-05 02:53:11 +00:00
|
|
|
return p.partitionID
|
2021-01-20 01:36:50 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 05:42:03 +00:00
|
|
|
// getSegmentIDs returns segment ids by DataScope
|
|
|
|
func (p *Partition) getSegmentIDs(segType segmentType) ([]UniqueID, error) {
|
|
|
|
switch segType {
|
|
|
|
case segmentTypeGrowing:
|
|
|
|
dst := make([]UniqueID, len(p.growingSegmentIDs))
|
|
|
|
copy(dst, p.growingSegmentIDs)
|
|
|
|
return dst, nil
|
|
|
|
case segmentTypeSealed:
|
|
|
|
dst := make([]UniqueID, len(p.sealedSegmentIDs))
|
|
|
|
copy(dst, p.sealedSegmentIDs)
|
|
|
|
return dst, nil
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("unexpected segmentType %s", segType.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-07 09:47:48 +00:00
|
|
|
// addSegmentID add segmentID to segmentIDs
|
2022-05-31 05:42:03 +00:00
|
|
|
func (p *Partition) addSegmentID(segmentID UniqueID, segType segmentType) {
|
|
|
|
switch segType {
|
|
|
|
case segmentTypeGrowing:
|
|
|
|
p.growingSegmentIDs = append(p.growingSegmentIDs, segmentID)
|
|
|
|
case segmentTypeSealed:
|
|
|
|
p.sealedSegmentIDs = append(p.sealedSegmentIDs, segmentID)
|
|
|
|
default:
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log.Info("add a segment to replica",
|
|
|
|
zap.Int64("collectionID", p.collectionID),
|
|
|
|
zap.Int64("partitionID", p.partitionID),
|
|
|
|
zap.Int64("segmentID", segmentID),
|
|
|
|
zap.String("segmentType", segType.String()))
|
2020-08-28 09:29:26 +00:00
|
|
|
}
|
|
|
|
|
2022-01-10 14:32:14 +00:00
|
|
|
// removeSegmentID removes segmentID from segmentIDs
|
2022-05-31 05:42:03 +00:00
|
|
|
func (p *Partition) removeSegmentID(segmentID UniqueID, segType segmentType) {
|
|
|
|
deleteFunc := func(segmentIDs []UniqueID) []UniqueID {
|
|
|
|
tmpIDs := make([]UniqueID, 0)
|
|
|
|
for _, id := range segmentIDs {
|
|
|
|
if id != segmentID {
|
|
|
|
tmpIDs = append(tmpIDs, id)
|
|
|
|
}
|
2021-02-05 02:53:11 +00:00
|
|
|
}
|
2022-05-31 05:42:03 +00:00
|
|
|
return tmpIDs
|
|
|
|
}
|
|
|
|
switch segType {
|
|
|
|
case segmentTypeGrowing:
|
|
|
|
p.growingSegmentIDs = deleteFunc(p.growingSegmentIDs)
|
|
|
|
case segmentTypeSealed:
|
|
|
|
p.sealedSegmentIDs = deleteFunc(p.sealedSegmentIDs)
|
|
|
|
default:
|
|
|
|
return
|
2021-02-05 02:53:11 +00:00
|
|
|
}
|
2022-06-28 02:16:17 +00:00
|
|
|
log.Info("remove a segment from replica",
|
|
|
|
zap.Int64("collectionID", p.collectionID),
|
|
|
|
zap.Int64("partitionID", p.partitionID),
|
|
|
|
zap.Int64("segmentID", segmentID),
|
|
|
|
zap.String("segmentType", segType.String()))
|
2021-02-05 02:53:11 +00:00
|
|
|
}
|
|
|
|
|
2022-01-10 14:34:09 +00:00
|
|
|
// newPartition returns a new Partition
|
2021-02-05 02:53:11 +00:00
|
|
|
func newPartition(collectionID UniqueID, partitionID UniqueID) *Partition {
|
2021-01-21 07:20:23 +00:00
|
|
|
var newPartition = &Partition{
|
2021-02-05 02:53:11 +00:00
|
|
|
collectionID: collectionID,
|
|
|
|
partitionID: partitionID,
|
2021-01-21 07:20:23 +00:00
|
|
|
}
|
|
|
|
|
2022-05-07 02:27:51 +00:00
|
|
|
log.Info("create partition", zap.Int64("partitionID", partitionID))
|
2021-01-21 07:20:23 +00:00
|
|
|
return newPartition
|
|
|
|
}
|