Skip to content

Commit

Permalink
Improve logging and flip if/else for readability
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Nov 16, 2021
1 parent 17737ab commit 175f400
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions go/vt/discovery/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func (hc *HealthCheckImpl) deleteTablet(tablet *topodata.Tablet) {
// delete from authoritative map
th, ok := hc.healthByAlias[tabletAlias]
if !ok {
log.Infof("We have no health data for tablet: %v, it might have been deleted already", tabletAlias)
log.Infof("We have no health data for tablet: %v, it might have been deleted already", tablet)
return
}
// Calling this will end the context associated with th.checkConn,
Expand Down Expand Up @@ -421,7 +421,7 @@ func (hc *HealthCheckImpl) updateHealth(th *TabletHealth, prevTarget *query.Targ
// tablet record that was deleted
_, ok := hc.healthByAlias[tabletAlias]
if !ok {
log.Infof("Tablet %s has been deleted, skipping health update", tabletAlias)
log.Infof("Tablet %v has been deleted, skipping health update", th.Tablet)
return
}

Expand Down
11 changes: 7 additions & 4 deletions go/vt/discovery/tablet_health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,13 @@ func (thc *tabletHealthCheck) checkConn(hc *HealthCheckImpl) {

if err != nil {
hcErrorCounters.Add([]string{thc.Target.Keyspace, thc.Target.Shard, topoproto.TabletTypeLString(thc.Target.TabletType)}, 1)
// We have reason to suspect the tablet healthcheck record is corrupted or invalid so let's remove the tablet's record
// from the healthcheck cache and the corrected tablet record will be fetched from the topology and added to the
// healthcheck cache again via the topology watcher.
// This means that another tablet has taken over the host:port that we were connected to.
// So let's remove the tablet's data from the healthcheck, and if it is still a part of the
// cluster, the new tablet record will be fetched from the topology server and re-added to
// the healthcheck cache again via the topology watcher.
// WARNING: Under no other circumstances should we be deleting the tablet here.
if strings.Contains(err.Error(), "health stats mismatch") {
log.Warningf("deleting tablet %v from healthcheck due to health stats mismatch", thc.Tablet)
hc.deleteTablet(thc.Tablet)
return
}
Expand Down Expand Up @@ -329,7 +332,7 @@ func (thc *tabletHealthCheck) checkConn(hc *HealthCheckImpl) {
}

func (thc *tabletHealthCheck) closeConnection(ctx context.Context, err error) {
log.Warningf("tablet %v healthcheck stream error: %v", thc.Tablet.Alias, err)
log.Warningf("tablet %v healthcheck stream error: %v", thc.Tablet, err)
thc.setServingState(false, err.Error())
thc.LastError = err
_ = thc.Conn.Close(ctx)
Expand Down
13 changes: 7 additions & 6 deletions go/vt/discovery/topology_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,19 +216,20 @@ func (tw *TopologyWatcher) loadTablets() {

for alias, newVal := range newTablets {
// trust the alias from topo and add it if it doesn't exist
if val, ok := tw.tablets[alias]; !ok {
tw.tabletRecorder.AddTablet(newVal.tablet)
topologyWatcherOperations.Add(topologyWatcherOpAddTablet, 1)
} else {
// check if the host and port have changed. If yes, replace tablet
if val, ok := tw.tablets[alias]; ok {
// check if the host and port have changed. If yes, replace tablet.
oldKey := TabletToMapKey(val.tablet)
newKey := TabletToMapKey(newVal.tablet)
if oldKey != newKey {
// This is the case where the same tablet alias is now reporting
// a different address key.
// a different address (host:port) key.
tw.tabletRecorder.ReplaceTablet(val.tablet, newVal.tablet)
topologyWatcherOperations.Add(topologyWatcherOpReplaceTablet, 1)
}
} else {
// This is a new tablet record, let's add it to the healthcheck
tw.tabletRecorder.AddTablet(newVal.tablet)
topologyWatcherOperations.Add(topologyWatcherOpAddTablet, 1)
}
}

Expand Down

0 comments on commit 175f400

Please sign in to comment.