Fix BF Concurrency issue (#20211)

Signed-off-by: xiaofan-luan <xiaofan.luan@zilliz.com>

Signed-off-by: xiaofan-luan <xiaofan.luan@zilliz.com>
This commit is contained in:
Xiaofan 2022-10-31 19:27:35 +08:00 committed by GitHub
parent 4f93dbc335
commit 99b958e360
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -17,6 +17,7 @@
package datanode
import (
"sync"
"sync/atomic"
"github.com/bits-and-blooms/bloom/v3"
@ -36,6 +37,7 @@ type Segment struct {
memorySize int64
compactedTo UniqueID
statLock sync.Mutex
currentStat *storage.PkStatistics
historyStats []*storage.PkStatistics
@ -70,6 +72,8 @@ func (s *Segment) setType(t datapb.SegmentType) {
}
func (s *Segment) updatePKRange(ids storage.FieldData) {
s.statLock.Lock()
defer s.statLock.Unlock()
s.InitCurrentStat()
err := s.currentStat.UpdatePKRange(ids)
if err != nil {
@ -87,6 +91,8 @@ func (s *Segment) InitCurrentStat() {
// check if PK exists is current
func (s *Segment) isPKExist(pk primaryKey) bool {
s.statLock.Lock()
defer s.statLock.Unlock()
if s.currentStat != nil && s.currentStat.PkExist(pk) {
return true
}

View File

@ -95,6 +95,7 @@ type Segment struct {
indexedFieldInfos *typeutil.ConcurrentMap[UniqueID, *IndexedFieldInfo]
statLock sync.Mutex
// only used by sealed segments
currentStat *storage.PkStatistics
historyStats []*storage.PkStatistics
@ -618,6 +619,8 @@ func (s *Segment) fillIndexedFieldsData(ctx context.Context, collectionID Unique
}
func (s *Segment) updateBloomFilter(pks []primaryKey) {
s.statLock.Lock()
defer s.statLock.Unlock()
s.InitCurrentStat()
buf := make([]byte, 8)
for _, pk := range pks {
@ -647,6 +650,8 @@ func (s *Segment) InitCurrentStat() {
// check if PK exists is current
func (s *Segment) isPKExist(pk primaryKey) bool {
s.statLock.Lock()
defer s.statLock.Unlock()
if s.currentStat != nil && s.currentStat.PkExist(pk) {
return true
}