From 31f8b03e39a5a91b7bce7b077cb9e4d7c5f6e5dd Mon Sep 17 00:00:00 2001 From: Harshit Gangal Date: Mon, 24 Jul 2023 20:47:54 +0530 Subject: [PATCH 1/2] ignore all error for views in engine reload (#13590) Signed-off-by: Harshit Gangal --- go/vt/vttablet/tabletserver/schema/engine.go | 15 +------- .../tabletserver/schema/engine_test.go | 38 ++++++++++++++++++- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/go/vt/vttablet/tabletserver/schema/engine.go b/go/vt/vttablet/tabletserver/schema/engine.go index 81f10235727..e29c57bbd73 100644 --- a/go/vt/vttablet/tabletserver/schema/engine.go +++ b/go/vt/vttablet/tabletserver/schema/engine.go @@ -20,7 +20,6 @@ import ( "bytes" "context" "encoding/json" - "errors" "fmt" "net/http" "strings" @@ -29,7 +28,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" @@ -461,17 +459,8 @@ func (se *Engine) reload(ctx context.Context, includeStats bool) error { tableType := row[1].String() table, err := LoadTable(conn, se.cp.DBName(), tableName, 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: diff --git a/go/vt/vttablet/tabletserver/schema/engine_test.go b/go/vt/vttablet/tabletserver/schema/engine_test.go index 29a74a28021..bf3d6666b33 100644 --- a/go/vt/vttablet/tabletserver/schema/engine_test.go +++ b/go/vt/vttablet/tabletserver/schema/engine_test.go @@ -454,10 +454,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() From 173024cdf7c424db216889be69be94d3efab58a8 Mon Sep 17 00:00:00 2001 From: Harshit Gangal Date: Tue, 25 Jul 2023 17:54:08 +0530 Subject: [PATCH 2/2] fix unit test Signed-off-by: Harshit Gangal --- go/vt/vttablet/tabletserver/schema/engine_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/vt/vttablet/tabletserver/schema/engine_test.go b/go/vt/vttablet/tabletserver/schema/engine_test.go index bf3d6666b33..79f3bf5d3b7 100644 --- a/go/vt/vttablet/tabletserver/schema/engine_test.go +++ b/go/vt/vttablet/tabletserver/schema/engine_test.go @@ -482,7 +482,7 @@ func TestOpenNoErrorDueToInvalidViews(t *testing.T) { 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) + se := newEngine(10, 1*time.Second, 1*time.Second, db) err := se.Open() require.NoError(t, err)