This repository has been archived by the owner on Nov 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 188
bug-fix: use table-info-before always and fix bug for recover lock in optimistic #1518
Merged
Merged
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
0dfad92
use tableInfoBefore instead of joined table
GMHDBJD 5101a9d
fix ut
GMHDBJD 60f5f43
Merge branch 'master' into useTableInfoBefore
GMHDBJD 08fe90f
add received
GMHDBJD 21d75d9
sort info by revision when recover
GMHDBJD 0325de4
add ut
GMHDBJD 1cd95d0
add more ut
GMHDBJD 0a67c32
join all infos and use table-info-before as table info
GMHDBJD f9153cd
Update pkg/terror/error_list.go
GMHDBJD cb236a0
rename revision
GMHDBJD bebd18b
rename test func
GMHDBJD 0196510
update errors
GMHDBJD 65bd0af
remove debug
GMHDBJD 2f5e68f
Merge branch 'master' into useTableInfoBefore
GMHDBJD ff42ec6
join all infos based on table-info-before if different
GMHDBJD 5e04e8f
Merge remote-tracking branch 'upstream/master' into useTableInfoBefore
GMHDBJD c660ba9
fix integration test
GMHDBJD 8450ef4
revert debug
GMHDBJD 814d7a7
address comment
GMHDBJD fb89276
Update tests/shardddl1/run.sh
GMHDBJD d274e6b
Merge branch 'master' into useTableInfoBefore
GMHDBJD fadfd2b
Merge branch 'master' into useTableInfoBefore
GMHDBJD 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
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 |
---|---|---|
|
@@ -23,6 +23,7 @@ import ( | |
"github.com/pingcap/parser/ast" | ||
"github.com/pingcap/parser/model" | ||
"github.com/pingcap/tidb-tools/pkg/dbutil" | ||
"github.com/pingcap/tidb-tools/pkg/schemacmp" | ||
tiddl "github.com/pingcap/tidb/ddl" | ||
"github.com/pingcap/tidb/sessionctx" | ||
"github.com/pingcap/tidb/util/mock" | ||
|
@@ -148,6 +149,7 @@ func (t *testOptimist) TestOptimist(c *C) { | |
t.testOptimist(c, noRestart) | ||
t.testOptimist(c, restartOnly) | ||
t.testOptimist(c, restartNewInstance) | ||
t.testSortInfos(c) | ||
} | ||
|
||
func (t *testOptimist) testOptimist(c *C, restart int) { | ||
|
@@ -656,14 +658,13 @@ func (t *testOptimist) TestOptimistLockConflict(c *C) { | |
tblID int64 = 111 | ||
DDLs1 = []string{"ALTER TABLE bar ADD COLUMN c1 TEXT"} | ||
DDLs2 = []string{"ALTER TABLE bar ADD COLUMN c1 DATETIME"} | ||
DDLs3 = []string{"ALTER TABLE bar DROP COLUMN c1"} | ||
ti0 = createTableInfo(c, p, se, tblID, `CREATE TABLE bar (id INT PRIMARY KEY)`) | ||
ti1 = createTableInfo(c, p, se, tblID, `CREATE TABLE bar (id INT PRIMARY KEY, c1 TEXT)`) | ||
ti2 = createTableInfo(c, p, se, tblID, `CREATE TABLE bar (id INT PRIMARY KEY, c1 DATETIME)`) | ||
ti3 = ti0 | ||
i1 = optimism.NewInfo(task, source1, "foo", "bar-1", downSchema, downTable, DDLs1, ti0, []*model.TableInfo{ti1}) | ||
i2 = optimism.NewInfo(task, source1, "foo", "bar-2", downSchema, downTable, DDLs2, ti0, []*model.TableInfo{ti2}) | ||
i3 = optimism.NewInfo(task, source1, "foo", "bar-2", downSchema, downTable, DDLs3, ti2, []*model.TableInfo{ti3}) | ||
i3 = optimism.NewInfo(task, source1, "foo", "bar-2", downSchema, downTable, DDLs1, ti0, []*model.TableInfo{ti3}) | ||
) | ||
|
||
st1.AddTable("foo", "bar-1", downSchema, downTable) | ||
|
@@ -714,6 +715,7 @@ func (t *testOptimist) TestOptimistLockConflict(c *C) { | |
c.Assert(len(errCh), Equals, 0) | ||
|
||
// PUT i3, no conflict now. | ||
// case for handle-error replace | ||
rev3, err := optimism.PutInfo(etcdTestCli, i3) | ||
c.Assert(err, IsNil) | ||
// wait operation for i3 become available. | ||
|
@@ -1029,3 +1031,127 @@ func (t *testOptimist) TestOptimistInitSchema(c *C) { | |
c.Assert(err, IsNil) | ||
c.Assert(is.TableInfo, DeepEquals, ti1) // the init schema is ti1 now. | ||
} | ||
|
||
func (t *testOptimist) testSortInfos(c *C) { | ||
defer clearOptimistTestSourceInfoOperation(c) | ||
|
||
var ( | ||
task = "test-optimist-init-schema" | ||
sources = []string{"mysql-replica-1", "mysql-replica-2"} | ||
upSchema = "foo" | ||
upTables = []string{"bar-1", "bar-2"} | ||
downSchema = "foo" | ||
downTable = "bar" | ||
|
||
p = parser.New() | ||
se = mock.NewContext() | ||
tblID int64 = 111 | ||
DDLs1 = []string{"ALTER TABLE bar ADD COLUMN c1 TEXT"} | ||
DDLs2 = []string{"ALTER TABLE bar ADD COLUMN c2 INT"} | ||
ti0 = createTableInfo(c, p, se, tblID, `CREATE TABLE bar (id INT PRIMARY KEY)`) | ||
ti1 = createTableInfo(c, p, se, tblID, `CREATE TABLE bar (id INT PRIMARY KEY, c1 TEXT)`) | ||
ti2 = createTableInfo(c, p, se, tblID, `CREATE TABLE bar (id INT PRIMARY KEY, c1 TEXT, c2 INT)`) | ||
i11 = optimism.NewInfo(task, sources[0], upSchema, upTables[0], downSchema, downTable, DDLs1, ti0, []*model.TableInfo{ti1}) | ||
i12 = optimism.NewInfo(task, sources[0], upSchema, upTables[1], downSchema, downTable, DDLs1, ti0, []*model.TableInfo{ti1}) | ||
i21 = optimism.NewInfo(task, sources[1], upSchema, upTables[1], downSchema, downTable, DDLs2, ti1, []*model.TableInfo{ti2}) | ||
) | ||
|
||
rev1, err := optimism.PutInfo(etcdTestCli, i11) | ||
c.Assert(err, IsNil) | ||
ifm, _, err := optimism.GetAllInfo(etcdTestCli) | ||
c.Assert(err, IsNil) | ||
infos := sortInfos(ifm) | ||
c.Assert(len(infos), Equals, 1) | ||
i11.Version = 1 | ||
i11.Revision = rev1 | ||
c.Assert(infos[0], DeepEquals, i11) | ||
|
||
rev2, err := optimism.PutInfo(etcdTestCli, i12) | ||
c.Assert(err, IsNil) | ||
ifm, _, err = optimism.GetAllInfo(etcdTestCli) | ||
c.Assert(err, IsNil) | ||
infos = sortInfos(ifm) | ||
c.Assert(len(infos), Equals, 2) | ||
i11.Version = 1 | ||
i11.Revision = rev1 | ||
i12.Version = 1 | ||
i12.Revision = rev2 | ||
c.Assert(infos[0], DeepEquals, i11) | ||
c.Assert(infos[1], DeepEquals, i12) | ||
|
||
rev3, err := optimism.PutInfo(etcdTestCli, i21) | ||
c.Assert(err, IsNil) | ||
rev4, err := optimism.PutInfo(etcdTestCli, i11) | ||
c.Assert(err, IsNil) | ||
ifm, _, err = optimism.GetAllInfo(etcdTestCli) | ||
c.Assert(err, IsNil) | ||
infos = sortInfos(ifm) | ||
c.Assert(len(infos), Equals, 3) | ||
|
||
i11.Version = 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems we could replace |
||
i11.Revision = rev4 | ||
i12.Version = 1 | ||
i12.Revision = rev2 | ||
i21.Version = 1 | ||
i21.Revision = rev3 | ||
c.Assert(infos[0], DeepEquals, i12) | ||
c.Assert(infos[1], DeepEquals, i21) | ||
c.Assert(infos[2], DeepEquals, i11) | ||
} | ||
|
||
func (t *testOptimist) TestBuildLockJoinedAndTable(c *C) { | ||
defer clearOptimistTestSourceInfoOperation(c) | ||
|
||
var ( | ||
logger = log.L() | ||
o = NewOptimist(&logger) | ||
task = "task" | ||
source1 = "mysql-replica-1" | ||
source2 = "mysql-replica-2" | ||
downSchema = "db" | ||
downTable = "tbl" | ||
st1 = optimism.NewSourceTables(task, source1) | ||
st2 = optimism.NewSourceTables(task, source2) | ||
DDLs1 = []string{"ALTER TABLE bar ADD COLUMN c1 INT"} | ||
DDLs2 = []string{"ALTER TABLE bar DROP COLUMN c1"} | ||
p = parser.New() | ||
se = mock.NewContext() | ||
tblID int64 = 111 | ||
ti0 = createTableInfo(c, p, se, tblID, `CREATE TABLE bar (id INT PRIMARY KEY)`) | ||
ti1 = createTableInfo(c, p, se, tblID, `CREATE TABLE bar (id INT PRIMARY KEY, c1 INT)`) | ||
ti2 = createTableInfo(c, p, se, tblID, `CREATE TABLE bar (id INT PRIMARY KEY, c1 INT, c2 INT)`) | ||
ti3 = createTableInfo(c, p, se, tblID, `CREATE TABLE bar (id INT PRIMARY KEY, c2 INT)`) | ||
|
||
i11 = optimism.NewInfo(task, source1, "foo", "bar-1", downSchema, downTable, DDLs1, ti0, []*model.TableInfo{ti1}) | ||
i21 = optimism.NewInfo(task, source2, "foo", "bar-1", downSchema, downTable, DDLs2, ti2, []*model.TableInfo{ti3}) | ||
) | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
st1.AddTable("db", "tbl-1", downSchema, downTable) | ||
st2.AddTable("db", "tbl-1", downSchema, downTable) | ||
|
||
c.Assert(o.Start(ctx, etcdTestCli), IsNil) | ||
_, err := optimism.PutSourceTables(etcdTestCli, st1) | ||
c.Assert(err, IsNil) | ||
_, err = optimism.PutSourceTables(etcdTestCli, st2) | ||
c.Assert(err, IsNil) | ||
|
||
_, err = optimism.PutInfo(etcdTestCli, i21) | ||
c.Assert(err, IsNil) | ||
_, err = optimism.PutInfo(etcdTestCli, i11) | ||
c.Assert(err, IsNil) | ||
|
||
ifm, _, err := optimism.GetAllInfo(etcdTestCli) | ||
c.Assert(err, IsNil) | ||
|
||
lockJoined, lockTTS := o.buildLockJoinedAndTTS(ifm) | ||
c.Assert(len(lockJoined), Equals, 1) | ||
c.Assert(len(lockTTS), Equals, 1) | ||
joined, ok := lockJoined[utils.GenDDLLockID(task, downSchema, downTable)] | ||
c.Assert(ok, IsTrue) | ||
cmp, err := joined.Compare(schemacmp.Encode(ti2)) | ||
c.Assert(err, IsNil) | ||
c.Assert(cmp, Equals, 0) | ||
} |
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
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
Oops, something went wrong.
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.
we could add a alerting rule for errors of Optimist initialization in future