From b529dfb7ead232524b9d11ae668c3d7d5f6cea88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Wed, 14 Jul 2021 10:33:12 +0200 Subject: [PATCH] Initial work to support MemSQL/SingleStore Issue: https://github.com/pingcap/dumpling/issues/309 - `WITH CONSISTENT SNAPSHOT` is not supported by MemSQL (same for Vitess). - `SHOW CREATE DATABASE` is not supported by MemSQL. --- v4/export/sql.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/v4/export/sql.go b/v4/export/sql.go index 4d7a03a3..44651615 100644 --- a/v4/export/sql.go +++ b/v4/export/sql.go @@ -50,7 +50,9 @@ func ShowCreateDatabase(db *sql.Conn, database string) (string, error) { query := fmt.Sprintf("SHOW CREATE DATABASE `%s`", escapeString(database)) err := simpleQuery(db, query, handleOneRow) if err != nil { - return "", errors.Annotatef(err, "sql: %s", query) + // Falling back to simple create statement. This can happen + // with MemSQL/SingleStore as MemSQL doesn't support `SHOW CREATE DATABASE` + return fmt.Sprintf("CREATE DATABASE `%s`", escapeString(database)), nil } return oneRow[1], nil } @@ -642,7 +644,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 acutally 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 }