Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions go/vt/discovery/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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
Expand Down