Skip to content

Commit

Permalink
enhance: Remove unnecessary clone in SetState (milvus-io#37697)
Browse files Browse the repository at this point in the history
issue: milvus-io#37637

---------

Signed-off-by: bigsheeper <[email protected]>
  • Loading branch information
bigsheeper authored Nov 15, 2024
1 parent 81fa7dd commit 18a6478
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion internal/datacoord/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
8 changes: 0 additions & 8 deletions internal/datacoord/segment_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions internal/datacoord/task_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 18a6478

Please sign in to comment.