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

Commit

Permalink
lightning: always enable autocommit in db connection (#1114) (#1125)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored May 26, 2021
1 parent 9695f60 commit 0bb5076
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion pkg/lightning/restore/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ func DBFromConfig(dsn config.DBStore) (*sql.DB, error) {
"allow_auto_random_explicit_insert": "1",
// allow use _tidb_rowid in sql statement
"tidb_opt_write_row_id": "1",
// always set auto-commit to ON
"autocommit": "1",
},
}
db, err := param.Connect()
Expand Down Expand Up @@ -255,7 +257,10 @@ func LoadSchemaInfo(
}

for _, tbl := range schema.Tables {
tblInfo := tableMap[strings.ToLower(tbl.Name)]
tblInfo, ok := tableMap[strings.ToLower(tbl.Name)]
if !ok {
return nil, errors.Errorf("table '%s' schema not found", tbl.Name)
}
tableName := tblInfo.Name.String()
if tblInfo.State != model.StatePublic {
err := errors.Errorf("table [%s.%s] state is not public", schema.Name, tableName)
Expand Down
7 changes: 6 additions & 1 deletion tests/lightning_alter_random/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ set -eu
# FIXME: auto-random is only stable on master currently.
check_cluster_version 4 0 0 AUTO_RANDOM || exit 0

# test lightning with autocommit disabled
run_sql "SET @@global.autocommit = '0';"

for backend in tidb importer local; do
if [ "$backend" = 'local' ]; then
check_cluster_version 4 0 0 'local backend' || continue
Expand All @@ -35,11 +38,13 @@ for backend in tidb importer local; do
check_contains 'inc: 3'

# auto random base is 4
run_sql "INSERT INTO alter_random.t VALUES ();"
run_sql "INSERT INTO alter_random.t VALUES ();commit;"
run_sql "SELECT id & b'000001111111111111111111111111111111111111111111111111111111111' as inc FROM alter_random.t"
if [ "$backend" = 'tidb' ]; then
check_contains 'inc: 30002'
else
check_contains 'inc: 4'
fi
done

run_sql "SET @@global.autocommit = '1';"

0 comments on commit 0bb5076

Please sign in to comment.