Skip to content

Commit

Permalink
Update recompute method and rename test case.
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schreiber <arthurschreiber@github.com>
  • Loading branch information
arthurschreiber authored and danieljoos committed Jul 12, 2024
1 parent 2a810d1 commit 1753623
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion go/vt/discovery/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion go/vt/discovery/healthcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1753623

Please sign in to comment.