2020-11-26 16:01:31 +08:00
|
|
|
package querynode
|
2020-11-09 16:27:11 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
#cgo CFLAGS: -I${SRCDIR}/../core/output/include
|
|
|
|
|
|
|
|
#cgo LDFLAGS: -L${SRCDIR}/../core/output/lib -lmilvus_segcore -Wl,-rpath=${SRCDIR}/../core/output/lib
|
|
|
|
|
2020-11-25 10:31:51 +08:00
|
|
|
#include "segcore/collection_c.h"
|
|
|
|
#include "segcore/segment_c.h"
|
2020-11-09 16:27:11 +08:00
|
|
|
|
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
import (
|
2020-12-03 19:00:11 +08:00
|
|
|
"fmt"
|
2020-11-25 10:31:51 +08:00
|
|
|
"log"
|
2020-11-12 12:04:12 +08:00
|
|
|
"strconv"
|
2020-11-13 17:20:13 +08:00
|
|
|
"sync"
|
2020-11-12 12:04:12 +08:00
|
|
|
|
2020-11-09 16:27:11 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/errors"
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/etcdpb"
|
2020-12-10 16:31:09 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/internalpb"
|
2020-11-09 16:27:11 +08:00
|
|
|
)
|
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
/*
|
|
|
|
* collectionReplica contains a in-memory local copy of persistent collections.
|
|
|
|
* In common cases, the system has multiple query nodes. Data of a collection will be
|
|
|
|
* distributed across all the available query nodes, and each query node's collectionReplica
|
|
|
|
* will maintain its own share (only part of the collection).
|
|
|
|
* Every replica tracks a value called tSafe which is the maximum timestamp that the replica
|
|
|
|
* is up-to-date.
|
|
|
|
*/
|
|
|
|
type collectionReplica interface {
|
2020-12-08 14:41:04 +08:00
|
|
|
getTSafe() tSafe
|
2020-11-17 20:00:23 +08:00
|
|
|
|
2020-11-13 17:20:13 +08:00
|
|
|
// collection
|
|
|
|
getCollectionNum() int
|
2020-12-10 16:31:09 +08:00
|
|
|
addCollection(collectionID UniqueID, schemaBlob string) error
|
2020-11-13 17:20:13 +08:00
|
|
|
removeCollection(collectionID UniqueID) error
|
|
|
|
getCollectionByID(collectionID UniqueID) (*Collection, error)
|
|
|
|
getCollectionByName(collectionName string) (*Collection, error)
|
2020-11-25 10:31:51 +08:00
|
|
|
hasCollection(collectionID UniqueID) bool
|
2020-11-13 17:20:13 +08:00
|
|
|
|
|
|
|
// partition
|
|
|
|
// Partition tags in different collections are not unique,
|
|
|
|
// so partition api should specify the target collection.
|
2020-11-25 10:31:51 +08:00
|
|
|
getPartitionNum(collectionID UniqueID) (int, error)
|
2020-11-13 17:20:13 +08:00
|
|
|
addPartition(collectionID UniqueID, partitionTag string) error
|
|
|
|
removePartition(collectionID UniqueID, partitionTag string) error
|
2020-11-25 10:31:51 +08:00
|
|
|
addPartitionsByCollectionMeta(colMeta *etcdpb.CollectionMeta) error
|
|
|
|
removePartitionsByCollectionMeta(colMeta *etcdpb.CollectionMeta) error
|
2020-11-13 17:20:13 +08:00
|
|
|
getPartitionByTag(collectionID UniqueID, partitionTag string) (*Partition, error)
|
2020-11-25 10:31:51 +08:00
|
|
|
hasPartition(collectionID UniqueID, partitionTag string) bool
|
2020-11-13 17:20:13 +08:00
|
|
|
|
|
|
|
// segment
|
|
|
|
getSegmentNum() int
|
2020-12-24 20:55:40 +08:00
|
|
|
getSegmentStatistics() []*internalpb.SegmentStats
|
2020-11-13 17:20:13 +08:00
|
|
|
addSegment(segmentID UniqueID, partitionTag string, collectionID UniqueID) error
|
|
|
|
removeSegment(segmentID UniqueID) error
|
|
|
|
getSegmentByID(segmentID UniqueID) (*Segment, error)
|
|
|
|
hasSegment(segmentID UniqueID) bool
|
2020-11-24 16:12:39 +08:00
|
|
|
|
|
|
|
freeAll()
|
2020-11-13 17:20:13 +08:00
|
|
|
}
|
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
type collectionReplicaImpl struct {
|
2020-11-13 17:20:13 +08:00
|
|
|
mu sync.RWMutex
|
2020-11-09 16:27:11 +08:00
|
|
|
collections []*Collection
|
|
|
|
segments map[UniqueID]*Segment
|
2020-11-18 16:38:28 +08:00
|
|
|
|
2020-12-08 14:41:04 +08:00
|
|
|
tSafe tSafe
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
//----------------------------------------------------------------------------------------------------- tSafe
|
2020-12-08 14:41:04 +08:00
|
|
|
func (colReplica *collectionReplicaImpl) getTSafe() tSafe {
|
2020-11-17 20:00:23 +08:00
|
|
|
return colReplica.tSafe
|
|
|
|
}
|
|
|
|
|
2020-11-09 16:27:11 +08:00
|
|
|
//----------------------------------------------------------------------------------------------------- collection
|
2020-11-17 20:00:23 +08:00
|
|
|
func (colReplica *collectionReplicaImpl) getCollectionNum() int {
|
|
|
|
colReplica.mu.RLock()
|
|
|
|
defer colReplica.mu.RUnlock()
|
2020-11-13 17:20:13 +08:00
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
return len(colReplica.collections)
|
2020-11-13 17:20:13 +08:00
|
|
|
}
|
|
|
|
|
2020-12-10 16:31:09 +08:00
|
|
|
func (colReplica *collectionReplicaImpl) addCollection(collectionID UniqueID, schemaBlob string) error {
|
2020-11-17 20:00:23 +08:00
|
|
|
colReplica.mu.Lock()
|
|
|
|
defer colReplica.mu.Unlock()
|
2020-11-13 17:20:13 +08:00
|
|
|
|
2020-12-10 16:31:09 +08:00
|
|
|
var newCollection = newCollection(collectionID, schemaBlob)
|
2020-11-17 20:00:23 +08:00
|
|
|
colReplica.collections = append(colReplica.collections, newCollection)
|
2020-11-09 16:27:11 +08:00
|
|
|
|
2020-11-13 17:20:13 +08:00
|
|
|
return nil
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
func (colReplica *collectionReplicaImpl) removeCollection(collectionID UniqueID) error {
|
|
|
|
collection, err := colReplica.getCollectionByID(collectionID)
|
2020-11-13 17:20:13 +08:00
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
colReplica.mu.Lock()
|
|
|
|
defer colReplica.mu.Unlock()
|
2020-11-13 17:20:13 +08:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
deleteCollection(collection)
|
|
|
|
|
|
|
|
tmpCollections := make([]*Collection, 0)
|
2020-11-17 20:00:23 +08:00
|
|
|
for _, col := range colReplica.collections {
|
2020-11-09 16:27:11 +08:00
|
|
|
if col.ID() == collectionID {
|
2020-11-13 17:20:13 +08:00
|
|
|
for _, p := range *col.Partitions() {
|
2020-11-09 16:27:11 +08:00
|
|
|
for _, s := range *p.Segments() {
|
2020-12-08 14:41:04 +08:00
|
|
|
deleteSegment(colReplica.segments[s.ID()])
|
2020-11-17 20:00:23 +08:00
|
|
|
delete(colReplica.segments, s.ID())
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
tmpCollections = append(tmpCollections, col)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
colReplica.collections = tmpCollections
|
2020-11-09 16:27:11 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
func (colReplica *collectionReplicaImpl) getCollectionByID(collectionID UniqueID) (*Collection, error) {
|
|
|
|
colReplica.mu.RLock()
|
|
|
|
defer colReplica.mu.RUnlock()
|
2020-11-13 17:20:13 +08:00
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
for _, collection := range colReplica.collections {
|
2020-11-09 16:27:11 +08:00
|
|
|
if collection.ID() == collectionID {
|
|
|
|
return collection, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, errors.New("cannot find collection, id = " + strconv.FormatInt(collectionID, 10))
|
|
|
|
}
|
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
func (colReplica *collectionReplicaImpl) getCollectionByName(collectionName string) (*Collection, error) {
|
|
|
|
colReplica.mu.RLock()
|
|
|
|
defer colReplica.mu.RUnlock()
|
2020-11-13 17:20:13 +08:00
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
for _, collection := range colReplica.collections {
|
2020-11-09 16:27:11 +08:00
|
|
|
if collection.Name() == collectionName {
|
|
|
|
return collection, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, errors.New("Cannot found collection: " + collectionName)
|
|
|
|
}
|
|
|
|
|
2020-11-25 10:31:51 +08:00
|
|
|
func (colReplica *collectionReplicaImpl) hasCollection(collectionID UniqueID) bool {
|
|
|
|
colReplica.mu.RLock()
|
|
|
|
defer colReplica.mu.RUnlock()
|
|
|
|
|
|
|
|
for _, col := range colReplica.collections {
|
|
|
|
if col.ID() == collectionID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-11-09 16:27:11 +08:00
|
|
|
//----------------------------------------------------------------------------------------------------- partition
|
2020-11-25 10:31:51 +08:00
|
|
|
func (colReplica *collectionReplicaImpl) getPartitionNum(collectionID UniqueID) (int, error) {
|
|
|
|
collection, err := colReplica.getCollectionByID(collectionID)
|
|
|
|
if err != nil {
|
|
|
|
return -1, err
|
|
|
|
}
|
|
|
|
|
|
|
|
colReplica.mu.RLock()
|
|
|
|
defer colReplica.mu.RUnlock()
|
|
|
|
|
|
|
|
return len(collection.partitions), nil
|
|
|
|
}
|
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
func (colReplica *collectionReplicaImpl) addPartition(collectionID UniqueID, partitionTag string) error {
|
|
|
|
collection, err := colReplica.getCollectionByID(collectionID)
|
2020-11-13 17:20:13 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
colReplica.mu.Lock()
|
|
|
|
defer colReplica.mu.Unlock()
|
2020-11-09 16:27:11 +08:00
|
|
|
|
2020-11-13 17:20:13 +08:00
|
|
|
var newPartition = newPartition(partitionTag)
|
2020-11-13 16:53:55 +08:00
|
|
|
|
2020-11-13 17:20:13 +08:00
|
|
|
*collection.Partitions() = append(*collection.Partitions(), newPartition)
|
|
|
|
return nil
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
func (colReplica *collectionReplicaImpl) removePartition(collectionID UniqueID, partitionTag string) error {
|
|
|
|
collection, err := colReplica.getCollectionByID(collectionID)
|
2020-11-13 17:20:13 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
colReplica.mu.Lock()
|
|
|
|
defer colReplica.mu.Unlock()
|
2020-11-13 16:53:55 +08:00
|
|
|
|
2020-11-13 17:20:13 +08:00
|
|
|
var tmpPartitions = make([]*Partition, 0)
|
|
|
|
for _, p := range *collection.Partitions() {
|
|
|
|
if p.Tag() == partitionTag {
|
|
|
|
for _, s := range *p.Segments() {
|
2020-12-08 14:41:04 +08:00
|
|
|
deleteSegment(colReplica.segments[s.ID()])
|
2020-11-17 20:00:23 +08:00
|
|
|
delete(colReplica.segments, s.ID())
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
2020-11-13 17:20:13 +08:00
|
|
|
} else {
|
|
|
|
tmpPartitions = append(tmpPartitions, p)
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-13 17:20:13 +08:00
|
|
|
*collection.Partitions() = tmpPartitions
|
|
|
|
return nil
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
|
2020-11-25 10:31:51 +08:00
|
|
|
func (colReplica *collectionReplicaImpl) addPartitionsByCollectionMeta(colMeta *etcdpb.CollectionMeta) error {
|
|
|
|
if !colReplica.hasCollection(colMeta.ID) {
|
|
|
|
err := errors.New("Cannot find collection, id = " + strconv.FormatInt(colMeta.ID, 10))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
pToAdd := make([]string, 0)
|
|
|
|
for _, partitionTag := range colMeta.PartitionTags {
|
|
|
|
if !colReplica.hasPartition(colMeta.ID, partitionTag) {
|
|
|
|
pToAdd = append(pToAdd, partitionTag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tag := range pToAdd {
|
|
|
|
err := colReplica.addPartition(colMeta.ID, tag)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
2020-12-03 19:00:11 +08:00
|
|
|
fmt.Println("add partition: ", tag)
|
2020-11-25 10:31:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (colReplica *collectionReplicaImpl) removePartitionsByCollectionMeta(colMeta *etcdpb.CollectionMeta) error {
|
|
|
|
col, err := colReplica.getCollectionByID(colMeta.ID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
colReplica.mu.Lock()
|
|
|
|
|
|
|
|
pToDel := make([]string, 0)
|
|
|
|
for _, partition := range col.partitions {
|
|
|
|
hasPartition := false
|
|
|
|
for _, tag := range colMeta.PartitionTags {
|
|
|
|
if partition.partitionTag == tag {
|
|
|
|
hasPartition = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !hasPartition {
|
|
|
|
pToDel = append(pToDel, partition.partitionTag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
colReplica.mu.Unlock()
|
|
|
|
|
|
|
|
for _, tag := range pToDel {
|
|
|
|
err := colReplica.removePartition(col.ID(), tag)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
2020-12-03 19:00:11 +08:00
|
|
|
fmt.Println("delete partition: ", tag)
|
2020-11-25 10:31:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
func (colReplica *collectionReplicaImpl) getPartitionByTag(collectionID UniqueID, partitionTag string) (*Partition, error) {
|
|
|
|
collection, err := colReplica.getCollectionByID(collectionID)
|
2020-11-12 14:46:02 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-11-13 17:20:13 +08:00
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
colReplica.mu.RLock()
|
|
|
|
defer colReplica.mu.RUnlock()
|
2020-11-13 17:20:13 +08:00
|
|
|
|
|
|
|
for _, p := range *collection.Partitions() {
|
2020-11-12 14:46:02 +08:00
|
|
|
if p.Tag() == partitionTag {
|
|
|
|
return p, nil
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, errors.New("cannot find partition, tag = " + partitionTag)
|
|
|
|
}
|
|
|
|
|
2020-11-25 10:31:51 +08:00
|
|
|
func (colReplica *collectionReplicaImpl) hasPartition(collectionID UniqueID, partitionTag string) bool {
|
|
|
|
collection, err := colReplica.getCollectionByID(collectionID)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
colReplica.mu.RLock()
|
|
|
|
defer colReplica.mu.RUnlock()
|
|
|
|
|
|
|
|
for _, p := range *collection.Partitions() {
|
|
|
|
if p.Tag() == partitionTag {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-11-09 16:27:11 +08:00
|
|
|
//----------------------------------------------------------------------------------------------------- segment
|
2020-11-17 20:00:23 +08:00
|
|
|
func (colReplica *collectionReplicaImpl) getSegmentNum() int {
|
|
|
|
colReplica.mu.RLock()
|
|
|
|
defer colReplica.mu.RUnlock()
|
2020-11-13 17:20:13 +08:00
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
return len(colReplica.segments)
|
2020-11-13 17:20:13 +08:00
|
|
|
}
|
|
|
|
|
2020-12-24 20:55:40 +08:00
|
|
|
func (colReplica *collectionReplicaImpl) getSegmentStatistics() []*internalpb.SegmentStats {
|
2020-11-25 10:31:51 +08:00
|
|
|
colReplica.mu.RLock()
|
|
|
|
defer colReplica.mu.RUnlock()
|
|
|
|
|
2020-11-13 17:20:13 +08:00
|
|
|
var statisticData = make([]*internalpb.SegmentStats, 0)
|
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
for segmentID, segment := range colReplica.segments {
|
2020-11-13 17:20:13 +08:00
|
|
|
currentMemSize := segment.getMemSize()
|
|
|
|
segment.lastMemSize = currentMemSize
|
|
|
|
segmentNumOfRows := segment.getRowCount()
|
|
|
|
|
|
|
|
stat := internalpb.SegmentStats{
|
|
|
|
SegmentID: segmentID,
|
|
|
|
MemorySize: currentMemSize,
|
|
|
|
NumRows: segmentNumOfRows,
|
|
|
|
RecentlyModified: segment.recentlyModified,
|
|
|
|
}
|
|
|
|
|
|
|
|
statisticData = append(statisticData, &stat)
|
2020-11-16 17:01:10 +08:00
|
|
|
segment.recentlyModified = false
|
2020-11-13 16:47:47 +08:00
|
|
|
}
|
2020-11-09 16:27:11 +08:00
|
|
|
|
2020-12-24 20:55:40 +08:00
|
|
|
return statisticData
|
2020-11-13 17:20:13 +08:00
|
|
|
}
|
2020-11-09 16:27:11 +08:00
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
func (colReplica *collectionReplicaImpl) addSegment(segmentID UniqueID, partitionTag string, collectionID UniqueID) error {
|
|
|
|
collection, err := colReplica.getCollectionByID(collectionID)
|
2020-11-13 17:20:13 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-11-13 16:47:47 +08:00
|
|
|
|
2020-12-11 11:38:32 +08:00
|
|
|
partition, err2 := colReplica.getPartitionByTag(collectionID, partitionTag)
|
|
|
|
if err2 != nil {
|
|
|
|
return err2
|
2020-11-13 16:53:55 +08:00
|
|
|
}
|
2020-11-09 16:27:11 +08:00
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
colReplica.mu.Lock()
|
|
|
|
defer colReplica.mu.Unlock()
|
2020-11-13 17:20:13 +08:00
|
|
|
|
2020-12-24 20:55:40 +08:00
|
|
|
var newSegment = newSegment(collection, segmentID, partitionTag, collectionID)
|
2020-11-13 17:20:13 +08:00
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
colReplica.segments[segmentID] = newSegment
|
2020-11-13 17:20:13 +08:00
|
|
|
*partition.Segments() = append(*partition.Segments(), newSegment)
|
|
|
|
|
|
|
|
return nil
|
2020-11-13 16:53:55 +08:00
|
|
|
}
|
2020-11-13 16:47:47 +08:00
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
func (colReplica *collectionReplicaImpl) removeSegment(segmentID UniqueID) error {
|
|
|
|
colReplica.mu.Lock()
|
|
|
|
defer colReplica.mu.Unlock()
|
2020-11-13 17:20:13 +08:00
|
|
|
|
2020-11-09 16:27:11 +08:00
|
|
|
var targetPartition *Partition
|
2020-11-13 17:20:13 +08:00
|
|
|
var segmentIndex = -1
|
2020-11-09 16:27:11 +08:00
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
for _, col := range colReplica.collections {
|
2020-11-09 16:27:11 +08:00
|
|
|
for _, p := range *col.Partitions() {
|
2020-11-13 17:20:13 +08:00
|
|
|
for i, s := range *p.Segments() {
|
|
|
|
if s.ID() == segmentID {
|
2020-11-09 16:27:11 +08:00
|
|
|
targetPartition = p
|
2020-11-13 17:20:13 +08:00
|
|
|
segmentIndex = i
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
delete(colReplica.segments, segmentID)
|
2020-11-13 17:20:13 +08:00
|
|
|
|
|
|
|
if targetPartition != nil && segmentIndex > 0 {
|
|
|
|
targetPartition.segments = append(targetPartition.segments[:segmentIndex], targetPartition.segments[segmentIndex+1:]...)
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
2020-11-12 12:04:12 +08:00
|
|
|
|
2020-11-13 17:20:13 +08:00
|
|
|
return nil
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
func (colReplica *collectionReplicaImpl) getSegmentByID(segmentID UniqueID) (*Segment, error) {
|
|
|
|
colReplica.mu.RLock()
|
|
|
|
defer colReplica.mu.RUnlock()
|
2020-11-13 17:20:13 +08:00
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
targetSegment, ok := colReplica.segments[segmentID]
|
2020-11-09 16:27:11 +08:00
|
|
|
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("cannot found segment with id = " + strconv.FormatInt(segmentID, 10))
|
|
|
|
}
|
|
|
|
|
|
|
|
return targetSegment, nil
|
|
|
|
}
|
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
func (colReplica *collectionReplicaImpl) hasSegment(segmentID UniqueID) bool {
|
|
|
|
colReplica.mu.RLock()
|
|
|
|
defer colReplica.mu.RUnlock()
|
2020-11-13 17:20:13 +08:00
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
_, ok := colReplica.segments[segmentID]
|
2020-11-09 16:27:11 +08:00
|
|
|
|
|
|
|
return ok
|
|
|
|
}
|
2020-11-24 16:12:39 +08:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------------------------------
|
|
|
|
func (colReplica *collectionReplicaImpl) freeAll() {
|
2020-11-25 10:31:51 +08:00
|
|
|
colReplica.mu.Lock()
|
|
|
|
defer colReplica.mu.Unlock()
|
|
|
|
|
2020-11-24 16:12:39 +08:00
|
|
|
for _, seg := range colReplica.segments {
|
|
|
|
deleteSegment(seg)
|
|
|
|
}
|
|
|
|
for _, col := range colReplica.collections {
|
|
|
|
deleteCollection(col)
|
|
|
|
}
|
|
|
|
}
|