From 175362338f6e6ea08391ba2d3faa92613da0b41b Mon Sep 17 00:00:00 2001 From: Arthur Schreiber Date: Fri, 12 Jul 2024 08:25:02 +0000 Subject: [PATCH] Update recompute method and rename test case. Signed-off-by: Arthur Schreiber --- go/vt/discovery/healthcheck.go | 9 ++++++++- go/vt/discovery/healthcheck_test.go | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/go/vt/discovery/healthcheck.go b/go/vt/discovery/healthcheck.go index 5bfed5bc485..ec54027a686 100644 --- a/go/vt/discovery/healthcheck.go +++ b/go/vt/discovery/healthcheck.go @@ -603,13 +603,20 @@ func (hc *HealthCheckImpl) recomputeHealthy(key KeyspaceShardTabletType) { // Recompute the healthy primary tablet for the given key. func (hc *HealthCheckImpl) recomputeHealthyPrimary(key KeyspaceShardTabletType) { highestPrimaryTermStartTime := int64(math.MinInt64) + var newestPrimary *TabletHealth for _, s := range hc.healthData[key] { if s.PrimaryTermStartTime >= highestPrimaryTermStartTime { highestPrimaryTermStartTime = s.PrimaryTermStartTime - hc.healthy[key][0] = s + newestPrimary = s } } + + if newestPrimary != nil { + hc.healthy[key] = []*TabletHealth{newestPrimary} + } else { + hc.healthy[key] = []*TabletHealth{} + } } // Subscribe adds a listener. Used by vtgate buffer to learn about primary changes. diff --git a/go/vt/discovery/healthcheck_test.go b/go/vt/discovery/healthcheck_test.go index 32f722cf13a..fd8f9910fcd 100644 --- a/go/vt/discovery/healthcheck_test.go +++ b/go/vt/discovery/healthcheck_test.go @@ -857,7 +857,7 @@ func TestRemoveTablet(t *testing.T) { // // During this time, operations like `RemoveTablet` should not lead // to multiple tablets becoming valid targets for `PRIMARY`. -func TestTabletRemoveDuringExternalReparenting(t *testing.T) { +func TestRemoveTabletDuringExternalReparenting(t *testing.T) { ctx := utils.LeakCheckContext(t) // reset error counters