Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

loader, syncer: support create/drop view #1310

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

lance6716
Copy link
Collaborator

@lance6716 lance6716 commented Nov 27, 2020

What problem does this PR solve?

close #1300

What is changed and how it works?

support dumpling's view file in load unit, support sync view as well.

sync of view didn't need a sharding sync lock, that is to say we could directly execute CREATE VIEW IF NOT EXISTS / DROP VIEW IF EXISTS to downstream when any shard send it

Check List

Tests

  • Unit test
  • Integration test

Code changes

Side effects

Related changes

  • Need to cherry-pick to the release branch
  • Need to be included in the release note

@lance6716 lance6716 added the status/DNM Do not merge, test is failing or blocked by another PR label Nov 27, 2020
@lance6716

This comment has been minimized.

@lance6716

This comment has been minimized.

@lance6716
Copy link
Collaborator Author

lance6716 commented Nov 28, 2020

waiting pingcap/tidb-tools#405 (but I think it's OK to merge this PR before tidb-tools. In days before v2.0.1 release will update dependencies as well)

@lance6716 lance6716 added needs-cherry-pick-release-2.0 This PR should be cherry-picked to release-2.0. Remove this label after cherry-picked to release-2.0 needs-update-release-note This PR should be added into release notes. Remove this label once the release notes are updated priority/important Major change, requires approval from ≥2 primary reviewers status/PTAL This PR is ready for review. Add this label back after committing new changes and removed status/DNM Do not merge, test is failing or blocked by another PR labels Nov 28, 2020
@lance6716 lance6716 added this to the v2.0.1 milestone Nov 28, 2020
@@ -1272,8 +1420,18 @@ func (l *Loader) restoreData(ctx context.Context) error {
dispatchMap[fmt.Sprintf("%s_%s_%s", db, table, file)] = j
}
}

