fix: Check replica exists before get latest leader (#31848)

See also #31847

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
This commit is contained in:
congqixia 2024-04-03 10:05:22 +08:00 committed by GitHub
parent 7471a8005f
commit 56e371c478
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View File

@ -246,6 +246,9 @@ func (mgr *LeaderViewManager) GetLeadersByShard(shard string) map[int64]*LeaderV
}
func (mgr *LeaderViewManager) GetLatestLeadersByReplicaShard(replica *Replica, shard string) *LeaderView {
if replica == nil {
return nil
}
mgr.rwmutex.RLock()
defer mgr.rwmutex.RUnlock()

View File

@ -143,6 +143,15 @@ func (suite *LeaderViewManagerSuite) TestGetDist() {
suite.Len(segments, 1)
}
func (suite *LeaderViewManagerSuite) TestGetLatestLeadersByReplicaShard() {
suite.Run("replica_nil", func() {
suite.NotPanics(func() {
lv := suite.mgr.GetLatestLeadersByReplicaShard(nil, "")
suite.Nil(lv)
})
})
}
func (suite *LeaderViewManagerSuite) TestGetLeader() {
mgr := suite.mgr