From 18a64782dc069d55a98046f6eecc412b180d4e01 Mon Sep 17 00:00:00 2001 From: "yihao.dai" Date: Fri, 15 Nov 2024 15:06:30 +0800 Subject: [PATCH] enhance: Remove unnecessary clone in SetState (#37697) issue: https://github.com/milvus-io/milvus/issues/37637 --------- Signed-off-by: bigsheeper --- internal/datacoord/meta.go | 2 +- internal/datacoord/segment_info.go | 8 -------- internal/datacoord/task_stats_test.go | 6 ++++-- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/internal/datacoord/meta.go b/internal/datacoord/meta.go index 4040c1239bd29..330d9012caf3d 100644 --- a/internal/datacoord/meta.go +++ b/internal/datacoord/meta.go @@ -642,7 +642,7 @@ func (m *meta) SetState(segmentID UniqueID, targetState commonpb.SegmentState) e // Apply segment metric update after successful meta update. metricMutation.commit() // Update in-memory meta. - m.segments.SetState(segmentID, targetState) + m.segments.SetSegment(segmentID, clonedSegment) } log.Info("meta update: setting segment state - complete", zap.Int64("segmentID", segmentID), diff --git a/internal/datacoord/segment_info.go b/internal/datacoord/segment_info.go index 1cee29f59bbbd..6d74d1c39cd70 100644 --- a/internal/datacoord/segment_info.go +++ b/internal/datacoord/segment_info.go @@ -219,14 +219,6 @@ func (s *SegmentsInfo) SetRowCount(segmentID UniqueID, rowCount int64) { } } -// SetState sets Segment State info for SegmentInfo with provided segmentID -// if SegmentInfo not found, do nothing -func (s *SegmentsInfo) SetState(segmentID UniqueID, state commonpb.SegmentState) { - if segment, ok := s.segments[segmentID]; ok { - s.segments[segmentID] = segment.Clone(SetState(state)) - } -} - // SetDmlPosition sets DmlPosition info (checkpoint for recovery) for SegmentInfo with provided segmentID // if SegmentInfo not found, do nothing func (s *SegmentsInfo) SetDmlPosition(segmentID UniqueID, pos *msgpb.MsgPosition) { diff --git a/internal/datacoord/task_stats_test.go b/internal/datacoord/task_stats_test.go index 992d174d64556..919970e51666d 100644 --- a/internal/datacoord/task_stats_test.go +++ b/internal/datacoord/task_stats_test.go @@ -546,10 +546,12 @@ func (s *statsTaskSuite) TestTaskStats_PreCheck() { s.Run("normal case", func() { catalog := catalogmocks.NewDataCoordCatalog(s.T()) + catalog.EXPECT().AlterSegments(mock.Anything, mock.Anything, mock.Anything).Return(nil) s.mt.catalog = catalog s.mt.statsTaskMeta.catalog = catalog - s.mt.segments.SetState(s.segID, commonpb.SegmentState_Flushed) - catalog.EXPECT().AlterSegments(mock.Anything, mock.Anything, mock.Anything).Return(nil) + updateStateOp := UpdateStatusOperator(s.segID, commonpb.SegmentState_Flushed) + err := s.mt.UpdateSegmentsInfo(updateStateOp) + s.NoError(err) catalog.EXPECT().SaveStatsTask(mock.Anything, mock.Anything).Return(nil) s.NoError(st.SetJobInfo(s.mt))