for view := range views {
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to create the view in a different database with the table?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I guess user may create that type of view. And dumpling will generate a "table file" for each view at view's database, I guess this logic is fine?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done in d168716

if err != nil {
return terror.WithScope(err, terror.ScopeInternal)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It sames that loader will ignore all SET sqls here. Is this by design?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

forgot 😂

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh, query will be added in L1222. We just didn't rename them

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, yes. My fault. Maybe you can add a comment before L1191 🤣

Comment on lines +1424 to +1432
for view := range views {
viewFile := fmt.Sprintf("%s/%s.%s-schema-view.sql", l.cfg.Dir, db, view)
l.logger.Info("start to create view", zap.String("view file", viewFile))
err := l.restoreView(ctx, dbConn, viewFile, db, view)
if err != nil {
return err
}
l.logger.Info("finish to create view", zap.String("view file", viewFile))
}
Copy link
Contributor

@lichunzhu lichunzhu Nov 30, 2020

Choose a reason for hiding this comment

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

What if some views needed tables in other databases are not created yet? I think we should create views when all tables in all databases have been created correctly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done in d168716

@lance6716 lance6716 added the status/WIP This PR is still work in progress label Nov 30, 2020
@lance6716 lance6716 added needs-cherry-pick-release-2.0 This PR should be cherry-picked to release-2.0. Remove this label after cherry-picked to release-2.0 needs-update-release-note This PR should be added into release notes. Remove this label once the release notes are updated status/PTAL This PR is ready for review. Add this label back after committing new changes and removed status/DNM Do not merge, test is failing or blocked by another PR labels Dec 30, 2020
@lance6716
Copy link
Collaborator Author

updated code and PR description, PTAL @lichunzhu @GMHDBJD @csuzhangxc

go.mod Show resolved Hide resolved
lichunzhu
lichunzhu previously approved these changes Jan 4, 2021
Copy link
Contributor

@lichunzhu lichunzhu left a comment

Choose a reason for hiding this comment

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

LGTM

@lance6716 lance6716 added the status/LGT1 One reviewer already commented LGTM label Jan 4, 2021
@lance6716
Copy link
Collaborator Author

PTAL @GMHDBJD

@@ -1868,7 +1872,18 @@ func (s *Syncer) handleQueryEvent(ev *replication.QueryEvent, ec eventContext) e
return err
}

if s.cfg.ShardMode == "" {
// VIEW statements are not needed sharding synchronized, so pretend this is no-shard-mode
Copy link
Collaborator

@GMHDBJD GMHDBJD Jan 7, 2021

Choose a reason for hiding this comment

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

What's the behavior when view statement in resharding sync? such as ddl1 view ddl2. How about add a test for it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

56ba826

in pessimistic mode, DDL lock will block sync of VIEW. in other cases VIEW is executed directly in downstream

@lance6716
Copy link
Collaborator Author

lance6716 commented Jan 7, 2021

data race recorded in #1351

[2021-01-07T04:24:29.483Z] WARNING: DATA RACE
[2021-01-07T04:24:29.483Z] Write at 0x00c0002da4f0 by goroutine 194:
[2021-01-07T04:24:29.483Z]   github.com/pingcap/dm/pkg/gtid.(*MySQLGTIDSet).Set()
[2021-01-07T04:24:29.483Z]       /home/jenkins/agent/workspace/dm_ghpr_test/go/src/github.com/pingcap/dm/pkg/gtid/gtid.go:105 +0xb5
[2021-01-07T04:24:29.483Z]   github.com/pingcap/dm/relay.(*Relay).handleEvents()
[2021-01-07T04:24:29.483Z]       /home/jenkins/agent/workspace/dm_ghpr_test/go/src/github.com/pingcap/dm/relay/relay.go:474 +0x1217
[2021-01-07T04:24:29.483Z]   github.com/pingcap/dm/relay.(*Relay).process()
[2021-01-07T04:24:29.483Z]       /home/jenkins/agent/workspace/dm_ghpr_test/go/src/github.com/pingcap/dm/relay/relay.go:257 +0x742
[2021-01-07T04:24:29.483Z]   github.com/pingcap/dm/relay.(*Relay).Process()
[2021-01-07T04:24:29.483Z]       /home/jenkins/agent/workspace/dm_ghpr_test/go/src/github.com/pingcap/dm/relay/relay.go:173 +0xb1
[2021-01-07T04:24:29.483Z]   github.com/pingcap/dm/dm/worker.(*realRelayHolder).run()
[2021-01-07T04:24:29.483Z]       /home/jenkins/agent/workspace/dm_ghpr_test/go/src/github.com/pingcap/dm/dm/worker/relay.go:141 +0x1e8
[2021-01-07T04:24:29.483Z]   github.com/pingcap/dm/dm/worker.(*realRelayHolder).Start.func1()
[2021-01-07T04:24:29.483Z]       /home/jenkins/agent/workspace/dm_ghpr_test/go/src/github.com/pingcap/dm/dm/worker/relay.go:117 +0x8a
[2021-01-07T04:24:29.483Z] 
[2021-01-07T04:24:29.483Z] Previous read at 0x00c0002da4f0 by goroutine 196:
[2021-01-07T04:24:29.483Z]   github.com/pingcap/dm/pkg/gtid.(*MySQLGTIDSet).Clone()
[2021-01-07T04:24:29.483Z]       /home/jenkins/agent/workspace/dm_ghpr_test/go/src/github.com/pingcap/dm/pkg/gtid/gtid.go:159 +0x8b
[2021-01-07T04:24:29.483Z]   github.com/pingcap/dm/relay.(*LocalMeta).GTID()
[2021-01-07T04:24:29.483Z]       /home/jenkins/agent/workspace/dm_ghpr_test/go/src/github.com/pingcap/dm/relay/meta.go:352 +0x101
[2021-01-07T04:24:29.483Z]   github.com/pingcap/dm/relay.(*Relay).Status()
[2021-01-07T04:24:29.483Z]       /home/jenkins/agent/workspace/dm_ghpr_test/go/src/github.com/pingcap/dm/relay/relay.go:763 +0x213
[2021-01-07T04:24:29.483Z]   github.com/pingcap/dm/dm/worker.(*realRelayHolder).Status()
[2021-01-07T04:24:29.484Z]       /home/jenkins/agent/workspace/dm_ghpr_test/go/src/github.com/pingcap/dm/dm/worker/relay.go:162 +0x1a3
[2021-01-07T04:24:29.484Z]   github.com/pingcap/dm/dm/worker.(*realTaskStatusChecker).checkRelayStatus()
[2021-01-07T04:24:29.484Z]       /home/jenkins/agent/workspace/dm_ghpr_test/go/src/github.com/pingcap/dm/dm/worker/task_checker.go:305 +0x156
[2021-01-07T04:24:29.484Z]   github.com/pingcap/dm/dm/worker.(*realTaskStatusChecker).check()
[2021-01-07T04:24:29.484Z]       /home/jenkins/agent/workspace/dm_ghpr_test/go/src/github.com/pingcap/dm/dm/worker/task_checker.go:410 +0xfa
[2021-01-07T04:24:29.484Z]   github.com/pingcap/dm/dm/worker.(*realTaskStatusChecker).run()
[2021-01-07T04:24:29.484Z]       /home/jenkins/agent/workspace/dm_ghpr_test/go/src/github.com/pingcap/dm/dm/worker/task_checker.go:216 +0x2ba
[2021-01-07T04:24:29.484Z]   github.com/pingcap/dm/dm/worker.(*realTaskStatusChecker).Start.func1()
[2021-01-07T04:24:29.484Z]       /home/jenkins/agent/workspace/dm_ghpr_test/go/src/github.com/pingcap/dm/dm/worker/task_checker.go:177 +0x8a
[2021-01-07T04:24:29.484Z] 
[2021-01-07T04:24:29.484Z] Goroutine 194 (running) created at:
[2021-01-07T04:24:29.484Z]   github.com/pingcap/dm/dm/worker.(*realRelayHolder).Start()
[2021-01-07T04:24:29.484Z]       /home/jenkins/agent/workspace/dm_ghpr_test/go/src/github.com/pingcap/dm/dm/worker/relay.go:115 +0x85
[2021-01-07T04:24:29.484Z]   github.com/pingcap/dm/dm/worker.(*Worker).Start()
[2021-01-07T04:24:29.484Z]       /home/jenkins/agent/workspace/dm_ghpr_test/go/src/github.com/pingcap/dm/dm/worker/worker.go:126 +0x772
[2021-01-07T04:24:29.484Z]   github.com/pingcap/dm/dm/worker.(*Server).startWorker.func1()
[2021-01-07T04:24:29.484Z]       /home/jenkins/agent/workspace/dm_ghpr_test/go/src/github.com/pingcap/dm/dm/worker/server.go:591 +0x59
[2021-01-07T04:24:29.484Z] 
[2021-01-07T04:24:29.484Z] Goroutine 196 (running) created at:
[2021-01-07T04:24:29.484Z]   github.com/pingcap/dm/dm/worker.(*realTaskStatusChecker).Start()
[2021-01-07T04:24:29.484Z]       /home/jenkins/agent/workspace/dm_ghpr_test/go/src/github.com/pingcap/dm/dm/worker/task_checker.go:175 +0x85
[2021-01-07T04:24:29.484Z]   github.com/pingcap/dm/dm/worker.(*Worker).Start()
[2021-01-07T04:24:29.484Z]       /home/jenkins/agent/workspace/dm_ghpr_test/go/src/github.com/pingcap/dm/dm/worker/worker.go:134 +0x6c8
[2021-01-07T04:24:29.484Z]   github.com/pingcap/dm/dm/worker.(*Server).startWorker.func1()
[2021-01-07T04:24:29.484Z]       /home/jenkins/agent/workspace/dm_ghpr_test/go/src/github.com/pingcap/dm/dm/worker/server.go:591 +0x59
[2021-01-07T04:24:29.484Z] ==================

run_sql_source1 "create view ${shardddl1}.v1 as select * from ${shardddl1}.${tb1};"
sleep 1
run_sql_tidb "show create view ${shardddl}.v"
check_contains "View: v"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems view is created here in pessimistic?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes. VIEW is pretend to sync in none ShardMode, try to immediately execute to downstream.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But the table may not be created?

create table                        <-- not sync
create view                         <-- sync
                     create table
                     create view

@lance6716 lance6716 added status/DNM Do not merge, test is failing or blocked by another PR and removed status/PTAL This PR is ready for review. Add this label back after committing new changes labels Jan 11, 2021
@ti-chi-bot
Copy link
Member

@lance6716: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@lance6716 lance6716 added status/Stale and removed status/DNM Do not merge, test is failing or blocked by another PR labels Aug 2, 2021
@lance6716
Copy link
Collaborator Author

/hold

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
do-not-merge/hold needs-cherry-pick-release-2.0 This PR should be cherry-picked to release-2.0. Remove this label after cherry-picked to release-2.0 needs-rebase needs-update-release-note This PR should be added into release notes. Remove this label once the release notes are updated status/LGT1 One reviewer already commented LGTM status/Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Didn't fully support sync view while remove view from builtin skip DDLs
5 participants