Skip to content

Commit

Permalink
export: initial work to support MemSQL/SingleStore (pingcap#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
dveeden authored Aug 3, 2021
1 parent 364e2ae commit d3c0ede
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions dumpling/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ coverage.txt
.idea
var
fix.sql
.vscode/
export-20*/
18 changes: 17 additions & 1 deletion dumpling/v4/export/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"strconv"
"strings"

"github.com/go-sql-driver/mysql"

tcontext "github.com/pingcap/dumpling/v4/context"

"github.com/pingcap/errors"
Expand Down Expand Up @@ -49,6 +51,13 @@ func ShowCreateDatabase(db *sql.Conn, database string) (string, error) {
}
query := fmt.Sprintf("SHOW CREATE DATABASE `%s`", escapeString(database))
err := simpleQuery(db, query, handleOneRow)
if mysqlErr, ok := errors.Cause(err).(*mysql.MySQLError); ok {
// Falling back to simple create statement for MemSQL/SingleStore, because of this:
// ERROR 1706 (HY000): Feature 'SHOW CREATE DATABASE' is not supported by MemSQL.
if mysqlErr.Number == 1706 {
return fmt.Sprintf("CREATE DATABASE `%s`", escapeString(database)), nil
}
}
if err != nil {
return "", errors.Annotatef(err, "sql: %s", query)
}
Expand Down Expand Up @@ -642,7 +651,14 @@ func createConnWithConsistency(ctx context.Context, db *sql.DB) (*sql.Conn, erro
query = "START TRANSACTION /*!40108 WITH CONSISTENT SNAPSHOT */"
_, err = conn.ExecContext(ctx, query)
if err != nil {
return nil, errors.Annotatef(err, "sql: %s", query)
// Some MySQL Compatible databases like Vitess and MemSQL/SingleStore
// are newer than 4.1.8 (the version comment) but don't actually support
// `WITH CONSISTENT SNAPSHOT`. So retry without that if the statement fails.
query = "START TRANSACTION"
_, err = conn.ExecContext(ctx, query)
if err != nil {
return nil, errors.Annotatef(err, "sql: %s", query)
}
}
return conn, nil
}
Expand Down

0 comments on commit d3c0ede

Please sign in to comment.