enhance: Use RWMutex and change WLock to RLock (#30557)

Related to #27675

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
pull/30308/head
congqixia 2024-02-06 17:13:56 +08:00 committed by GitHub
parent 92d1d744ae
commit b111f3b110
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 5 deletions

View File

@ -30,7 +30,7 @@ import (
// it maintains bloom filter generated from segment primary keys.
// it may be updated with new insert FieldData when serving growing segments.
type BloomFilterSet struct {
mut sync.Mutex
mut sync.RWMutex
batchSize uint
current *storage.PkStatistics
history []*storage.PkStatistics
@ -56,8 +56,8 @@ func NewBloomFilterSetWithBatchSize(batchSize uint, historyEntries ...*storage.P
}
func (bfs *BloomFilterSet) PkExists(pk storage.PrimaryKey) bool {
bfs.mut.Lock()
defer bfs.mut.Unlock()
bfs.mut.RLock()
defer bfs.mut.RUnlock()
if bfs.current != nil && bfs.current.PkExist(pk) {
return true
}
@ -101,8 +101,8 @@ func (bfs *BloomFilterSet) Roll(newStats ...*storage.PrimaryKeyStats) {
}
func (bfs *BloomFilterSet) GetHistory() []*storage.PkStatistics {
bfs.mut.Lock()
defer bfs.mut.Unlock()
bfs.mut.RLock()
defer bfs.mut.RUnlock()
return bfs.history
}