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

使用sqlparser替换正则进行queryevent的解析 #382

Merged
merged 19 commits into from
May 15, 2019
Merged

使用sqlparser替换正则进行queryevent的解析 #382

merged 19 commits into from
May 15, 2019

Conversation

lintanghui
Copy link
Contributor

#381
某些case下的queryevent正则无法正常解析到表结构变更无法刷新table缓存导致binlog格式解析失败
例如:使用ghost时的rename语句为:
rename /* gh-ost */ tablepercona.order_basictopercona._order_basic_del, percona._order_basic_ghotopercona.order_basic
当ddl存在注释或同时操作多个table的时候正则匹配到对应到表变更

canal/sync.go Outdated Show resolved Hide resolved
@siddontang
Copy link
Collaborator

Great, PTAL @GregoryIan

@IANTHEREAL IANTHEREAL mentioned this pull request May 6, 2019
canal/sync.go Outdated Show resolved Hide resolved
canal/sync.go Outdated Show resolved Hide resolved
canal/canal_test.go Outdated Show resolved Hide resolved
canal/canal.go Outdated Show resolved Hide resolved
canal/sync.go Outdated Show resolved Hide resolved
canal/sync.go Outdated Show resolved Hide resolved
canal/sync.go Outdated Show resolved Hide resolved
}
ns = append(ns, n)
}
case *ast.AlterTableStmt:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still AlterTableStmt problem, AlterTableStmt contains field Specs and AlterTableRenameTable spec stores table name in its NewTable field, you know? you should fetch new table name from it I think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think what we need is just clear old table cache. for new table, it will be fetched when table cache miss. i think it's unneccessary to get new table name here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, but it's also relay on definition of OnTableChanged, would user want to receive new table like create table, rename table? we should make it clear @siddontang

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is another PR #358 do this, I think we can merge this at first, and then introduce #358

@IANTHEREAL
Copy link
Collaborator

IANTHEREAL commented May 10, 2019

Very good code refine, there are still a few problems, but I believe we will be able to solve it soon @lintanghui

}
for _, st := range stmts {
nodes := parseStmt(st)
if len(nodes) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if len(nodes) != 1, then fatal? similar with others.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one stmt may contains multi tables, eg: rename a to b,c to d; then nodes will contain two nodes a and c.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, I think in these cases, we must assert the number of the nodes is what we want.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what we need to do is to range nodes and then clear old table cache, rather than care about the number if nodes. if len(nodes)<0 range it, if len(nodes)==0 do nothing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In test cases, we must ensure parseStmt works correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, some test had been writed to test parseStmt

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some test had been writed to test parseStmt

so, test the length of return nodes too?

canal/sync.go Outdated Show resolved Hide resolved
@lintanghui
Copy link
Contributor Author

PTAL @siddontang

go.mod Outdated Show resolved Hide resolved
go.mod Show resolved Hide resolved
github.com/pingcap/errors v0.11.0 h1:DCJQB8jrHbQ1VVlMFIrbj2ApScNNotVmkSNplu2yUt4=
github.com/pingcap/errors v0.11.0/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
github.com/pingcap/parser v0.0.0-20190506092653-e336082eb825 h1:U9Kdnknj4n2v76Mg7wazevZ5N9U1OIaMwSNRVLEcLX0=
github.com/pingcap/parser v0.0.0-20190506092653-e336082eb825/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA=
github.com/pingcap/tipb v0.0.0-20190428032612-535e1abaa330 h1:rRMLMjIMFulCX9sGKZ1hoov/iROMsKyC8Snc02nSukw=
Copy link
Collaborator

@siddontang siddontang May 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

em, why do we use tipb here?

github.com/pingcap/errors v0.11.0
github.com/pingcap/parser v0.0.0-20190506092653-e336082eb825
github.com/pingcap/tipb v0.0.0-20190428032612-535e1abaa330 // indirect
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need tipb here?

@siddontang siddontang merged commit 35983ce into go-mysql-org:master May 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants