From 54e93ed06ebc81ac717648679b252e8bd074ec39 Mon Sep 17 00:00:00 2001 From: dongmen <20351731+asddongmen@users.noreply.github.com> Date: Wed, 29 May 2024 17:43:22 +0800 Subject: [PATCH] syncpoint (ticdc): make syncpoint support base64 encoded password (#11162) close pingcap/tiflow#10516 --- cdc/sink/mysql/mysql_syncpoint_store.go | 7 +++++-- tests/integration_tests/syncpoint/data/prepare.sql | 9 +++++++++ tests/integration_tests/syncpoint/run.sh | 4 +++- 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 tests/integration_tests/syncpoint/data/prepare.sql diff --git a/cdc/sink/mysql/mysql_syncpoint_store.go b/cdc/sink/mysql/mysql_syncpoint_store.go index 8c48c64a8e1..714ace4af42 100644 --- a/cdc/sink/mysql/mysql_syncpoint_store.go +++ b/cdc/sink/mysql/mysql_syncpoint_store.go @@ -32,6 +32,7 @@ import ( "github.com/pingcap/tiflow/pkg/errorutil" "github.com/pingcap/tiflow/pkg/filter" "github.com/pingcap/tiflow/pkg/security" + pmysql "github.com/pingcap/tiflow/pkg/sink/mysql" "go.uber.org/zap" ) @@ -120,11 +121,13 @@ func newMySQLSyncPointStore( if dsn.Params == nil { dsn.Params = make(map[string]string, 1) } - testDB, err := sql.Open("mysql", dsn.FormatDSN()) + + testDB, err := pmysql.GetTestDB(ctx, dsn, GetDBConnImpl) if err != nil { - return nil, cerror.ErrMySQLConnectionError.Wrap(err).GenWithStack("fail to open MySQL connection when configuring sink") + return nil, err } defer testDB.Close() + dsnStr, err = generateDSNByParams(ctx, dsn, params, testDB) if err != nil { return nil, errors.Trace(err) diff --git a/tests/integration_tests/syncpoint/data/prepare.sql b/tests/integration_tests/syncpoint/data/prepare.sql new file mode 100644 index 00000000000..bd603480b8c --- /dev/null +++ b/tests/integration_tests/syncpoint/data/prepare.sql @@ -0,0 +1,9 @@ +-- create user and grant all privileges +-- 'test123456' encoded by base64 -> "dGVzdDEyMzQ1Ng==" +CREATE USER 'syncpoint'@'%' IDENTIFIED BY 'test123456'; + +-- 授予所有数据库的所有权限 +GRANT ALL PRIVILEGES ON *.* TO 'syncpoint'@'%' WITH GRANT OPTION; + +-- 应用权限更改 +FLUSH PRIVILEGES; diff --git a/tests/integration_tests/syncpoint/run.sh b/tests/integration_tests/syncpoint/run.sh index 18c659917c9..fb43a06139f 100755 --- a/tests/integration_tests/syncpoint/run.sh +++ b/tests/integration_tests/syncpoint/run.sh @@ -160,9 +160,11 @@ function run() { start_ts=$(run_cdc_cli_tso_query ${UP_PD_HOST_1} ${UP_PD_PORT_1}) run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY + run_sql_file $CUR/data/prepare.sql ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} + # this test contains `set global tidb_external_ts = ?` , which requires super privilege, so we # can't use the normal user - SINK_URI="mysql://root@127.0.0.1:3306/?max-txn-row=1" + SINK_URI="mysql://syncpoint:dGVzdDEyMzQ1Ng==@127.0.0.1:3306/?max-txn-row=1" run_sql "SET GLOBAL tidb_enable_external_ts_read = on;" ${DOWN_TIDB_HOST} ${DOWN_TIDB_PORT} run_cdc_cli changefeed create --start-ts=$start_ts --sink-uri="$SINK_URI" --config="$CUR/conf/changefeed.toml"