diff --git a/go/vt/discovery/healthcheck.go b/go/vt/discovery/healthcheck.go index e6f37e6af33..430b05b18c1 100644 --- a/go/vt/discovery/healthcheck.go +++ b/go/vt/discovery/healthcheck.go @@ -386,8 +386,8 @@ func (hc *HealthCheckImpl) deleteTablet(tablet *topodata.Tablet) { log.Infof("We have no health data for tablet: %v, it might have been deleted already", tabletAlias) return } - // calling this will end the context associated with th.checkConn - // which will call finalizeConn, which will close the connection + // Calling this will end the context associated with th.checkConn, + // which will call finalizeConn, which will close the connection. th.cancelFunc() delete(hc.healthByAlias, tabletAlias) // delete from map by keyspace.shard.tabletType @@ -442,24 +442,27 @@ func (hc *HealthCheckImpl) updateHealth(th *TabletHealth, shr *query.StreamHealt } } if !trivialNonMasterUpdate { - if shr.Target.TabletType != topodata.TabletType_MASTER { + // We re-sort the healthy tablet list whenever we get a health update for tablets we can route to. + // Tablets from other cells for non-master targets should not trigger a re-sort; + // they should also be excluded from healthy list. + if shr.Target.TabletType != topodata.TabletType_MASTER && hc.isIncluded(shr.Target.TabletType, shr.TabletAlias) { all := hc.healthData[targetKey] allArray := make([]*TabletHealth, 0, len(all)) for _, s := range all { - // only tablets in same cell / cellAlias are included in healthy list - if hc.isIncluded(shr) { + // Only tablets in same cell / cellAlias are included in healthy list. + if hc.isIncluded(s.Tablet.Type, s.Tablet.Alias) { allArray = append(allArray, s) } } hc.healthy[targetKey] = FilterStatsByReplicationLag(allArray) } - if targetChanged && currentTarget.TabletType != topodata.TabletType_MASTER { // also recompute old target's healthy list + if targetChanged && currentTarget.TabletType != topodata.TabletType_MASTER && hc.isIncluded(shr.Target.TabletType, shr.TabletAlias) { // also recompute old target's healthy list oldTargetKey := hc.keyFromTarget(currentTarget) all := hc.healthData[oldTargetKey] allArray := make([]*TabletHealth, 0, len(all)) for _, s := range all { - // only tablets in same cell / cellAlias are included in healthy list - if hc.isIncluded(shr) { + // Only tablets in same cell / cellAlias are included in healthy list. + if hc.isIncluded(s.Tablet.Type, s.Tablet.Alias) { allArray = append(allArray, s) } } @@ -686,14 +689,14 @@ func (hc *HealthCheckImpl) getAliasByCell(cell string) string { return alias } -func (hc *HealthCheckImpl) isIncluded(shr *query.StreamHealthResponse) bool { - if shr.Target.TabletType == topodata.TabletType_MASTER { +func (hc *HealthCheckImpl) isIncluded(tabletType topodata.TabletType, tabletAlias *topodata.TabletAlias) bool { + if tabletType == topodata.TabletType_MASTER { return true } - if shr.TabletAlias.Cell == hc.cell { + if tabletAlias.Cell == hc.cell { return true } - if hc.getAliasByCell(shr.TabletAlias.Cell) == hc.getAliasByCell(hc.cell) { + if hc.getAliasByCell(tabletAlias.Cell) == hc.getAliasByCell(hc.cell) { return true } return false