Skip to content

Commit

Permalink
ignore all error for views in engine reload (#13590)
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
  • Loading branch information
harshit-gangal committed Jul 25, 2023
1 parent 5fcbf9e commit 4e78b07
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
15 changes: 2 additions & 13 deletions go/vt/vttablet/tabletserver/schema/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"strings"
Expand All @@ -31,7 +30,6 @@ import (

"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/vt/concurrency"
"vitess.io/vitess/go/vt/mysqlctl"
"vitess.io/vitess/go/vt/mysqlctl/tmutils"
"vitess.io/vitess/go/vt/sidecardb"

Expand Down Expand Up @@ -503,17 +501,8 @@ func (se *Engine) reload(ctx context.Context, includeStats bool) error {
tableType := row[1].String()
table, err := LoadTable(conn, se.cp.DBName(), tableName, tableType, row[3].ToString())
if err != nil {
isView := strings.Contains(tableType, tmutils.TableView)
var emptyColumnsError mysqlctl.EmptyColumnsErr
if errors.As(err, &emptyColumnsError) && isView {
log.Warningf("Failed reading schema for the table: %s, error: %v", tableName, err)
continue
}
sqlErr, isSQLErr := mysql.NewSQLErrorFromError(err).(*mysql.SQLError)
if isSQLErr && sqlErr != nil && sqlErr.Number() == mysql.ERNoSuchUser && isView {
// A VIEW that has an invalid DEFINER, leading to:
// ERROR 1449 (HY000): The user specified as a definer (...) does not exist
log.Warningf("Failed reading schema for the table: %s, error: %v", tableName, err)
if isView := strings.Contains(tableType, tmutils.TableView); isView {
log.Warningf("Failed reading schema for the view: %s, error: %v", tableName, err)
continue
}
// Non recoverable error:
Expand Down
38 changes: 37 additions & 1 deletion go/vt/vttablet/tabletserver/schema/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,46 @@ func TestOpenFailedDueToLoadTableErr(t *testing.T) {

logs := tl.GetAllLogs()
logOutput := strings.Join(logs, ":::")
assert.Contains(t, logOutput, "WARNING:Failed reading schema for the table: test_view")
assert.Contains(t, logOutput, "WARNING:Failed reading schema for the view: test_view")
assert.Contains(t, logOutput, "The user specified as a definer ('root'@'%') does not exist (errno 1449) (sqlstate HY000)")
}

// TestOpenNoErrorDueToInvalidViews tests that schema engine load does not fail instead should log the failures for the views
func TestOpenNoErrorDueToInvalidViews(t *testing.T) {
tl := syslogger.NewTestLogger()
defer tl.Close()
db := fakesqldb.New(t)
defer db.Close()
schematest.AddDefaultQueries(db)
db.AddQueryPattern(baseShowTablesPattern, &sqltypes.Result{
Fields: mysql.BaseShowTablesFields,
Rows: [][]sqltypes.Value{
mysql.BaseShowTablesRow("foo_view", true, "VIEW"),
mysql.BaseShowTablesRow("bar_view", true, "VIEW"),
},
})

// adding column query for table_view
db.AddQueryPattern(fmt.Sprintf(mysql.GetColumnNamesQueryPatternForTable, "foo_view"),
&sqltypes.Result{})
db.AddQueryPattern(fmt.Sprintf(mysql.GetColumnNamesQueryPatternForTable, "bar_view"),
sqltypes.MakeTestResult(sqltypes.MakeTestFields("column_name", "varchar"), "col1", "col2"))
// rejecting the impossible query
db.AddRejectedQuery("SELECT `col1`, `col2` FROM `fakesqldb`.`bar_view` WHERE 1 != 1", mysql.NewSQLError(mysql.ERWrongFieldWithGroup, mysql.SSClientError, "random error for table bar_view"))

AddFakeInnoDBReadRowsResult(db, 0)
se := newEngine(10, 1*time.Second, 1*time.Second, 0, db)
err := se.Open()
require.NoError(t, err)

logs := tl.GetAllLogs()
logOutput := strings.Join(logs, ":::")
assert.Contains(t, logOutput, "WARNING:Failed reading schema for the view: foo_view")
assert.Contains(t, logOutput, "unable to get columns for table fakesqldb.foo_view")
assert.Contains(t, logOutput, "WARNING:Failed reading schema for the view: bar_view")
assert.Contains(t, logOutput, "random error for table bar_view")
}

func TestExportVars(t *testing.T) {
db := fakesqldb.New(t)
defer db.Close()
Expand Down

0 comments on commit 4e78b07

Please sign in to comment.