Skip to content

Commit

Permalink
Initial work to support MemSQL/SingleStore
Browse files Browse the repository at this point in the history
Issue: pingcap#309

- `WITH CONSISTENT SNAPSHOT` is not supported by MemSQL (same for
  Vitess).
- `SHOW CREATE DATABASE` is not supported by MemSQL.
  • Loading branch information
dveeden authored and ti-chi-bot committed Aug 3, 2021
1 parent 9509923 commit cf69df4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .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 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 @@ -47,6 +49,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 @@ -584,7 +593,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 cf69df4

Please sign in to comment.