2021-12-08 09:21:56 +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
2021-04-19 13:47:10 +08:00
// with the License. You may obtain a copy of the License at
//
2021-12-08 09:21:56 +08:00
// http://www.apache.org/licenses/LICENSE-2.0
2021-04-19 13:47:10 +08:00
//
2021-12-08 09:21:56 +08: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 13:47:10 +08:00
2021-01-16 10:12:14 +08:00
package querynode
2020-08-28 17:29:26 +08:00
2020-09-02 10:38:08 +08:00
/ *
2020-10-23 18:01:24 +08:00
# cgo CFLAGS : - I $ { SRCDIR } / . . / core / output / include
2020-09-02 10:38:08 +08:00
2020-10-31 15:11:47 +08:00
# cgo LDFLAGS : - L $ { SRCDIR } / . . / core / output / lib - lmilvus_segcore - Wl , - rpath = $ { SRCDIR } / . . / core / output / lib
2020-09-02 10:38:08 +08:00
2020-11-25 10:31:51 +08:00
# include "segcore/collection_c.h"
# include "segcore/segment_c.h"
2020-09-02 10:38:08 +08:00
* /
2020-08-28 17:29:26 +08:00
import "C"
2021-03-05 09:21:35 +08:00
import (
"go.uber.org/zap"
2021-04-22 14:45:57 +08:00
"github.com/milvus-io/milvus/internal/log"
2021-03-05 09:21:35 +08:00
)
2020-08-28 17:29:26 +08:00
2021-10-05 21:36:24 +08:00
// Partition is a logical division of Collection and can be considered as an attribute of Segment.
2020-08-28 17:29:26 +08:00
type Partition struct {
2021-02-05 10:53:11 +08:00
collectionID UniqueID
partitionID UniqueID
segmentIDs [ ] UniqueID
2020-08-28 17:29:26 +08:00
}
2021-10-05 21:36:24 +08:00
// ID returns the identity of the partition.
2021-01-20 09:36:50 +08:00
func ( p * Partition ) ID ( ) UniqueID {
2021-02-05 10:53:11 +08:00
return p . partitionID
2021-01-20 09:36:50 +08:00
}
2021-02-05 10:53:11 +08:00
func ( p * Partition ) addSegmentID ( segmentID UniqueID ) {
p . segmentIDs = append ( p . segmentIDs , segmentID )
2021-12-24 17:18:28 +08:00
log . Debug ( "add a segment to replica" , zap . Int64 ( "collectionID" , p . collectionID ) , zap . Int64 ( "partitionID" , p . partitionID ) , zap . Int64 ( "segmentID" , segmentID ) )
2020-08-28 17:29:26 +08:00
}
2021-02-05 10:53:11 +08:00
func ( p * Partition ) removeSegmentID ( segmentID UniqueID ) {
tmpIDs := make ( [ ] UniqueID , 0 )
for _ , id := range p . segmentIDs {
2021-04-29 15:59:08 +08:00
if id != segmentID {
2021-02-05 10:53:11 +08:00
tmpIDs = append ( tmpIDs , id )
}
}
p . segmentIDs = tmpIDs
2021-12-24 17:02:50 +08:00
log . Debug ( "remove a segment from replica" , zap . Int64 ( "collectionID" , p . collectionID ) , zap . Int64 ( "partitionID" , p . partitionID ) , zap . Int64 ( "segmentID" , segmentID ) )
2021-02-05 10:53:11 +08:00
}
func newPartition ( collectionID UniqueID , partitionID UniqueID ) * Partition {
2021-01-21 15:20:23 +08:00
var newPartition = & Partition {
2021-02-05 10:53:11 +08:00
collectionID : collectionID ,
partitionID : partitionID ,
2021-01-21 15:20:23 +08:00
}
2021-03-05 09:21:35 +08:00
log . Debug ( "create partition" , zap . Int64 ( "partitionID" , partitionID ) )
2021-01-21 15:20:23 +08:00
return newPartition
}