Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: [2.4] Fix load slowly #37735

Open
wants to merge 1 commit into
base: 2.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions internal/querycoordv2/observers/target_observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@
mut sync.Mutex // Guard readyNotifiers
readyNotifiers map[int64][]chan struct{} // CollectionID -> Notifiers

dispatcher *taskDispatcher[int64]
keylocks *lock.KeyLock[int64]
// loadingDispatcher updates targets for collections that are loading (also collections without a current target).
loadingDispatcher *taskDispatcher[int64]
// loadedDispatcher updates targets for loaded collections.
loadedDispatcher *taskDispatcher[int64]

keylocks *lock.KeyLock[int64]

startOnce sync.Once
stopOnce sync.Once
Expand Down Expand Up @@ -117,8 +121,8 @@
keylocks: lock.NewKeyLock[int64](),
}

dispatcher := newTaskDispatcher(result.check)
result.dispatcher = dispatcher
result.loadingDispatcher = newTaskDispatcher(result.check)
result.loadedDispatcher = newTaskDispatcher(result.check)
return result
}

Expand All @@ -127,7 +131,8 @@
ctx, cancel := context.WithCancel(context.Background())
ob.cancel = cancel

ob.dispatcher.Start()
ob.loadingDispatcher.Start()
ob.loadedDispatcher.Start()

ob.wg.Add(1)
go func() {
Expand All @@ -147,7 +152,8 @@
}
ob.wg.Wait()

ob.dispatcher.Stop()
ob.loadingDispatcher.Stop()
ob.loadedDispatcher.Stop()
})
}

Expand All @@ -170,7 +176,13 @@

case <-ticker.C:
ob.clean()
ob.dispatcher.AddTask(ob.meta.GetAll()...)
loaded := lo.FilterMap(ob.meta.GetAllCollections(), func(collection *meta.Collection, _ int) (int64, bool) {
if collection.GetStatus() == querypb.LoadStatus_Loaded {
return collection.GetCollectionID(), true
}
return 0, false
})
ob.loadedDispatcher.AddTask(loaded...)

case req := <-ob.updateChan:
log.Info("manually trigger update target",
Expand Down Expand Up @@ -220,13 +232,13 @@
func (ob *TargetObserver) Check(ctx context.Context, collectionID int64, partitionID int64) bool {
result := ob.targetMgr.IsCurrentTargetExist(collectionID, partitionID)
if !result {
ob.dispatcher.AddTask(collectionID)
ob.loadingDispatcher.AddTask(collectionID)
}
return result
}

func (ob *TargetObserver) TriggerUpdateCurrentTarget(collectionID int64) {
ob.dispatcher.AddTask(collectionID)

Check failure on line 241 in internal/querycoordv2/observers/target_observer.go

View workflow job for this annotation

GitHub Actions / Code Checker MacOS 12

ob.dispatcher undefined (type *TargetObserver has no field or method dispatcher)
}

func (ob *TargetObserver) check(ctx context.Context, collectionID int64) {
Expand Down
7 changes: 5 additions & 2 deletions internal/querycoordv2/observers/target_observer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ func (suite *TargetObserverSuite) SetupTest() {
suite.collectionID = int64(1000)
suite.partitionID = int64(100)

err = suite.meta.CollectionManager.PutCollection(utils.CreateTestCollection(suite.collectionID, 1))
testCollection := utils.CreateTestCollection(suite.collectionID, 1)
testCollection.Status = querypb.LoadStatus_Loaded
err = suite.meta.CollectionManager.PutCollection(testCollection)
suite.NoError(err)
err = suite.meta.CollectionManager.PutPartition(utils.CreateTestPartition(suite.collectionID, suite.partitionID))
suite.NoError(err)
Expand Down Expand Up @@ -318,7 +320,8 @@ func (suite *TargetObserverCheckSuite) SetupTest() {
func (s *TargetObserverCheckSuite) TestCheck() {
r := s.observer.Check(context.Background(), s.collectionID, common.AllPartitionsID)
s.False(r)
s.True(s.observer.dispatcher.tasks.Contain(s.collectionID))
s.False(s.observer.loadedDispatcher.tasks.Contain(s.collectionID))
s.True(s.observer.loadingDispatcher.tasks.Contain(s.collectionID))
}

func TestTargetObserver(t *testing.T) {
Expand Down
Loading