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

fix snapshot problem #111

Merged
merged 9 commits into from Jun 30, 2020
Merged

fix snapshot problem #111

merged 9 commits into from Jun 30, 2020

Conversation

lichunzhu
Copy link
Contributor

@lichunzhu lichunzhu commented Jun 30, 2020

What problem does this PR solve?

fix #112

  1. Now dumpling use db.Exec("set tidb_snapshot = ?") to set tidb_snapshot, but this can only influence that connection. The connection pool's tidb_snapshot is not set.
  2. Now dumpling get tables before we set snapshot, which means the fetched tables are not the tables we actually want. But for consistency "lock" it needs all tables to lock before the dump process.

What is changed and how it works?

  1. Add SessionParams in conf. After we adjust all the SessionParams dumpling will reset sql.DB with the new dsn. This can make sure all connections' session variable has been set.
  2. Delete consistency snapshot. Current process order:
    a. set snapshot ts into session params
    b. fetch all the tables.
    c. set consistency.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)

Side effects

  • Increased code complexity

Related changes

  • Need to cherry-pick to the release branch
  • Need to update the documentation

Release note

  • fix the problem that --snapshot argument can't work

@lichunzhu lichunzhu requested a review from kennytm June 30, 2020 09:56
@codecov
Copy link

codecov bot commented Jun 30, 2020

Codecov Report

Merging #111 into master will decrease coverage by 1.35%.
The diff coverage is 6.15%.

@@            Coverage Diff             @@
##           master     #111      +/-   ##
==========================================
- Coverage   51.92%   50.56%   -1.36%     
==========================================
  Files          17       17              
  Lines        1770     1780      +10     
==========================================
- Hits          919      900      -19     
- Misses        782      816      +34     
+ Partials       69       64       -5     

Copy link
Collaborator

@kennytm kennytm left a comment

Choose a reason for hiding this comment

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

rest LGTM

v4/export/sql.go Outdated
Comment on lines 415 to 417
v = wrapQuotes(v)
s := fmt.Sprintf("SET SESSION %s = %s", k, v)
_, err := db.Exec(s)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
v = wrapQuotes(v)
s := fmt.Sprintf("SET SESSION %s = %s", k, v)
_, err := db.Exec(s)
s := fmt.Sprintf("SET SESSION %s = ?", k)
_, err := db.Exec(s, v)

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 use this format at first, but at last this failed when I try to set tidb_mem_quota_query.

[2020/06/30 18:39:05.433 +08:00] [ERROR] [main.go:191] ["dump failed error stack info"] [error="Error 1231: Variable 'tidb_mem_quota_query' can't be set to the value of '%!s(MISSING)'"] [errorVerbose="err = Error 1231: Variable 'tidb_mem_quota_query' can't be set to the value of '%!s(MISSING)'\ngoroutine 1 [running]:\nruntime/debug.Stack(0x19fc520, 0xc0001fc220, 0x19fd9e0)\n\t/usr/local/go/src/runtime/debug/stack.go:24 +0x9d\ngithub.com/pingcap/dumpling/v4/export.withStack(0x19fc520, 0xc0001fc220, 0xc000038000, 0xc000152570)\n\t/Users/chauncy/code/goPath/src/github.com/pingcap/dumpling/v4/export/error.go:59 +0x8d\ngithub.com/pingcap/dumpling/v4/export.resetDBWithSessionParams(0xc0001fe000, 0xc000152540, 0x2a, 0xc0001d2600, 0x2a, 0x0, 0x0)\n\t/Users/chauncy/code/goPath/src/github.com/pingcap/dumpling/v4/export/sql.go:389 +0x684\ngithub.com/pingcap/dumpling/v4/export.Dump(0x1a13400, 0xc000038090, 0xc00012cea0, 0x0, 0x0)\n\t/Users/chauncy/code/goPath/src/github.com/pingcap/dumpling/v4/export/dump.go:101 +0x327\nmain.main()\n\t/Users/chauncy/code/goPath/src/github.com/pingcap/dumpling/cmd/dumpling/main.go:189 +0x132f\n"] [stack="github.com/pingcap/log.Error\n\t/Users/chauncy/code/goPath/pkg/mod/github.com/pingcap/log@v0.0.0-20200511115504-543df19646ad/global.go:42\nmain.main\n\t/Users/chauncy/code/goPath/src/github.com/pingcap/dumpling/cmd/dumpling/main.go:191\nruntime.main\n\t/usr/local/go/src/runtime/proc.go:203"]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

arguments:

Running command: ['/Users/chauncy/code/goPath/src/github.com/pingcap/dumpling/bin/dumpling', '-T', 'TICASE_3204_WTHYZC.dumpsnap', '--dump-empty-database=false', '--snapshot', '2020-06-30 18:39:03', '-h', '127.0.0.1', '-P', '4000', '-u', 'root', '-p', '', '-o', '/var/folders/sr/_hc37vmj0db6ht4_w6rw34880000gn/T/tmptv4miiea']

Copy link
Collaborator

Choose a reason for hiding this comment

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

@lichunzhu why is it %!s(MISSING)

Copy link
Contributor Author

@lichunzhu lichunzhu Jun 30, 2020

Choose a reason for hiding this comment

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

@kennytm Before db.Exec this variable's values is "34359738368". Maybe after translation it becomes %!s(MISSING).

@@ -53,7 +53,7 @@ type Config struct {
FileType string
EscapeBackslash bool
DumpEmptyDatabase bool
TiDBMemQuotaQuery uint64
SessionParams map[string]string
Copy link
Collaborator

Choose a reason for hiding this comment

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

perhaps this should be

Suggested change
SessionParams map[string]string
SessionParams map[string]interface{}

so that we could assign a number to it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But we still have to transfer it to string for dsn 🤔

overvenus
overvenus previously approved these changes Jun 30, 2020
Copy link
Member

@overvenus overvenus left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@kennytm kennytm left a comment

Choose a reason for hiding this comment

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

Rest LGTM

v4/export/sql.go Outdated
dsn += fmt.Sprintf("&%s=%s", k, url.QueryEscape(v))
var s string
if str, ok := v.(string); ok {
s = wrapQuotation(str)
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's just wrap the quotation mark directly. the only case the str passes the strings.HasPrefix stuff is when user invokes dumpling as

./dumpling --snapshot "'stuff'"

which is so unnatural that there's no point supporting it.

Suggested change
s = wrapQuotation(str)
s = wrapStringWith(str, "'")

(the wrapBackTicks function probably has the same bug, let's check it in the future)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

@lichunzhu
Copy link
Contributor Author

@kennytm PTAL again

@kennytm kennytm added the status/LGT1 One reviewer approved (LGTM1) label Jun 30, 2020
@kennytm kennytm merged commit ff92fcf into pingcap:master Jun 30, 2020
@lichunzhu lichunzhu deleted the fixSnapshotProblem branch June 30, 2020 12:38
@lichunzhu lichunzhu mentioned this pull request Apr 2, 2021
tisonkun pushed a commit to tisonkun/dumpling that referenced this pull request Oct 20, 2021
* hotfix snapshot

* update code

* fix again

* use session param to reset db after setup

* address comment

* address comment
tisonkun pushed a commit to tisonkun/dumpling that referenced this pull request Oct 20, 2021
* hotfix snapshot

* update code

* fix again

* use session param to reset db after setup

* address comment

* address comment
tisonkun pushed a commit to tisonkun/dumpling that referenced this pull request Oct 20, 2021
* hotfix snapshot

* update code

* fix again

* use session param to reset db after setup

* address comment

* address comment
tisonkun pushed a commit to tisonkun/dumpling that referenced this pull request Oct 20, 2021
* hotfix snapshot

* update code

* fix again

* use session param to reset db after setup

* address comment

* address comment
tisonkun pushed a commit to tisonkun/tidb that referenced this pull request Oct 20, 2021
* hotfix snapshot

* update code

* fix again

* use session param to reset db after setup

* address comment

* address comment
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status/LGT1 One reviewer approved (LGTM1)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

--snapshot argument doesn't work
3 participants