Fix crash caused by segment function concurrency (#24351)

Signed-off-by: sunby <bingyi.sun@zilliz.com>
Co-authored-by: sunby <bingyi.sun@zilliz.com>
pull/24334/head
Bingyi Sun 2023-05-24 19:23:27 +08:00 committed by GitHub
parent 8e3ba74648
commit 0c8045d66c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 0 deletions

View File

@ -222,10 +222,17 @@ func NewSegment(collection *Collection,
return segment, nil
}
func (s *LocalSegment) isValid() bool {
return s.ptr != nil
}
func (s *LocalSegment) InsertCount() int64 {
s.mut.RLock()
defer s.mut.RUnlock()
if !s.isValid() {
return 0
}
var rowCount C.int64_t
GetPool().Submit(func() (any, error) {
rowCount = C.GetRowCount(s.ptr)
@ -239,6 +246,9 @@ func (s *LocalSegment) RowNum() int64 {
s.mut.RLock()
defer s.mut.RUnlock()
if !s.isValid() {
return 0
}
var rowCount C.int64_t
GetPool().Submit(func() (any, error) {
rowCount = C.GetRealCount(s.ptr)
@ -252,6 +262,9 @@ func (s *LocalSegment) MemSize() int64 {
s.mut.RLock()
defer s.mut.RUnlock()
if !s.isValid() {
return 0
}
var memoryUsageInBytes C.int64_t
GetPool().Submit(func() (any, error) {
memoryUsageInBytes = C.GetMemoryUsageInBytes(s.ptr)
@ -285,6 +298,9 @@ func (s *LocalSegment) ExistIndex(fieldID int64) bool {
func (s *LocalSegment) HasRawData(fieldID int64) bool {
s.mut.RLock()
defer s.mut.RUnlock()
if !s.isValid() {
return false
}
ret := C.HasRawData(s.ptr, C.int64_t(fieldID))
return bool(ret)
}