Skip to content

Commit

Permalink
etcdutil: return original enpoints when all are evicted (#7779)
Browse files Browse the repository at this point in the history
ref #7499, ref #7730

Return the originally picked endpoints directly if all are evicted to gain better availability.

Signed-off-by: JmPotato <ghzpotato@gmail.com>
  • Loading branch information
JmPotato committed Jan 31, 2024
1 parent 1c54865 commit 357ad3f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
12 changes: 10 additions & 2 deletions pkg/utils/etcdutil/health_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (checker *healthChecker) syncer(ctx context.Context) {
for {
select {
case <-ctx.Done():
log.Info("etcd client is closed, exit update endpoint goroutine",
log.Info("etcd client is closed, exit the endpoint syncer goroutine",
zap.String("source", checker.source))
return
case <-ticker.C:
Expand All @@ -110,7 +110,7 @@ func (checker *healthChecker) inspector(ctx context.Context) {
for {
select {
case <-ctx.Done():
log.Info("etcd client is closed, exit health check goroutine",
log.Info("etcd client is closed, exit the health inspector goroutine",
zap.String("source", checker.source))
checker.close()
return
Expand Down 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 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 357ad3f

Please sign in to comment.