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 authored Jul 24, 2023
1 parent 0d0ada9 commit 4416975
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 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 @@ -500,17 +498,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
21 changes: 14 additions & 7 deletions go/vt/vttablet/tabletserver/schema/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,12 @@ 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)")
}

// TestOpenFailedDueToEmptyColumnInView tests that schema engine load should not fail instead should log the failures for empty columns in view
func TestOpenFailedDueToEmptyColumnInView(t *testing.T) {
// 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)
Expand All @@ -471,13 +471,18 @@ func TestOpenFailedDueToEmptyColumnInView(t *testing.T) {
db.AddQueryPattern(baseShowTablesPattern, &sqltypes.Result{
Fields: mysql.BaseShowTablesFields,
Rows: [][]sqltypes.Value{
mysql.BaseShowTablesRow("test_view", true, "VIEW"),
mysql.BaseShowTablesRow("foo_view", true, "VIEW"),
mysql.BaseShowTablesRow("bar_view", true, "VIEW"),
},
})

// adding column query for table_view
db.AddQueryPattern(fmt.Sprintf(mysql.GetColumnNamesQueryPatternForTable, "test_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)
Expand All @@ -486,8 +491,10 @@ func TestOpenFailedDueToEmptyColumnInView(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, "unable to get columns for table fakesqldb.test_view")
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) {
Expand Down

0 comments on commit 4416975

Please sign in to comment.