Fix Data race of loadType in querynode/collection.go (#17275)

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
pull/17278/head
congqixia 2022-05-30 19:16:02 +08:00 committed by GitHub
parent 11834a0948
commit cecbd40a22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -33,6 +33,7 @@ import (
"fmt"
"math"
"sync"
"sync/atomic"
"unsafe"
"github.com/milvus-io/milvus/internal/util/typeutil"
@ -61,7 +62,7 @@ type Collection struct {
vDeltaChannels []Channel
pDeltaChannels []Channel
loadType loadType
loadType int32
releaseMu sync.RWMutex // guards release
releasedPartitions map[UniqueID]struct{}
@ -283,12 +284,13 @@ func (c *Collection) getReleaseTime() (Timestamp, bool) {
// setLoadType set the loading type of collection, which is loadTypeCollection or loadTypePartition
func (c *Collection) setLoadType(l loadType) {
c.loadType = l
atomic.StoreInt32(&c.loadType, int32(l))
}
// getLoadType get the loadType of collection, which is loadTypeCollection or loadTypePartition
func (c *Collection) getLoadType() loadType {
return c.loadType
l := atomic.LoadInt32(&c.loadType)
return loadType(l)
}
// getFieldType get the field type according to the field id.