Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: update pessimistic lock ttl. #10578

Merged
merged 2 commits into from
May 24, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ type PessimisticTxn struct {
Default bool `toml:"default" json:"default"`
// The max count of retry for a single statement in a pessimistic transaction.
MaxRetryCount uint `toml:"max-retry-count" json:"max-retry-count"`
// The pessimistic lock ttl in milliseconds.
TTL uint64 `toml:"ttl" json:"ttl"`
// The pessimistic lock ttl.
TTL string `toml:"ttl" json:"ttl"`
}

var defaultConf = Config{
Expand Down Expand Up @@ -391,7 +391,7 @@ var defaultConf = Config{
Enable: false,
Default: false,
MaxRetryCount: 256,
TTL: 60 * 1000,
TTL: "30s",
},
}

Expand Down Expand Up @@ -554,6 +554,17 @@ func (c *Config) Valid() error {
if c.TiKVClient.MaxTxnTimeUse == 0 {
return fmt.Errorf("max-txn-time-use should be greater than 0")
}
if c.PessimisticTxn.TTL != "" {
dur, err := time.ParseDuration(c.PessimisticTxn.TTL)
if err != nil {
return err
}
minDur := time.Second * 15
maxDur := time.Second * 60
if dur < minDur || dur > maxDur {
return fmt.Errorf("pessimistic transaction ttl %s out of range [%s, %s]", dur, minDur, maxDur)
}
}
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,5 @@ default = false
max-retry-count = 256

# default TTL in milliseconds for pessimistic lock.
ttl = 60000
# The value must between "15s" and "60s".
ttl = "30s"
17 changes: 17 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,20 @@ func (s *testConfigSuite) TestConfigDiff(c *C) {
c.Assert(diffs["Performance.FeedbackProbability"][0], Equals, float64(2333))
c.Assert(diffs["Performance.FeedbackProbability"][1], Equals, float64(23.33))
}

func (s *testConfigSuite) TestValid(c *C) {
c1 := NewConfig()
tests := []struct {
ttl string
valid bool
}{
{"14s", false},
{"15s", true},
{"60s", true},
{"61s", false},
}
for _, tt := range tests {
c1.PessimisticTxn.TTL = tt.ttl
c.Assert(c1.Valid() == nil, Equals, tt.valid)
}
}
7 changes: 6 additions & 1 deletion store/tikv/2pc.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ var (
tikvSecondaryLockCleanupFailureCounterRollback = metrics.TiKVSecondaryLockCleanupFailureCounter.WithLabelValues("rollback")
)

// Global variable set by config file.
var (
PessimisticLockTTL uint64
)

func (ca twoPhaseCommitAction) String() string {
switch ca {
case actionPrewrite:
Expand Down Expand Up @@ -567,7 +572,7 @@ func (c *twoPhaseCommitter) pessimisticLockSingleBatch(bo *Backoffer, batch batc
PrimaryLock: c.primary(),
StartVersion: c.startTS,
ForUpdateTs: c.forUpdateTS,
LockTtl: config.GetGlobalConfig().PessimisticTxn.TTL,
LockTtl: PessimisticLockTTL,
IsFirstLock: c.isFirstLock,
},
Context: pb.Context{
Expand Down
1 change: 1 addition & 0 deletions tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ func setGlobalVars() {
}

tikv.CommitMaxBackoff = int(parseDuration(cfg.TiKVClient.CommitTimeout).Seconds() * 1000)
tikv.PessimisticLockTTL = uint64(parseDuration(cfg.PessimisticTxn.TTL).Seconds() * 1000)
}

func setupLog() {
Expand Down