mirror of https://github.com/milvus-io/milvus.git
Fix GetShardLeader returns old leader (#22887)
Signed-off-by: yah01 <yang.cen@zilliz.com>pull/22900/head
parent
fd974df09f
commit
68b9cabb87
|
@ -195,10 +195,19 @@ func (dh *distHandler) updateLeaderView(resp *querypb.GetDataDistributionRespons
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var version int64
|
||||||
|
for _, channel := range resp.GetChannels() {
|
||||||
|
if channel.GetChannel() == lview.GetChannel() {
|
||||||
|
version = channel.GetVersion()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
view := &meta.LeaderView{
|
view := &meta.LeaderView{
|
||||||
ID: resp.GetNodeID(),
|
ID: resp.GetNodeID(),
|
||||||
CollectionID: lview.GetCollection(),
|
CollectionID: lview.GetCollection(),
|
||||||
Channel: lview.GetChannel(),
|
Channel: lview.GetChannel(),
|
||||||
|
Version: version,
|
||||||
Segments: lview.GetSegmentDist(),
|
Segments: lview.GetSegmentDist(),
|
||||||
GrowingSegments: segments,
|
GrowingSegments: segments,
|
||||||
}
|
}
|
||||||
|
|
|
@ -374,3 +374,31 @@ func checkNodeAvailable(nodeID int64, info *session.NodeInfo) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func filterDupLeaders(replicaManager *meta.ReplicaManager, leaders map[int64]*meta.LeaderView) map[int64]*meta.LeaderView {
|
||||||
|
type leaderID struct {
|
||||||
|
ReplicaID int64
|
||||||
|
Shard string
|
||||||
|
}
|
||||||
|
|
||||||
|
newLeaders := make(map[leaderID]*meta.LeaderView)
|
||||||
|
for _, view := range leaders {
|
||||||
|
replica := replicaManager.GetByCollectionAndNode(view.CollectionID, view.ID)
|
||||||
|
if replica == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
id := leaderID{replica.GetID(), view.Channel}
|
||||||
|
if old, ok := newLeaders[id]; ok && old.Version > view.Version {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
newLeaders[id] = view
|
||||||
|
}
|
||||||
|
|
||||||
|
result := make(map[int64]*meta.LeaderView)
|
||||||
|
for _, v := range newLeaders {
|
||||||
|
result[v.ID] = v
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ type LeaderView struct {
|
||||||
ID int64
|
ID int64
|
||||||
CollectionID int64
|
CollectionID int64
|
||||||
Channel string
|
Channel string
|
||||||
|
Version int64
|
||||||
Segments map[int64]*querypb.SegmentDist
|
Segments map[int64]*querypb.SegmentDist
|
||||||
GrowingSegments map[int64]*Segment
|
GrowingSegments map[int64]*Segment
|
||||||
}
|
}
|
||||||
|
@ -46,6 +47,7 @@ func (view *LeaderView) Clone() *LeaderView {
|
||||||
ID: view.ID,
|
ID: view.ID,
|
||||||
CollectionID: view.CollectionID,
|
CollectionID: view.CollectionID,
|
||||||
Channel: view.Channel,
|
Channel: view.Channel,
|
||||||
|
Version: view.Version,
|
||||||
Segments: segments,
|
Segments: segments,
|
||||||
GrowingSegments: growings,
|
GrowingSegments: growings,
|
||||||
}
|
}
|
||||||
|
|
|
@ -859,6 +859,7 @@ func (s *Server) GetShardLeaders(ctx context.Context, req *querypb.GetShardLeade
|
||||||
log := log.With(zap.String("channel", channel.GetChannelName()))
|
log := log.With(zap.String("channel", channel.GetChannelName()))
|
||||||
|
|
||||||
leaders := s.dist.LeaderViewManager.GetLeadersByShard(channel.GetChannelName())
|
leaders := s.dist.LeaderViewManager.GetLeadersByShard(channel.GetChannelName())
|
||||||
|
leaders = filterDupLeaders(s.meta.ReplicaManager, leaders)
|
||||||
ids := make([]int64, 0, len(leaders))
|
ids := make([]int64, 0, len(leaders))
|
||||||
addrs := make([]string, 0, len(leaders))
|
addrs := make([]string, 0, len(leaders))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue