storage/mysql: support pre-5.7.20 instances with tx_isolation only
This commit is contained in:
parent
8427f0f15c
commit
d2c33db8a8
@ -29,6 +29,7 @@ const (
|
|||||||
// MySQL error codes
|
// MySQL error codes
|
||||||
mysqlErrDupEntry = 1062
|
mysqlErrDupEntry = 1062
|
||||||
mysqlErrDupEntryWithKeyName = 1586
|
mysqlErrDupEntryWithKeyName = 1586
|
||||||
|
mysqlErrUnknownSysVar = 1193
|
||||||
)
|
)
|
||||||
|
|
||||||
// SQLite3 options for creating an SQL db.
|
// SQLite3 options for creating an SQL db.
|
||||||
@ -307,6 +308,26 @@ func (s *MySQL) open(logger log.Logger) (*conn, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = db.Ping()
|
||||||
|
if err != nil {
|
||||||
|
if mysqlErr, ok := err.(*mysql.MySQLError); ok && mysqlErr.Number == mysqlErrUnknownSysVar {
|
||||||
|
logger.Info("reconnecting with MySQL pre-5.7.20 compatibilty mode")
|
||||||
|
|
||||||
|
// MySQL 5.7.20 introduced transaction_isolation and deprecated tx_isolation.
|
||||||
|
// MySQL 8.0 doesn't have tx_isolation at all.
|
||||||
|
// https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_transaction_isolation
|
||||||
|
delete(cfg.Params, "transaction_isolation")
|
||||||
|
cfg.Params["tx_isolation"] = "'SERIALIZABLE'"
|
||||||
|
|
||||||
|
db, err = sql.Open("mysql", cfg.FormatDSN())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
errCheck := func(err error) bool {
|
errCheck := func(err error) bool {
|
||||||
sqlErr, ok := err.(*mysql.MySQLError)
|
sqlErr, ok := err.(*mysql.MySQLError)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
Reference in New Issue
Block a user