Check enableIndex before load index

Signed-off-by: XuanYang-cn <xuan.yang@zilliz.com>
pull/4973/head^2
XuanYang-cn 2021-03-10 14:51:00 +08:00 committed by yefu.chen
parent 7b2d67242d
commit 8567679888
4 changed files with 41 additions and 0 deletions

View File

@ -63,6 +63,7 @@ type ReplicaInterface interface {
getSegmentByID(segmentID UniqueID) (*Segment, error)
hasSegment(segmentID UniqueID) bool
getSegmentNum() int
setSegmentEnableIndex(segmentID UniqueID, enable bool) error
getSegmentStatistics() []*internalpb2.SegmentStats
getEnabledSegmentsBySegmentType(segType segmentType) ([]UniqueID, []UniqueID, []UniqueID)
@ -510,6 +511,10 @@ func (colReplica *collectionReplica) getSegmentsBySegmentType(segType segmentTyp
for _, segment := range colReplica.segments {
if segment.getType() == segType {
if segType == segTypeSealed && !segment.getEnableIndex() {
continue
}
targetCollectionIDs = append(targetCollectionIDs, segment.collectionID)
targetPartitionIDs = append(targetPartitionIDs, segment.partitionID)
targetSegmentIDs = append(targetSegmentIDs, segment.segmentID)
@ -538,6 +543,20 @@ func (colReplica *collectionReplica) replaceGrowingSegmentBySealedSegment(segmen
return nil
}
func (colReplica *collectionReplica) setSegmentEnableIndex(segmentID UniqueID, enable bool) error {
colReplica.mu.Lock()
defer colReplica.mu.Unlock()
targetSegment, err := colReplica.getSegmentByIDPrivate(segmentID)
if targetSegment.segmentType != segTypeSealed {
return errors.New("unexpected segment type")
}
if err == nil && targetSegment != nil {
targetSegment.setEnableIndex(enable)
}
return nil
}
//-----------------------------------------------------------------------------------------------------
func (colReplica *collectionReplica) getTSafe() tSafer {
return colReplica.tSafe

View File

@ -258,6 +258,8 @@ func TestReplaceGrowingSegmentBySealedSegment(t *testing.T) {
ns := newSegment(collection, segmentID, defaultPartitionID, collectionID, segTypeSealed)
err = node.replica.replaceGrowingSegmentBySealedSegment(ns)
assert.NoError(t, err)
err = node.replica.setSegmentEnableIndex(segmentID, true)
assert.NoError(t, err)
segmentNums := node.replica.getSegmentNum()
assert.Equal(t, segmentNums, 1)

View File

@ -324,6 +324,11 @@ func (loader *indexLoader) getIndexInfo(collectionID UniqueID, segmentID UniqueI
if response.Status.ErrorCode != commonpb.ErrorCode_ERROR_CODE_SUCCESS {
return -1, -1, errors.New(response.Status.Reason)
}
loader.replica.setSegmentEnableIndex(segmentID, response.EnableIndex)
if !response.EnableIndex {
return -1, -1, errors.New("There are no indexes on this segment")
}
return response.IndexID, response.BuildID, nil
}

View File

@ -44,6 +44,9 @@ type Segment struct {
lastMemSize int64
lastRowCount int64
once sync.Once // guards enableIndex
enableIndex bool
rmMutex sync.Mutex // guards recentlyModified
recentlyModified bool
@ -61,6 +64,18 @@ func (s *Segment) ID() UniqueID {
return s.segmentID
}
func (s *Segment) setEnableIndex(enable bool) {
setOnce := func() {
s.enableIndex = enable
}
s.once.Do(setOnce)
}
func (s *Segment) getEnableIndex() bool {
return s.enableIndex
}
func (s *Segment) setRecentlyModified(modify bool) {
s.rmMutex.Lock()
defer s.rmMutex.Unlock()