Skip to content

Commit

Permalink
Return original enpoints when all are evicted
Browse files Browse the repository at this point in the history
Signed-off-by: JmPotato <ghzpotato@gmail.com>
  • Loading branch information
JmPotato committed Jan 30, 2024
1 parent 1c54865 commit 5ba046f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
8 changes: 8 additions & 0 deletions pkg/utils/etcdutil/health_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,14 @@ func (checker *healthChecker) filterEps(eps []string) []string {
}
pickedEps = append(pickedEps, ep)
}
// If the pickedEps is empty, it means all endpoints are evicted,
// to gain a better availability, just use the original picked endpoints.
if len(pickedEps) == 0 {
log.Warn("all etcd endpoints are evicted, use the picked endpoints directly",
zap.Strings("endpoints", eps),
zap.String("source", checker.source))
return eps
}
return pickedEps
}

Expand Down
42 changes: 40 additions & 2 deletions pkg/utils/etcdutil/health_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,45 @@ func TestPickEps(t *testing.T) {
},
},
map[string]int{"A": 0, "B": 1, "C": 1, "D": 0},
[]string{},
[]string{"B", "C"},
},
// {B, C} -> {A, B, C}
{
[]healthProbe{
{
ep: "A",
took: time.Millisecond,
},
{
ep: "B",
took: time.Millisecond,
},
{
ep: "C",
took: time.Millisecond,
},
},
map[string]int{"A": 1, "B": 2, "C": 2, "D": 0},
[]string{"A", "B", "C"},
},
// {A, B, C} -> {A, C, E}
{
[]healthProbe{
{
ep: "A",
took: time.Millisecond,
},
{
ep: "C",
took: time.Millisecond,
},
{
ep: "E",
took: time.Millisecond,
},
},
map[string]int{"A": 2, "B": 0, "D": 0},
[]string{"C", "E"},
},
}
check(re, testCases)
Expand Down Expand Up @@ -318,7 +356,7 @@ func TestLatencyPick(t *testing.T) {
},
},
map[string]int{"A": 1, "B": 1, "C": 0},
[]string{},
[]string{"A", "B"},
},
}
check(re, testCases)
Expand Down

0 comments on commit 5ba046f

Please sign in to comment.