You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
After #5245, we may run into a corner case that storage.schema_version > TiDBSchemaSyncer.cur_version.
Background:
After the feature concurrent DDL, TiDB does update schema version before set schema diff, and they are done in separate transactions.
So TiFlash may see a schema version X but no schema diff X, meaning that the transaction of schema diff X has not been committed or has been aborted.
However, TiDB makes sure that if we get a schema version X, then the schema diff X-1 must exist. Otherwise the transaction of schema diff X-1 is aborted and we can safely ignore it.
Since TiDB can not make sure the schema diff of the latest schema version X is not empty, under this situation we should set the cur_version to X-1 and try to fetch the schema diff X next time.
However, even if the last schema diff X is empty, the schema builder is now still constructed with X but not X-1. So we will update table.schema_version to X but TiDBSchemaSyncer.cur_version to X-1. That will make some queries fail unexpectedly.
For tryLoadSchemaDiffs
We should first fetch the schema diff and check whether the schema diff of X is empty or not before creating the SchemaBuilder instance. If the schema diff of X is empty, we should set SchemaBuilder.target_version to be X-1
For loadAllSchema
We should check the diff by getter.checkSchemaDiffExists before creating the SchemaBuilder instance. Not do the check after loadAllSchema is done.
And we should add some unit test cases
3. What did you see instead (Required)
4. What is your TiFlash version? (Required)
master
The text was updated successfully, but these errors were encountered:
As the time span between update schema version and set schema diff is relative small (usually less than 50ms), and user can workaround this bug by creating an empty table. Mark this bug to be moderate.
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
After #5245, we may run into a corner case that storage.schema_version > TiDBSchemaSyncer.cur_version.
Background:
After the feature concurrent DDL, TiDB does
update schema version
beforeset schema diff
, and they are done in separate transactions.So TiFlash may see a schema version X but no schema diff X, meaning that the transaction of schema diff X has not been committed or has been aborted.
However, TiDB makes sure that if we get a schema version X, then the schema diff X-1 must exist. Otherwise the transaction of schema diff X-1 is aborted and we can safely ignore it.
Since TiDB can not make sure the schema diff of the latest schema version X is not empty, under this situation we should set the
cur_version
to X-1 and try to fetch the schema diff X next time.However, even if the last schema diff X is empty, the schema builder is now still constructed with X but not X-1. So we will update table.schema_version to X but TiDBSchemaSyncer.cur_version to X-1. That will make some queries fail unexpectedly.
tiflash/dbms/src/TiDB/Schema/TiDBSchemaSyncer.h
Lines 170 to 181 in 7099184
tiflash/dbms/src/TiDB/Schema/TiDBSchemaSyncer.h
Lines 248 to 252 in 7099184
Codes snippets for updating storage.table_info.schema_version
tiflash/dbms/src/TiDB/Schema/SchemaBuilder.h
Lines 38 to 44 in 7099184
tiflash/dbms/src/TiDB/Schema/SchemaBuilder.cpp
Lines 383 to 384 in 7099184
tiflash/dbms/src/TiDB/Schema/SchemaBuilder.cpp
Lines 1061 to 1062 in 7099184
2. What did you expect to see? (Required)
tryLoadSchemaDiffs
We should first fetch the schema diff and check whether the schema diff of X is empty or not before creating the
SchemaBuilder
instance. If the schema diff of X is empty, we should setSchemaBuilder.target_version
to be X-1loadAllSchema
We should check the diff by
getter.checkSchemaDiffExists
before creating theSchemaBuilder
instance. Not do the check afterloadAllSchema
is done.And we should add some unit test cases
3. What did you see instead (Required)
4. What is your TiFlash version? (Required)
master
The text was updated successfully, but these errors were encountered: