From 8f13fcd612dc75a59c095f1e322f8cea5257a849 Mon Sep 17 00:00:00 2001 From: yah01 Date: Fri, 11 Nov 2022 14:37:05 +0800 Subject: [PATCH] Only log if the refresh actually happens (#20505) Signed-off-by: yah01 Signed-off-by: yah01 --- .../observers/collection_observer.go | 31 ++++++++++++------- .../indexparams/disk_index_params_test.go | 29 ----------------- 2 files changed, 19 insertions(+), 41 deletions(-) diff --git a/internal/querycoordv2/observers/collection_observer.go b/internal/querycoordv2/observers/collection_observer.go index d0a71fa8c6..dd2f76cf0b 100644 --- a/internal/querycoordv2/observers/collection_observer.go +++ b/internal/querycoordv2/observers/collection_observer.go @@ -117,10 +117,11 @@ func (ob *CollectionObserver) observeTimeout() { ob.meta.ReplicaManager.RemoveCollection(collection.GetCollectionID()) ob.targetMgr.RemoveCollection(collection.GetCollectionID()) } else if now.After(refreshTime) { - ob.refreshTargets(collection.UpdatedAt, collection.GetCollectionID()) - log.Info("load for long time, refresh targets of collection", - zap.Duration("loadTime", time.Since(collection.CreatedAt)), - ) + if ob.refreshTargets(collection.UpdatedAt, collection.GetCollectionID()) { + log.Info("load for long time, refresh targets of collection", + zap.Duration("loadTime", time.Since(collection.CreatedAt)), + ) + } } } @@ -155,20 +156,25 @@ func (ob *CollectionObserver) observeTimeout() { partitionIDs := lo.Map(partitions, func(partition *meta.Partition, _ int) int64 { return partition.GetPartitionID() }) - ob.refreshTargets(partition.UpdatedAt, partition.GetCollectionID(), partitionIDs...) - log.Info("load for long time, refresh targets of partitions", - zap.Duration("loadTime", time.Since(partition.CreatedAt)), - ) + if ob.refreshTargets(partition.UpdatedAt, partition.GetCollectionID(), partitionIDs...) { + log.Info("load for long time, refresh targets of partitions", + zap.Duration("loadTime", time.Since(partition.CreatedAt)), + ) + } break } } } } -func (ob *CollectionObserver) refreshTargets(updatedAt time.Time, collectionID int64, partitions ...int64) { +// refreshTargets refreshes the targets of the given collection, +// avoids repeated refreshing by checking the updatedAt, +// returns true if actually refreshed the targets, +// false otherwise +func (ob *CollectionObserver) refreshTargets(updatedAt time.Time, collectionID int64, partitions ...int64) bool { refreshedTime, ok := ob.refreshed[collectionID] if ok && refreshedTime.Equal(updatedAt) { - return + return false } ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) @@ -181,8 +187,8 @@ func (ob *CollectionObserver) refreshTargets(updatedAt time.Time, collectionID i var err error partitions, err = ob.broker.GetPartitions(ctx, collectionID) if err != nil { - log.Error("failed to get partitions from RootCoord", zap.Error(err)) - return + log.Warn("failed to get partitions from RootCoord, will refresh targets later", zap.Error(err)) + return false } } @@ -195,6 +201,7 @@ func (ob *CollectionObserver) refreshTargets(updatedAt time.Time, collectionID i ) ob.refreshed[collectionID] = updatedAt + return true } func (ob *CollectionObserver) observeLoadStatus() { diff --git a/internal/util/indexparams/disk_index_params_test.go b/internal/util/indexparams/disk_index_params_test.go index 58a40cf387..41e580128c 100644 --- a/internal/util/indexparams/disk_index_params_test.go +++ b/internal/util/indexparams/disk_index_params_test.go @@ -27,35 +27,6 @@ import ( ) func TestDiskIndexParams(t *testing.T) { - t.Run("fill index params without auto index param", func(t *testing.T) { - var params paramtable.ComponentParam - params.Init() - - indexParams := make(map[string]string) - err := FillDiskIndexParams(¶ms, indexParams) - assert.NoError(t, err) - - pgCodeBudgetGBRatio, err := strconv.ParseFloat(indexParams[PQCodeBudgetRatioKey], 64) - assert.NoError(t, err) - assert.Equal(t, 0.125, pgCodeBudgetGBRatio) - - buildNumThreadsRatio, err := strconv.ParseFloat(indexParams[NumBuildThreadRatioKey], 64) - assert.NoError(t, err) - assert.Equal(t, 1.0, buildNumThreadsRatio) - - searchCacheBudgetGBRatio, err := strconv.ParseFloat(indexParams[SearchCacheBudgetRatioKey], 64) - assert.NoError(t, err) - assert.Equal(t, 0.125, searchCacheBudgetGBRatio) - - loadNumThreadRatio, err := strconv.ParseFloat(indexParams[NumLoadThreadRatioKey], 64) - assert.NoError(t, err) - assert.Equal(t, 8.0, loadNumThreadRatio) - - beamWidthRatio, err := strconv.ParseFloat(indexParams[BeamWidthRatioKey], 64) - assert.NoError(t, err) - assert.Equal(t, 4.0, beamWidthRatio) - }) - t.Run("fill index params with auto index", func(t *testing.T) { var params paramtable.ComponentParam params.AutoIndexConfig.Enable = true