fix: support account creation on pxc
This commit is contained in:
@@ -1859,6 +1859,9 @@ func (a *adapter) UserCreate(user *t.User) error {
|
||||
func lockUserAccountNoSequence(ctx context.Context, tx *sqlx.Tx) (func(), error) {
|
||||
var locked sql.NullInt64
|
||||
if err := tx.QueryRowContext(ctx, "SELECT GET_LOCK(CONCAT(DATABASE(), ':im_users_account_no'), 10)").Scan(&locked); err != nil {
|
||||
if isPXCStrictModeNamedLockError(err) {
|
||||
return func() {}, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
if !locked.Valid || locked.Int64 != 1 {
|
||||
@@ -5105,6 +5108,20 @@ func isIDOutOfRange(err error) bool {
|
||||
return ok && myerr.Number == 1264 && strings.Contains(strings.ToLower(myerr.Message), "id")
|
||||
}
|
||||
|
||||
func isPXCStrictModeNamedLockError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
myerr, ok := err.(*ms.MySQLError)
|
||||
if !ok || myerr.Number != 1105 {
|
||||
return false
|
||||
}
|
||||
msg := strings.ToLower(myerr.Message)
|
||||
return strings.Contains(msg, "percona-xtradb-cluster") &&
|
||||
strings.Contains(msg, "pxc_strict_mode") &&
|
||||
(strings.Contains(msg, "get_lock") || strings.Contains(msg, "release_lock"))
|
||||
}
|
||||
|
||||
func mysqlDefaultString(value, fallback string) string {
|
||||
if strings.TrimSpace(value) == "" {
|
||||
return fallback
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
//go:build mysql
|
||||
|
||||
package mysql
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
ms "github.com/go-sql-driver/mysql"
|
||||
)
|
||||
|
||||
func TestPXCStrictModeNamedLockError(t *testing.T) {
|
||||
err := &ms.MySQLError{
|
||||
Number: 1105,
|
||||
Message: "Percona-XtraDB-Cluster prohibits use of GET_LOCK with pxc_strict_mode = ENFORCING",
|
||||
}
|
||||
if !isPXCStrictModeNamedLockError(err) {
|
||||
t.Fatal("expected PXC GET_LOCK strict mode error to be recognized")
|
||||
}
|
||||
|
||||
err = &ms.MySQLError{
|
||||
Number: 1105,
|
||||
Message: "Percona-XtraDB-Cluster prohibits use of RELEASE_LOCK with pxc_strict_mode = ENFORCING",
|
||||
}
|
||||
if !isPXCStrictModeNamedLockError(err) {
|
||||
t.Fatal("expected PXC RELEASE_LOCK strict mode error to be recognized")
|
||||
}
|
||||
|
||||
if isPXCStrictModeNamedLockError(&ms.MySQLError{Number: 1062, Message: "Duplicate entry"}) {
|
||||
t.Fatal("duplicate errors must not be recognized as PXC named lock errors")
|
||||
}
|
||||
if isPXCStrictModeNamedLockError(errors.New("GET_LOCK failed")) {
|
||||
t.Fatal("generic errors must not be recognized as PXC named lock errors")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user