Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

export: initial work to support MemSQL/SingleStore #311

Merged
merged 1 commit into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe group the 3-rd party packages


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)
dveeden marked this conversation as resolved.
Show resolved Hide resolved
}
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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we check the error type here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could try to detect the error type and check for the error number here. However I think retrying without the optional part should give the same result. I don't think the extra complexity is needed.

5.5.58 127.0.0.1:3306  test  SQL  START TRANSACTION /*!40108 WITH CONSISTENT SNAPSHOT */;
ERROR: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WITH CONSISTENT SNAPSHOT */' at line 1
5.5.58 127.0.0.1:3306  test  SQL  SELECT @@version, @@memsql_version;
+-----------+------------------+
| @@version | @@memsql_version |
+-----------+------------------+
| 5.5.58    | 7.3.13           |
+-----------+------------------+
1 row in set (0.0357 sec)

Copy link
Contributor

Choose a reason for hiding this comment

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

I see

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