Skip to content

Commit

Permalink
ks6.6: add a switch for alter user pessimistic (pingcap#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
ystaticy authored Feb 28, 2023
1 parent 0505fa1 commit 57c7c5b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ type Config struct {

EnableRULimit bool `toml:"enable-ru-limit" json:"enable-ru-limit"`

EnableAlterUserPessimistic bool `toml:"enable-alter-user-pessimistic" json:"enable-alter-user-pessimistic"`

// The following items are deprecated. We need to keep them here temporarily
// to support the upgrade process. They can be removed in future.

Expand Down Expand Up @@ -1048,6 +1050,7 @@ var defaultConf = Config{
SkipGCDropTable: false,
SkipRedoDeleteRangeGC: true,
EnableRULimit: false,
EnableAlterUserPessimistic: false,
EnableGlobalKill: true,
TrxSummary: DefaultTrxSummary(),
DisaggregatedTiFlash: false,
Expand Down
13 changes: 11 additions & 2 deletions executor/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -1725,8 +1725,17 @@ func (e *SimpleExec) executeAlterUser(ctx context.Context, s *ast.AlterUserStmt)
if err != nil {
return err
}
if _, err := sqlExecutor.ExecuteInternal(ctx, "BEGIN PESSIMISTIC"); err != nil {
return err

if config.GetGlobalConfig().EnableAlterUserPessimistic {
logutil.BgLogger().Info("execute `alter user` using PESSIMISTIC transaction")
if _, err := sqlExecutor.ExecuteInternal(ctx, "BEGIN PESSIMISTIC"); err != nil {
return err
}
} else {
logutil.BgLogger().Info("execute `alter user` using OPTIMISTIC transaction")
if _, err := sqlExecutor.ExecuteInternal(ctx, "BEGIN"); err != nil {
return err
}
}

for _, spec := range s.Specs {
Expand Down

0 comments on commit 57c7c5b

Please sign in to comment.