mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-06 17:18:35 +08:00
Fix load timeout after next target updates (#21759)
Signed-off-by: sunby <bingyi.sun@zilliz.com> Co-authored-by: sunby <bingyi.sun@zilliz.com>
This commit is contained in:
parent
e64f55cd27
commit
b91bb5a729
@ -304,13 +304,6 @@ func (m *CollectionManager) PutCollection(collection *Collection) error {
|
|||||||
return m.putCollection(collection, true)
|
return m.putCollection(collection, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *CollectionManager) PutCollectionWithoutSave(collection *Collection) {
|
|
||||||
m.rwmutex.Lock()
|
|
||||||
defer m.rwmutex.Unlock()
|
|
||||||
|
|
||||||
m.putCollection(collection, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *CollectionManager) UpdateCollection(collection *Collection) error {
|
func (m *CollectionManager) UpdateCollection(collection *Collection) error {
|
||||||
m.rwmutex.Lock()
|
m.rwmutex.Lock()
|
||||||
defer m.rwmutex.Unlock()
|
defer m.rwmutex.Unlock()
|
||||||
|
|||||||
@ -17,6 +17,8 @@
|
|||||||
package meta
|
package meta
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
|
|
||||||
"github.com/milvus-io/milvus/internal/proto/datapb"
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
||||||
@ -26,12 +28,14 @@ import (
|
|||||||
type CollectionTarget struct {
|
type CollectionTarget struct {
|
||||||
segments map[int64]*datapb.SegmentInfo
|
segments map[int64]*datapb.SegmentInfo
|
||||||
dmChannels map[string]*DmChannel
|
dmChannels map[string]*DmChannel
|
||||||
|
createTime time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCollectionTarget(segments map[int64]*datapb.SegmentInfo, dmChannels map[string]*DmChannel) *CollectionTarget {
|
func NewCollectionTarget(segments map[int64]*datapb.SegmentInfo, dmChannels map[string]*DmChannel) *CollectionTarget {
|
||||||
return &CollectionTarget{
|
return &CollectionTarget{
|
||||||
segments: segments,
|
segments: segments,
|
||||||
dmChannels: dmChannels,
|
dmChannels: dmChannels,
|
||||||
|
createTime: time.Now(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,6 +55,10 @@ func (p *CollectionTarget) GetAllDmChannelNames() []string {
|
|||||||
return lo.Keys(p.dmChannels)
|
return lo.Keys(p.dmChannels)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *CollectionTarget) GetCreateTime() time.Time {
|
||||||
|
return p.createTime
|
||||||
|
}
|
||||||
|
|
||||||
func (p *CollectionTarget) IsEmpty() bool {
|
func (p *CollectionTarget) IsEmpty() bool {
|
||||||
return len(p.dmChannels)+len(p.segments) == 0
|
return len(p.dmChannels)+len(p.segments) == 0
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/milvus-io/milvus/internal/log"
|
"github.com/milvus-io/milvus/internal/log"
|
||||||
"github.com/milvus-io/milvus/internal/proto/datapb"
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
||||||
@ -402,6 +403,17 @@ func (mgr *TargetManager) GetHistoricalSegment(collectionID int64, id int64, sco
|
|||||||
return collectionTarget.GetAllSegments()[id]
|
return collectionTarget.GetAllSegments()[id]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mgr *TargetManager) GetNextTargetCreateTime(collectionID int64) time.Time {
|
||||||
|
mgr.rwMutex.RLock()
|
||||||
|
defer mgr.rwMutex.RUnlock()
|
||||||
|
targetMap := mgr.getTarget(NextTarget)
|
||||||
|
collectionTarget := targetMap.getCollectionTarget(collectionID)
|
||||||
|
if collectionTarget == nil {
|
||||||
|
return time.Time{}
|
||||||
|
}
|
||||||
|
return collectionTarget.GetCreateTime()
|
||||||
|
}
|
||||||
|
|
||||||
func (mgr *TargetManager) IsCurrentTargetExist(collectionID int64) bool {
|
func (mgr *TargetManager) IsCurrentTargetExist(collectionID int64) bool {
|
||||||
newChannels := mgr.GetDmChannelsByCollection(collectionID, CurrentTarget)
|
newChannels := mgr.GetDmChannelsByCollection(collectionID, CurrentTarget)
|
||||||
|
|
||||||
|
|||||||
@ -34,12 +34,13 @@ import (
|
|||||||
type CollectionObserver struct {
|
type CollectionObserver struct {
|
||||||
stopCh chan struct{}
|
stopCh chan struct{}
|
||||||
|
|
||||||
dist *meta.DistributionManager
|
dist *meta.DistributionManager
|
||||||
meta *meta.Meta
|
meta *meta.Meta
|
||||||
targetMgr *meta.TargetManager
|
targetMgr *meta.TargetManager
|
||||||
targetObserver *TargetObserver
|
targetObserver *TargetObserver
|
||||||
collectionLoadedCount map[int64]int
|
collectionLoadedCount map[int64]int
|
||||||
partitionLoadedCount map[int64]int
|
partitionLoadedCount map[int64]int
|
||||||
|
collectionNextTargetTime map[int64]time.Time
|
||||||
|
|
||||||
stopOnce sync.Once
|
stopOnce sync.Once
|
||||||
}
|
}
|
||||||
@ -51,13 +52,14 @@ func NewCollectionObserver(
|
|||||||
targetObserver *TargetObserver,
|
targetObserver *TargetObserver,
|
||||||
) *CollectionObserver {
|
) *CollectionObserver {
|
||||||
return &CollectionObserver{
|
return &CollectionObserver{
|
||||||
stopCh: make(chan struct{}),
|
stopCh: make(chan struct{}),
|
||||||
dist: dist,
|
dist: dist,
|
||||||
meta: meta,
|
meta: meta,
|
||||||
targetMgr: targetMgr,
|
targetMgr: targetMgr,
|
||||||
targetObserver: targetObserver,
|
targetObserver: targetObserver,
|
||||||
collectionLoadedCount: make(map[int64]int),
|
collectionLoadedCount: make(map[int64]int),
|
||||||
partitionLoadedCount: make(map[int64]int),
|
partitionLoadedCount: make(map[int64]int),
|
||||||
|
collectionNextTargetTime: make(map[int64]time.Time),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,9 +202,16 @@ func (ob *CollectionObserver) observeCollectionLoadStatus(collection *meta.Colle
|
|||||||
updated.LoadPercentage = int32(loadedCount * 100 / (targetNum * int(collection.GetReplicaNumber())))
|
updated.LoadPercentage = int32(loadedCount * 100 / (targetNum * int(collection.GetReplicaNumber())))
|
||||||
}
|
}
|
||||||
|
|
||||||
if loadedCount <= ob.collectionLoadedCount[collection.GetCollectionID()] && updated.LoadPercentage != 100 {
|
targetTime := ob.targetMgr.GetNextTargetCreateTime(collection.CollectionID)
|
||||||
|
lastTime, ok := ob.collectionNextTargetTime[collection.CollectionID]
|
||||||
|
|
||||||
|
if ok && targetTime.Equal(lastTime) &&
|
||||||
|
loadedCount <= ob.collectionLoadedCount[collection.GetCollectionID()] &&
|
||||||
|
updated.LoadPercentage != 100 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ob.collectionNextTargetTime[collection.GetCollectionID()] = targetTime
|
||||||
ob.collectionLoadedCount[collection.GetCollectionID()] = loadedCount
|
ob.collectionLoadedCount[collection.GetCollectionID()] = loadedCount
|
||||||
if updated.LoadPercentage == 100 && ob.targetObserver.Check(updated.GetCollectionID()) {
|
if updated.LoadPercentage == 100 && ob.targetObserver.Check(updated.GetCollectionID()) {
|
||||||
delete(ob.collectionLoadedCount, collection.GetCollectionID())
|
delete(ob.collectionLoadedCount, collection.GetCollectionID())
|
||||||
@ -260,12 +269,17 @@ func (ob *CollectionObserver) observePartitionLoadStatus(partition *meta.Partiti
|
|||||||
zap.Int("loadSegmentCount", loadedCount-subChannelCount))
|
zap.Int("loadSegmentCount", loadedCount-subChannelCount))
|
||||||
}
|
}
|
||||||
updated.LoadPercentage = int32(loadedCount * 100 / (targetNum * int(partition.GetReplicaNumber())))
|
updated.LoadPercentage = int32(loadedCount * 100 / (targetNum * int(partition.GetReplicaNumber())))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if loadedCount <= ob.partitionLoadedCount[partition.GetPartitionID()] && updated.LoadPercentage != 100 {
|
targetTime := ob.targetMgr.GetNextTargetCreateTime(partition.GetCollectionID())
|
||||||
|
lastTime, ok := ob.collectionNextTargetTime[partition.GetCollectionID()]
|
||||||
|
|
||||||
|
if ok && targetTime.Equal(lastTime) &&
|
||||||
|
loadedCount <= ob.partitionLoadedCount[partition.GetPartitionID()] &&
|
||||||
|
updated.LoadPercentage != 100 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
ob.collectionNextTargetTime[partition.GetCollectionID()] = targetTime
|
||||||
ob.partitionLoadedCount[partition.GetPartitionID()] = loadedCount
|
ob.partitionLoadedCount[partition.GetPartitionID()] = loadedCount
|
||||||
if updated.LoadPercentage == 100 && ob.targetObserver.Check(updated.GetCollectionID()) {
|
if updated.LoadPercentage == 100 && ob.targetObserver.Check(updated.GetCollectionID()) {
|
||||||
delete(ob.partitionLoadedCount, partition.GetPartitionID())
|
delete(ob.partitionLoadedCount, partition.GetPartitionID())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user