-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
br: reused table id is disabled when restore a brand-new cluster #41358
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
50acd22
fix: reused table id been disabled
fengou1 139f65f
fix: remove unused test help function
fengou1 ac617af
fix: remove unused help function
fengou1 6e0008f
revert a commit
fengou1 0d85974
Update br/pkg/gluetidb/glue_test.go
fengou1 effff38
update bazel and add some comments
fengou1 fc757f1
fix: drop test table in case of tables existed.
fengou1 dd7388a
fix: remove optional parameter and enhance unit test cases
fengou1 d114b7c
fix: add compile check and update funciton signature
fengou1 a8dc751
fix: add a fail point and new unit test
fengou1 bd2de8a
fix: move failpoint to ddl package
fengou1 31fd37f
fix: add reused table id check
fengou1 7ff7752
fix: add a new failure case
fengou1 a4e8c59
fix: linter issue
fengou1 84575c9
fix: remove empty line
fengou1 4694132
fix: update bazel
fengou1 594db2b
fix: update bazel
fengou1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
// Copyright 2023 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package gluetidb | ||
|
||
import ( | ||
"context" | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/pingcap/failpoint" | ||
"github.com/pingcap/tidb/ddl" | ||
"github.com/pingcap/tidb/kv" | ||
"github.com/pingcap/tidb/meta" | ||
"github.com/pingcap/tidb/parser/model" | ||
"github.com/pingcap/tidb/sessionctx" | ||
"github.com/pingcap/tidb/testkit" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// batch create table with table id reused | ||
func TestSplitBatchCreateTableWithTableId(t *testing.T) { | ||
store, dom := testkit.CreateMockStoreAndDomain(t) | ||
tk := testkit.NewTestKit(t, store) | ||
tk.MustExec("use test") | ||
tk.MustExec("drop table if exists table_id_resued1") | ||
tk.MustExec("drop table if exists table_id_resued2") | ||
tk.MustExec("drop table if exists table_id_new") | ||
|
||
d := dom.DDL() | ||
require.NotNil(t, d) | ||
|
||
infos1 := []*model.TableInfo{} | ||
infos1 = append(infos1, &model.TableInfo{ | ||
ID: 124, | ||
Name: model.NewCIStr("table_id_resued1"), | ||
}) | ||
infos1 = append(infos1, &model.TableInfo{ | ||
ID: 125, | ||
Name: model.NewCIStr("table_id_resued2"), | ||
}) | ||
|
||
se := &tidbSession{se: tk.Session()} | ||
|
||
// keep/reused table id verification | ||
tk.Session().SetValue(sessionctx.QueryString, "skip") | ||
err := se.SplitBatchCreateTable(model.NewCIStr("test"), infos1, ddl.AllocTableIDIf(func(ti *model.TableInfo) bool { | ||
return false | ||
})) | ||
require.NoError(t, err) | ||
|
||
tk.MustQuery("select tidb_table_id from information_schema.tables where table_name = 'table_id_resued1'").Check(testkit.Rows("124")) | ||
tk.MustQuery("select tidb_table_id from information_schema.tables where table_name = 'table_id_resued2'").Check(testkit.Rows("125")) | ||
ctx := kv.WithInternalSourceType(context.Background(), kv.InternalTxnOthers) | ||
|
||
// allocate new table id verification | ||
// query the global id | ||
var id int64 | ||
err = kv.RunInNewTxn(ctx, store, true, func(_ context.Context, txn kv.Transaction) error { | ||
m := meta.NewMeta(txn) | ||
var err error | ||
id, err = m.GenGlobalID() | ||
return err | ||
}) | ||
|
||
require.NoError(t, err) | ||
|
||
infos2 := []*model.TableInfo{} | ||
infos2 = append(infos2, &model.TableInfo{ | ||
ID: 124, | ||
Name: model.NewCIStr("table_id_new"), | ||
}) | ||
|
||
tk.Session().SetValue(sessionctx.QueryString, "skip") | ||
err = se.SplitBatchCreateTable(model.NewCIStr("test"), infos2, ddl.AllocTableIDIf(func(ti *model.TableInfo) bool { | ||
fengou1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return true | ||
})) | ||
require.NoError(t, err) | ||
|
||
idGen, ok := tk.MustQuery("select tidb_table_id from information_schema.tables where table_name = 'table_id_new'").Rows()[0][0].(string) | ||
require.True(t, ok) | ||
idGenNum, err := strconv.ParseInt(idGen, 10, 64) | ||
require.NoError(t, err) | ||
require.Greater(t, idGenNum, id) | ||
|
||
// a empty table info with len(info3) = 0 | ||
infos3 := []*model.TableInfo{} | ||
|
||
err = se.SplitBatchCreateTable(model.NewCIStr("test"), infos3, ddl.AllocTableIDIf(func(ti *model.TableInfo) bool { | ||
return false | ||
})) | ||
require.NoError(t, err) | ||
} | ||
|
||
// batch create table with table id reused | ||
func TestSplitBatchCreateTable(t *testing.T) { | ||
store, dom := testkit.CreateMockStoreAndDomain(t) | ||
tk := testkit.NewTestKit(t, store) | ||
tk.MustExec("use test") | ||
tk.MustExec("drop table if exists table_1") | ||
tk.MustExec("drop table if exists table_2") | ||
tk.MustExec("drop table if exists table_3") | ||
|
||
d := dom.DDL() | ||
require.NotNil(t, d) | ||
|
||
infos := []*model.TableInfo{} | ||
infos = append(infos, &model.TableInfo{ | ||
ID: 1234, | ||
Name: model.NewCIStr("tables_1"), | ||
}) | ||
infos = append(infos, &model.TableInfo{ | ||
ID: 1235, | ||
Name: model.NewCIStr("tables_2"), | ||
}) | ||
infos = append(infos, &model.TableInfo{ | ||
ID: 1236, | ||
Name: model.NewCIStr("tables_3"), | ||
}) | ||
|
||
se := &tidbSession{se: tk.Session()} | ||
|
||
// keep/reused table id verification | ||
tk.Session().SetValue(sessionctx.QueryString, "skip") | ||
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/ddl/RestoreBatchCreateTableEntryTooLarge", "return(1)")) | ||
err := se.SplitBatchCreateTable(model.NewCIStr("test"), infos, ddl.AllocTableIDIf(func(ti *model.TableInfo) bool { | ||
return false | ||
})) | ||
|
||
require.NoError(t, err) | ||
tk.MustQuery("show tables like '%tables_%'").Check(testkit.Rows("tables_1", "tables_2", "tables_3")) | ||
jobs := tk.MustQuery("admin show ddl jobs").Rows() | ||
require.Greater(t, len(jobs), 3) | ||
// check table_1 | ||
job1 := jobs[0] | ||
require.Equal(t, "test", job1[1]) | ||
require.Equal(t, "tables_3", job1[2]) | ||
require.Equal(t, "create tables", job1[3]) | ||
require.Equal(t, "public", job1[4]) | ||
|
||
// check table_2 | ||
job2 := jobs[1] | ||
require.Equal(t, "test", job2[1]) | ||
require.Equal(t, "tables_2", job2[2]) | ||
require.Equal(t, "create tables", job2[3]) | ||
require.Equal(t, "public", job2[4]) | ||
|
||
// check table_3 | ||
job3 := jobs[2] | ||
require.Equal(t, "test", job3[1]) | ||
require.Equal(t, "tables_1", job3[2]) | ||
require.Equal(t, "create tables", job3[3]) | ||
require.Equal(t, "public", job3[4]) | ||
|
||
// check reused table id | ||
tk.MustQuery("select tidb_table_id from information_schema.tables where table_name = 'tables_1'").Check(testkit.Rows("1234")) | ||
tk.MustQuery("select tidb_table_id from information_schema.tables where table_name = 'tables_2'").Check(testkit.Rows("1235")) | ||
tk.MustQuery("select tidb_table_id from information_schema.tables where table_name = 'tables_3'").Check(testkit.Rows("1236")) | ||
|
||
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/ddl/RestoreBatchCreateTableEntryTooLarge")) | ||
} | ||
|
||
// batch create table with table id reused | ||
func TestSplitBatchCreateTableFailWithEntryTooLarge(t *testing.T) { | ||
store, dom := testkit.CreateMockStoreAndDomain(t) | ||
tk := testkit.NewTestKit(t, store) | ||
tk.MustExec("use test") | ||
tk.MustExec("drop table if exists table_1") | ||
tk.MustExec("drop table if exists table_2") | ||
tk.MustExec("drop table if exists table_3") | ||
|
||
d := dom.DDL() | ||
require.NotNil(t, d) | ||
|
||
infos := []*model.TableInfo{} | ||
infos = append(infos, &model.TableInfo{ | ||
Name: model.NewCIStr("tables_1"), | ||
}) | ||
infos = append(infos, &model.TableInfo{ | ||
Name: model.NewCIStr("tables_2"), | ||
}) | ||
infos = append(infos, &model.TableInfo{ | ||
Name: model.NewCIStr("tables_3"), | ||
}) | ||
|
||
se := &tidbSession{se: tk.Session()} | ||
|
||
tk.Session().SetValue(sessionctx.QueryString, "skip") | ||
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/ddl/RestoreBatchCreateTableEntryTooLarge", "return(0)")) | ||
err := se.SplitBatchCreateTable(model.NewCIStr("test"), infos, ddl.AllocTableIDIf(func(ti *model.TableInfo) bool { | ||
return true | ||
})) | ||
|
||
require.True(t, kv.ErrEntryTooLarge.Equal(err)) | ||
|
||
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/ddl/RestoreBatchCreateTableEntryTooLarge")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and also add a case that
len(infos)==0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add new case in dd7388a