Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Report: Mysqld.GetSchema() race condition when table is dropped throughout inspection #12640

Closed
shlomi-noach opened this issue Mar 16, 2023 · 1 comment · Fixed by #12641

Comments

@shlomi-noach
Copy link
Contributor

shlomi-noach commented Mar 16, 2023

Overview of the Issue

Mysqld.GetSchema() is susceptible to two race conditions. One leading to a Table X doesn't exist (errno 1146) error, and the other to silent missing PK information.

The race conditions both happen when a table is dropped after the initial call to collectBasicData():

tds, err := mysqld.collectBasicTableData(ctx, dbName, request.Tables, request.ExcludeTables, request.IncludeViews)

1st race condition: a table is dropped right after this query, and before iterating the table for collectSchema()/.GetColumns():

fields, columns, schema, err := mysqld.collectSchema(ctx, dbName, td.Name, td.Type, request.TableSchemaOnly)

in this scenario, we get a Table X doesn't exist (errno 1146), because we actively SELECT from the table that is now dropped.

2nd race condition: a table is dropped right before analyzing primary keys:

colMap, err = mysqld.getPrimaryKeyColumns(ctx, dbName, tableNames...)

In this scenario, there's no error here, because we get PK information from information_schema. But we will have missing data in the table definition (nil value for PrimaryKeyColumns).

Either way, it's valid for a table to be dropped during this time. The fix is to identify that a table has been dropped, and silently ignore such table.


This affects anything that attempts to ReloadSchema, which means any VReplication or Online DDL operations.

Reproduction Steps

Binary Version

-

Operating System and Environment details

-

Log Fragments

No response

@shlomi-noach
Copy link
Contributor Author

The 2nd race condition holds true, but identifying it is a bit more complex. The fact that a table does not appear in INFORMATION_SCHEMA.STATISTICS does not mean the table does not exist - it may exist and have no indexes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants