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
tracker: get some session variables from downtream #1032
Merged
Merged
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
9eac402
tracker: get alter-pk and some session variables from downtream
lance6716 3cb2870
add test
lance6716 a81e238
fix hound
lance6716 6121699
Merge branch 'master' into retrieve-tidb
lance6716 76f66ee
change test
lance6716 514d419
change config structure
lance6716 547af04
use more common way to retrieve alter-pk
lance6716 817df9c
fix CI
lance6716 4ef9e8d
fix CI
lance6716 1cca733
Merge branch 'master' of https://github.com/pingcap/dm into retrieve-…
lance6716 6e2f4bb
Merge branch 'master' into retrieve-tidb
lance6716 0357f8c
fix CI
lance6716 80d1005
Merge branch 'retrieve-tidb' of github.com:lance6716/dm into retrieve…
lance6716 13150c0
add integration test
lance6716 c0d0a99
Merge branch 'master' of https://github.com/pingcap/dm into retrieve-…
lance6716 0ace2c9
address comment
lance6716 ff807c8
remove tidbconfig arg
lance6716 2d0af11
Merge branch 'master' of https://github.com/pingcap/dm into retrieve-…
lance6716 0bc3094
fix test
lance6716 ab8b918
Merge branch 'master' into retrieve-tidb
lance6716 ed25402
Merge branch 'master' into retrieve-tidb
lance6716 914c285
address comment
lance6716 6e63459
Merge branch 'retrieve-tidb' of github.com:lance6716/dm into retrieve…
lance6716 87eeda5
Merge branch 'master' of https://github.com/pingcap/dm into retrieve-…
lance6716 6ec2b8d
test CI
lance6716 86dd372
Merge branch 'master' into retrieve-tidb
lance6716 8fc1466
address comment
lance6716 b538de5
Merge branch 'retrieve-tidb' of github.com:lance6716/dm into retrieve…
lance6716 1a0f80e
Merge branch 'master' into retrieve-tidb
lance6716 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
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 |
---|---|---|
|
@@ -24,28 +24,67 @@ import ( | |
"github.com/pingcap/parser/model" | ||
"github.com/pingcap/tidb-tools/pkg/dbutil" | ||
"github.com/pingcap/tidb-tools/pkg/filter" | ||
tidbConfig "github.com/pingcap/tidb/config" | ||
"github.com/pingcap/tidb/domain" | ||
"github.com/pingcap/tidb/infoschema" | ||
"github.com/pingcap/tidb/kv" | ||
"github.com/pingcap/tidb/meta" | ||
"github.com/pingcap/tidb/session" | ||
"github.com/pingcap/tidb/store/mockstore" | ||
|
||
"github.com/pingcap/dm/pkg/conn" | ||
tcontext "github.com/pingcap/dm/pkg/context" | ||
) | ||
|
||
const ( | ||
waitDDLRetryCount = 10 | ||
schemaLeaseTime = 10 * time.Millisecond | ||
) | ||
|
||
var ( | ||
sessionVars = []string{"sql_mode", "tidb_skip_utf8_check"} | ||
) | ||
|
||
// Tracker is used to track schema locally. | ||
type Tracker struct { | ||
store kv.Storage | ||
dom *domain.Domain | ||
se session.Session | ||
} | ||
|
||
// NewTracker creates a new tracker. | ||
func NewTracker(sessionCfg map[string]string) (*Tracker, error) { | ||
// NewTracker creates a new tracker. `sessionCfg` will be set as tracker's session variables if specified, or retrieve | ||
// some variable from downstream TiDB using `tidbConn`. | ||
func NewTracker(sessionCfg map[string]string, tidbConn *conn.BaseConn) (*Tracker, error) { | ||
// NOTE: tidb uses a **global** config so can't isolate tracker's config from each other. If that isolation is needed, | ||
// we might SetGlobalConfig before every call to tracker, or use some patch like https://github.com/bouk/monkey | ||
toSet := tidbConfig.NewConfig() | ||
toSet.AlterPrimaryKey = true | ||
tidbConfig.StoreGlobalConfig(toSet) | ||
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. Any test for it? rest LGTM 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. |
||
|
||
if len(sessionCfg) == 0 { | ||
sessionCfg = make(map[string]string) | ||
var ignoredColumn interface{} | ||
for _, k := range sessionVars { | ||
rows, err2 := tidbConn.QuerySQL(tcontext.Background(), fmt.Sprintf("show variables like '%s'", k)) | ||
csuzhangxc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err2 != nil { | ||
return nil, err2 | ||
} | ||
if rows.Next() { | ||
var value string | ||
if err3 := rows.Scan(&ignoredColumn, &value); err3 != nil { | ||
return nil, err3 | ||
} | ||
sessionCfg[k] = value | ||
} | ||
if err2 = rows.Close(); err2 != nil { | ||
csuzhangxc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return nil, err2 | ||
} | ||
if err2 = rows.Err(); err2 != nil { | ||
return nil, err2 | ||
} | ||
} | ||
} | ||
|
||
store, err := mockstore.NewMockStore(mockstore.WithStoreType(mockstore.MockTiKV)) | ||
if err != nil { | ||
return nil, err | ||
|
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.
Can we remove it now?
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.
not sure, maybe we could use it in future 🤔
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.
ah so many reference, I prefer leave it here in case of we need it in future