Skip to content

Commit

Permalink
update config
Browse files Browse the repository at this point in the history
  • Loading branch information
coocood committed Apr 29, 2019
1 parent 89c134e commit 41d79c7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ type Plugin struct {
// PessimisticTxn is the config for pessimistic transaction.
type PessimisticTxn struct {
Enable bool `toml:"enable" json:"enable"`
Default bool `toml:"default" json:"default"`
MaxRetryCount uint `toml:"max-retry-count" json:"max-retry-count"`
TTL uint64 `toml:"ttl" json:"ttl"`
}
Expand Down Expand Up @@ -378,6 +379,7 @@ var defaultConf = Config{
},
PessimisticTxn: PessimisticTxn{
Enable: false,
Default: false,
MaxRetryCount: 256,
TTL: 60 * 1000,
},
Expand Down
5 changes: 4 additions & 1 deletion config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,12 @@ binlog-socket = ""
strategy = "range"

[pessimistic-txn]
# enable pessimistic transaction by default.
# enable pessimistic transaction.
enable = false

# start pessimistic transaction by default.
default = false

# max retry count for a statement in a pessimistic transaction.
max-retry-count = 256

Expand Down
3 changes: 2 additions & 1 deletion executor/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ func (e *SimpleExec) executeBegin(ctx context.Context, s *ast.BeginStmt) error {
if err != nil {
return err
}
if s.Pessimistic || config.GetGlobalConfig().PessimisticTxn.Enable || e.ctx.GetSessionVars().PessimisticLock {
pTxnConf := config.GetGlobalConfig().PessimisticTxn
if pTxnConf.Enable && (s.Pessimistic || pTxnConf.Default || e.ctx.GetSessionVars().PessimisticLock) {
txn.SetOption(kv.Pessimistic, true)
}
return nil
Expand Down
3 changes: 3 additions & 0 deletions session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2550,6 +2550,9 @@ func (s *testSessionSuite) TestTxnGoString(c *C) {
}

func (s *testSessionSuite) TestPessimisticTxn(c *C) {
if !config.GetGlobalConfig().PessimisticTxn.Enable {
c.Skip("pessimistic transaction is not enabled")
}
tk := testkit.NewTestKitWithInit(c, s.store)
// Make the name has different indent for easier read.
tk1 := testkit.NewTestKitWithInit(c, s.store)
Expand Down

0 comments on commit 41d79c7

Please sign in to comment.