Fix the refresh may be notified finished early (#24438)

Signed-off-by: yah01 <yah2er0ne@outlook.com>
pull/24455/head
yah01 2023-05-26 18:43:26 +08:00 committed by GitHub
parent 5efa49f112
commit 848ef7418b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 13 deletions

View File

@ -61,7 +61,7 @@ func NewTargetManager(broker Broker, meta *Meta) *TargetManager {
// UpdateCollectionCurrentTarget updates the current target to next target,
// WARN: DO NOT call this method for an existing collection as target observer running, or it will lead to a double-update,
// which may make the current target not available
func (mgr *TargetManager) UpdateCollectionCurrentTarget(collectionID int64, partitionIDs ...int64) {
func (mgr *TargetManager) UpdateCollectionCurrentTarget(collectionID int64, partitionIDs ...int64) bool {
mgr.rwMutex.Lock()
defer mgr.rwMutex.Unlock()
log := log.With(zap.Int64("collectionID", collectionID),
@ -72,7 +72,7 @@ func (mgr *TargetManager) UpdateCollectionCurrentTarget(collectionID int64, part
newTarget := mgr.next.getCollectionTarget(collectionID)
if newTarget == nil || newTarget.IsEmpty() {
log.Info("next target does not exist, skip it")
return
return false
}
mgr.current.updateCollectionTarget(collectionID, newTarget)
mgr.next.removeCollectionTarget(collectionID)
@ -80,6 +80,7 @@ func (mgr *TargetManager) UpdateCollectionCurrentTarget(collectionID int64, part
log.Debug("finish to update current target for collection",
zap.Int64s("segments", newTarget.GetAllSegmentIDs()),
zap.Strings("channels", newTarget.GetAllDmChannelNames()))
return true
}
// UpdateCollectionNextTargetWithPartitions pulls next target from DataCoord,

View File

@ -273,16 +273,16 @@ func (ob *TargetObserver) shouldUpdateCurrentTarget(collectionID int64) bool {
func (ob *TargetObserver) updateCurrentTarget(collectionID int64) {
log.Info("observer trigger update current target", zap.Int64("collectionID", collectionID))
ob.targetMgr.UpdateCollectionCurrentTarget(collectionID)
ob.mut.Lock()
defer ob.mut.Unlock()
notifiers := ob.readyNotifiers[collectionID]
for _, notifier := range notifiers {
close(notifier)
}
// Reuse the capacity of notifiers slice
if notifiers != nil {
ob.readyNotifiers[collectionID] = notifiers[:0]
if ob.targetMgr.UpdateCollectionCurrentTarget(collectionID) {
ob.mut.Lock()
defer ob.mut.Unlock()
notifiers := ob.readyNotifiers[collectionID]
for _, notifier := range notifiers {
close(notifier)
}
// Reuse the capacity of notifiers slice
if notifiers != nil {
ob.readyNotifiers[collectionID] = notifiers[:0]
}
}
}