Skip to content

Commit

Permalink
minimize logging of errors when loading keyspace
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <andres@planetscale.com>
  • Loading branch information
systay committed Oct 13, 2021
1 parent 90c2edb commit 6cb2ed2
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions go/vt/vtgate/schema/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package schema

import (
"context"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -52,6 +53,9 @@ type (
// map of keyspace currently tracked
tracked map[keyspaceStr]*updateController
consumeDelay time.Duration

// we'll only log a failed keyspace loading once
failedKeyspaces []string
}
)

Expand Down Expand Up @@ -128,14 +132,39 @@ func (t *Tracker) newUpdateController() *updateController {
}

func (t *Tracker) initKeyspace(th *discovery.TabletHealth) bool {
if t.isFailedKeyspace(th) {
return false
}

err := t.LoadKeyspace(th.Conn, th.Target)
if err != nil {
t.checkIfWeShouldFailKeyspace(th, err)
log.Warningf("Unable to add keyspace to tracker: %v", err)
return false
}
return true
}

// checkIfWeShouldFailKeyspace inspects an error and
// will mark a keyspace as failed and won't try to load more information from it
func (t *Tracker) checkIfWeShouldFailKeyspace(th *discovery.TabletHealth, err error) {
errMessage := err.Error()
if strings.Contains(errMessage, "Unknown database '") ||
strings.Contains(errMessage, "Table '_vt.schemacopy' doesn't exist") {
t.failedKeyspaces = append(t.failedKeyspaces, th.Target.Keyspace)
}
}

func (t *Tracker) isFailedKeyspace(th *discovery.TabletHealth) bool {
for _, keyspace := range t.failedKeyspaces {
if th.Target.Keyspace == keyspace {
// this keyspace is marked as failed. we are not going to reload
return true
}
}
return false
}

// Stop stops the schema tracking
func (t *Tracker) Stop() {
log.Info("Stopping schema tracking")
Expand Down

0 comments on commit 6cb2ed2

Please sign in to comment.