-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enhance: Periodically synchronize segments to datanode watcher #33420
Merged
sre-ci-robot
merged 12 commits into
milvus-io:master
from
xiaocai2333:update_sync_segments
May 30, 2024
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
064f89b
Periodically synchronize segment to datanode
xiaocai2333 9d2e4d4
fix checker
xiaocai2333 1c64f3c
fix collection info is nil
xiaocai2333 75af257
remove unused code
xiaocai2333 6c068ae
skip sync empty segment
xiaocai2333 5ebd62a
update
xiaocai2333 782b948
fix ut
xiaocai2333 70b4942
fix comment
xiaocai2333 9a53916
fix checker
xiaocai2333 786281d
fix comment
xiaocai2333 5afdb7b
fix ut
xiaocai2333 36e1504
use Rlock instead of Lock
xiaocai2333 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
// Licensed to the LF AI & Data foundation under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package datacoord | ||
|
||
import ( | ||
"sync" | ||
"time" | ||
|
||
"github.com/samber/lo" | ||
"go.uber.org/zap" | ||
|
||
"github.com/milvus-io/milvus/internal/proto/datapb" | ||
"github.com/milvus-io/milvus/pkg/log" | ||
"github.com/milvus-io/milvus/pkg/util/logutil" | ||
"github.com/milvus-io/milvus/pkg/util/typeutil" | ||
) | ||
|
||
type SyncSegmentsScheduler struct { | ||
quit chan struct{} | ||
wg sync.WaitGroup | ||
|
||
meta *meta | ||
channelManager ChannelManager | ||
sessions SessionManager | ||
} | ||
|
||
func newSyncSegmentsScheduler(m *meta, channelManager ChannelManager, sessions SessionManager) *SyncSegmentsScheduler { | ||
return &SyncSegmentsScheduler{ | ||
quit: make(chan struct{}), | ||
wg: sync.WaitGroup{}, | ||
meta: m, | ||
channelManager: channelManager, | ||
sessions: sessions, | ||
} | ||
} | ||
|
||
func (sss *SyncSegmentsScheduler) Start() { | ||
sss.quit = make(chan struct{}) | ||
sss.wg.Add(1) | ||
|
||
go func() { | ||
defer logutil.LogPanic() | ||
ticker := time.NewTicker(Params.DataCoordCfg.SyncSegmentsInterval.GetAsDuration(time.Second)) | ||
defer sss.wg.Done() | ||
|
||
for { | ||
select { | ||
case <-sss.quit: | ||
log.Info("sync segments scheduler quit") | ||
ticker.Stop() | ||
return | ||
case <-ticker.C: | ||
sss.SyncSegmentsForCollections() | ||
} | ||
} | ||
}() | ||
log.Info("SyncSegmentsScheduler started...") | ||
} | ||
|
||
func (sss *SyncSegmentsScheduler) Stop() { | ||
close(sss.quit) | ||
sss.wg.Wait() | ||
} | ||
|
||
func (sss *SyncSegmentsScheduler) SyncSegmentsForCollections() { | ||
collIDs := sss.meta.ListCollections() | ||
for _, collID := range collIDs { | ||
collInfo := sss.meta.GetCollection(collID) | ||
if collInfo == nil { | ||
log.Warn("collection info is nil, skip it", zap.Int64("collectionID", collID)) | ||
continue | ||
} | ||
pkField, err := typeutil.GetPrimaryFieldSchema(collInfo.Schema) | ||
if err != nil { | ||
log.Warn("get primary field from schema failed", zap.Int64("collectionID", collID), | ||
zap.Error(err)) | ||
continue | ||
} | ||
for _, channelName := range collInfo.VChannelNames { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can execute concurrently at the channel level? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thinks it's no necessary. I already add the concurrently for load pk in datanode. |
||
nodeID, err := sss.channelManager.FindWatcher(channelName) | ||
if err != nil { | ||
log.Warn("find watcher for channel failed", zap.Int64("collectionID", collID), | ||
zap.String("channelName", channelName), zap.Error(err)) | ||
continue | ||
} | ||
for _, partitionID := range collInfo.Partitions { | ||
if err := sss.SyncSegments(collID, partitionID, channelName, nodeID, pkField.GetFieldID()); err != nil { | ||
log.Warn("sync segment with channel failed, retry next ticker", | ||
zap.Int64("collectionID", collID), | ||
zap.Int64("partitionID", partitionID), | ||
zap.String("channel", channelName), | ||
zap.Error(err)) | ||
continue | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
func (sss *SyncSegmentsScheduler) SyncSegments(collectionID, partitionID int64, channelName string, nodeID, pkFieldID int64) error { | ||
log := log.With(zap.Int64("collectionID", collectionID), zap.Int64("partitionID", partitionID), | ||
zap.String("channelName", channelName), zap.Int64("nodeID", nodeID)) | ||
segments := sss.meta.SelectSegments(WithChannel(channelName), SegmentFilterFunc(func(info *SegmentInfo) bool { | ||
return info.GetPartitionID() == partitionID && isSegmentHealthy(info) | ||
})) | ||
req := &datapb.SyncSegmentsRequest{ | ||
ChannelName: channelName, | ||
PartitionId: partitionID, | ||
CollectionId: collectionID, | ||
SegmentInfos: make(map[int64]*datapb.SyncSegmentInfo), | ||
} | ||
|
||
for _, seg := range segments { | ||
for _, statsLog := range seg.GetStatslogs() { | ||
if statsLog.GetFieldID() == pkFieldID { | ||
req.SegmentInfos[seg.ID] = &datapb.SyncSegmentInfo{ | ||
SegmentId: seg.GetID(), | ||
PkStatsLog: statsLog, | ||
State: seg.GetState(), | ||
Level: seg.GetLevel(), | ||
NumOfRows: seg.GetNumOfRows(), | ||
} | ||
} | ||
} | ||
} | ||
|
||
if err := sss.sessions.SyncSegments(nodeID, req); err != nil { | ||
log.Warn("fail to sync segments with node", zap.Error(err)) | ||
return err | ||
} | ||
log.Info("sync segments success", zap.Int64s("segments", lo.Map(segments, func(t *SegmentInfo, i int) int64 { | ||
return t.GetID() | ||
}))) | ||
return nil | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this