Skip to content

Conversation

ti-chi-bot
Copy link
Member

This is an automated cherry-pick of #12169

What problem does this PR solve?

Issue Number: close #12167

What is changed and how it works?

Use lower case for Sysvar 'gtid_mode' for better upstream compatibility (i.e. txsql).

Check List

Tests

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

Questions

Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?

Release note

Please refer to [Release Notes Language Style Guide](https://pingcap.github.io/tidb-dev-guide/contribute-to-tidb/release-notes-style-guide.html) to write a quality release note.

If you don't think this PR needs a release note then fill it with `None`.

@ti-chi-bot ti-chi-bot added area/dm Issues or PRs related to DM. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. type/cherry-pick-for-release-6.5 This PR is cherry-picked to release-6.5 from a source PR. labels Jul 24, 2025
Copy link
Contributor

ti-chi-bot bot commented Jul 24, 2025

This cherry pick PR is for a release branch and has not yet been approved by triage owners.
Adding the do-not-merge/cherry-pick-not-approved label.

To merge this cherry pick:

  1. It must be approved by the approvers firstly.
  2. AFTER it has been approved by approvers, please wait for the cherry-pick merging approval from triage owners.

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-sigs/prow repository.

@ti-chi-bot ti-chi-bot bot added do-not-merge/cherry-pick-not-approved size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jul 24, 2025
Copy link
Contributor

ti-chi-bot bot commented Jul 24, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign dsdashun for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @ti-chi-bot, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request primarily focuses on enhancing compatibility with upstream MySQL variants by standardizing the query for the gtid_mode system variable to its lowercase form. It also involves updates to the GetGTIDMode function's signature and corresponding test cases, with additional test functions being introduced as part of the automated cherry-pick.

Highlights

  • GTID Mode Query Standardization: The GetGTIDMode function has been updated to query the gtid_mode system variable using its lowercase name ("gtid_mode") instead of the uppercase ("GTID_MODE"). This change aims to improve compatibility with various upstream MySQL distributions, such as txsql.
  • Function Signature Update: The signature of the GetGTIDMode function in dm/pkg/utils/db.go has been modified. It now accepts *tcontext.Context and *BaseDB as parameters, replacing the more generic context.Context and *sql.DB types. This indicates a move towards more specific internal type usage for context and database connections.
  • Test Suite Refactoring and Expansion: The unit tests in dm/pkg/utils/db_test.go have been updated to align with the new GetGTIDMode function signature and the lowercase gtid_mode query. Additionally, several new test functions (TestFetchAllDoTables, TestFetchTargetDoTables, etc.) have been introduced, which appear to be part of a broader set of changes integrated via the automated cherry-pick process.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@OliverS929
Copy link
Contributor

/cherry-pick-invite OliverS929

@ti-chi-bot
Copy link
Member Author

@OliverS929 Please accept the invitation then you can push to the cherry-pick pull requests.
Comment with "/cherry-pick-invite" if the invitation is expired.
https://github.com/ti-chi-bot/tiflow/invitations

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request aims to change the system variable 'GTID_MODE' to lowercase for better upstream compatibility. However, the changes introduce several merge conflicts across multiple files, which will prevent the code from compiling. These conflicts must be resolved before the PR can be merged. It appears an automated cherry-pick has caused these issues due to significant divergence between branches, including file refactoring and moves.

Comment on lines 339 to 347
<<<<<<< HEAD:dm/pkg/utils/db.go
// GetGTIDMode return GTID_MODE.
func GetGTIDMode(ctx context.Context, db *sql.DB) (string, error) {
val, err := GetGlobalVariable(ctx, db, "GTID_MODE")
=======
// GetGTIDMode return gtid_mode (lowercase for better upstream compatibility, e.g., txsql).
func GetGTIDMode(ctx *tcontext.Context, db *BaseDB) (string, error) {
val, err := GetGlobalVariable(ctx, db, "gtid_mode")
>>>>>>> 8f20364e59 (DM: Use lower case for Sysvar 'gtid_mode' for better upstream compatibility. (#12169)):dm/pkg/conn/db.go

Choose a reason for hiding this comment

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

critical

This file contains unresolved merge conflict markers (<<<<<<<, =======, >>>>>>>), which will prevent the code from compiling.

It appears this conflict arose from an automated cherry-pick onto a branch where GetGTIDMode was refactored and possibly moved. The function signature in the conflicting change uses types (*tcontext.Context, *BaseDB) that are not available in this file's scope.

Please resolve this conflict by removing the markers and ensuring there is a single, correct implementation of the function. You may need to adjust the PR to apply the change in the correct file.

Comment on lines 191 to 199
<<<<<<< HEAD:dm/pkg/utils/db_test.go
rows := mock.NewRows([]string{"Variable_name", "Value"}).AddRow("GTID_MODE", "ON")
mock.ExpectQuery(`SHOW GLOBAL VARIABLES LIKE 'GTID_MODE'`).WillReturnRows(rows)
mode, err := GetGTIDMode(ctx, db)
=======
rows := mock.NewRows([]string{"Variable_name", "Value"}).AddRow("gtid_mode", "ON")
mock.ExpectQuery(`SHOW GLOBAL VARIABLES LIKE 'gtid_mode'`).WillReturnRows(rows)
mode, err := GetGTIDMode(tctx, NewBaseDBForTest(db))
>>>>>>> 8f20364e59 (DM: Use lower case for Sysvar 'gtid_mode' for better upstream compatibility. (#12169)):dm/pkg/conn/db_test.go

Choose a reason for hiding this comment

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

critical

This test contains unresolved merge conflict markers, which will cause compilation to fail. This seems related to the conflict in dm/pkg/utils/db.go.

Please resolve this conflict. The call to GetGTIDMode here is also inconsistent, reflecting the refactoring that likely caused the conflict.

Comment on lines 469 to 643
require.Len(t, got, 1)
require.Equal(t, []string{"tbl1", "tbl2"}, got[doSchema])
require.NoError(t, mock.ExpectationsWereMet())
}

func TestFetchTargetDoTables(t *testing.T) {
t.Parallel()

db, mock, err := sqlmock.New()
require.NoError(t, err)

// empty filter and router, just as upstream.
ba, err := filter.New(false, nil)
require.NoError(t, err)
r, err := regexprrouter.NewRegExprRouter(false, nil)
require.NoError(t, err)

schemas := []string{"shard1"}
rows := sqlmock.NewRows([]string{"Database"})
addRowsForSchemas(rows, schemas)
mock.ExpectQuery(`SHOW DATABASES`).WillReturnRows(rows)

tablesM := map[string][]string{
"shard1": {"tbl1", "tbl2"},
}
for schema, tables := range tablesM {
rows = sqlmock.NewRows([]string{fmt.Sprintf("Tables_in_%s", schema), "Table_type"})
addRowsForTables(rows, tables)
mock.ExpectQuery(fmt.Sprintf("SHOW FULL TABLES IN `%s` WHERE Table_Type != 'VIEW'", schema)).WillReturnRows(rows)
}

tablesMap, extendedCols, err := FetchTargetDoTables(context.Background(), "", NewBaseDBForTest(db), ba, r)
require.NoError(t, err)
require.Equal(t, map[filter.Table][]filter.Table{
{Schema: "shard1", Name: "tbl1"}: {{Schema: "shard1", Name: "tbl1"}},
{Schema: "shard1", Name: "tbl2"}: {{Schema: "shard1", Name: "tbl2"}},
}, tablesMap)
require.Len(t, extendedCols, 0)
require.NoError(t, mock.ExpectationsWereMet())

// route to the same downstream.
r, err = regexprrouter.NewRegExprRouter(false, []*router.TableRule{
{SchemaPattern: "shard*", TablePattern: "tbl*", TargetSchema: "shard", TargetTable: "tbl"},
})
require.NoError(t, err)

rows = sqlmock.NewRows([]string{"Database"})
addRowsForSchemas(rows, schemas)
mock.ExpectQuery(`SHOW DATABASES`).WillReturnRows(rows)
for schema, tables := range tablesM {
rows = sqlmock.NewRows([]string{fmt.Sprintf("Tables_in_%s", schema), "Table_type"})
addRowsForTables(rows, tables)
mock.ExpectQuery(fmt.Sprintf("SHOW FULL TABLES IN `%s` WHERE Table_Type != 'VIEW'", schema)).WillReturnRows(rows)
}

tablesMap, extendedCols, err = FetchTargetDoTables(context.Background(), "", NewBaseDBForTest(db), ba, r)
require.NoError(t, err)
require.Equal(t, map[filter.Table][]filter.Table{
{Schema: "shard", Name: "tbl"}: {
{Schema: "shard1", Name: "tbl1"},
{Schema: "shard1", Name: "tbl2"},
},
}, tablesMap)
require.Len(t, extendedCols, 0)
require.NoError(t, mock.ExpectationsWereMet())
}

func addRowsForSchemas(rows *sqlmock.Rows, schemas []string) {
for _, d := range schemas {
rows.AddRow(d)
}
}

func addRowsForTables(rows *sqlmock.Rows, tables []string) {
for _, table := range tables {
rows.AddRow(table, "BASE TABLE")
}
}

func TestGetGTIDMode(t *testing.T) {
t.Parallel()

db, mock, err := sqlmock.New()
require.NoError(t, err)

tctx := tcontext.NewContext(context.Background(), log.L())

// Mock the query for GetGlobalVariable
rows := mock.NewRows([]string{"Variable_name", "Value"}).AddRow("gtid_mode", "ON")
mock.ExpectQuery(`SHOW GLOBAL VARIABLES LIKE 'gtid_mode'`).WillReturnRows(rows)

// Call the actual GetGTIDMode function
gtidMode, err := GetGTIDMode(tctx, NewBaseDBForTest(db))

// Assert the results when we use lowercase gtid_mode
require.NoError(t, err)
require.Equal(t, "ON", gtidMode)
require.NoError(t, mock.ExpectationsWereMet())
}
>>>>>>> 8f20364e59 (DM: Use lower case for Sysvar 'gtid_mode' for better upstream compatibility. (#12169)):dm/pkg/conn/db_test.go

Choose a reason for hiding this comment

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

critical

This part of the file also contains merge conflict markers. It seems to be attempting to add a large block of new tests, but the <<<<<<< and >>>>>>> markers make the code invalid.

The path in the marker (dm/pkg/conn/db_test.go) suggests these tests might belong to a different file. Please resolve this conflict and ensure the new tests are placed in the correct location.

@ti-chi-bot ti-chi-bot bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 6, 2025
@OliverS929
Copy link
Contributor

/retest

1 similar comment
@OliverS929
Copy link
Contributor

/retest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/dm Issues or PRs related to DM. do-not-merge/cherry-pick-not-approved do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/cherry-pick-for-release-6.5 This PR is cherry-picked to release-6.5 from a source PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants