Skip to content

Commit

Permalink
Mysqld.GetSchema: tolerate tables being dropped while inspecting sche…
Browse files Browse the repository at this point in the history
…ma (vitessio#12641)

* Mysqld.GetSchema: tolerate tables being dropped while inspecting schema

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>

* lack of primary key columns in STATISTICS does not mean table is dropped. It can also mean the table does not have PRIMARY KEY

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>

* populate validTds rather than rely on nil hints

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>

* re-introdce earlier check

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>

* use validTds, sync

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>

* due to many tests consistently failing, trying a different approach: we keep the table, but with empty column/key/fields info

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>

* grammar

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>

---------

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
  • Loading branch information
shlomi-noach committed Mar 20, 2023
1 parent c1d8c14 commit 5e5f3b4
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions go/vt/mysqlctl/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"strings"
"sync"

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/vt/concurrency"
"vitess.io/vitess/go/vt/vterrors"
Expand Down Expand Up @@ -109,6 +110,15 @@ func (mysqld *Mysqld) GetSchema(ctx context.Context, dbName string, request *tab

fields, columns, schema, err := mysqld.collectSchema(ctx, dbName, td.Name, td.Type, request.TableSchemaOnly)
if err != nil {
// There's a possible race condition: it could happen that a table was dropped in between reading
// the list of tables (collectBasicTableData(), earlier) and the point above where we investigate
// the table.
// This is fine. We identify the situation and keep the table without any fields/columns/key information
sqlErr, isSQLErr := mysql.NewSQLErrorFromError(err).(*mysql.SQLError)
if isSQLErr && sqlErr != nil && sqlErr.Number() == mysql.ERNoSuchTable {
return
}

allErrors.RecordError(err)
cancel()
return
Expand All @@ -121,6 +131,8 @@ func (mysqld *Mysqld) GetSchema(ctx context.Context, dbName string, request *tab
}

// Get primary columns concurrently.
// The below runs a single query on `INFORMATION_SCHEMA` and does not interact with the actual tables.
// It is therefore safe to run even if some tables are dropped in the interim.
colMap := map[string][]string{}
if len(tableNames) > 0 {
wg.Add(1)
Expand Down

0 comments on commit 5e5f3b4

Please sign in to comment.